diff --git a/.github/source-code.sh b/.github/source-code.sh new file mode 100755 index 0000000..5b8eaec --- /dev/null +++ b/.github/source-code.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -vex + +test -n "${ASSET_BASENAME}" +test -n "${GH_TAG}" +test -n "${WORK_DIR}" +test -n "${REPO_DIR}" + +command -v pipx >/dev/null +command -v gh >/dev/null + +archives=( "${ASSET_BASENAME}-source-code."{zip,tar.gz} ) + +cmd="${1}" +cmd_pack="pack" +cmd_upload="upload" + +test "${cmd}" = "${cmd_pack}" || test "${cmd}" = "${cmd_upload}" + +cd "${WORK_DIR}" + +for arch in "${archives[@]}" + case "${cmd}" in + + "${cmd_pack}" ) + pipx run git-archive-all --verbose -C "${REPO_DIR}" "${arch}" | grep -v "/3rd/" + ;; + + "${cmd_upload}" ) + label="Source code full (${arch#*.})" + gh release upload --clobber "${GH_TAG}" "${arch}#${label}" + ;; + + * ) + exit 1 + ;; + + esac +done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f712722..817ffa8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ on: env: GH_TAG: ${{ github.ref_name }} - REL_TAG: ${{ github.ref_name }} + ASSET_BASENAME: "amalgamate-${{ github.ref_name }}" jobs: draft: @@ -22,7 +22,7 @@ jobs: GH_REPO: ${{ github.repository }} run: > gh release create "${GH_TAG}" - --title "amalgamate ${REL_TAG}" + --title "amalgamate ${GH_TAG}" --draft --generate-notes --verify-tag @@ -30,19 +30,19 @@ jobs: source_code: needs: [ draft ] runs-on: ubuntu-latest + env: + WORK_DIR: ${{ github.workspace }} + REPO_DIR: ${{ github.workspace }}/repo steps: - uses: actions/checkout@v4 - with: { submodules: true } - - - name: Initialize environment - run: echo archives= "amalgamate-${{ github.ref_name }}-source-code."{zip,tar.gz} >> "${GITHUB_ENV}" + with: { submodules: true, path: "repo" } - name: Create assets - run: printf "%s\n" ${archives} | xargs --verbose --max-args=1 pipx run git-archive-all --verbose | grep -v /3rd/ + run: bash .github/source-code.sh pack - name: Upload assets env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" } - run: gh release upload --clobber "${GH_TAG}" ${archives} + run: bash .github/source-code.sh upload linux_n_macos: needs: [ draft ] @@ -68,17 +68,17 @@ jobs: - uses: ilammy/msvc-dev-cmd@v1 - name: Initialize environment - run: Add-Content "${env:GITHUB_ENV}" "archive=amalgamate-${env:REL_TAG}-windows-amd64.zip" + run: Add-Content "${GITHUB_ENV}" "ARCHIVE_PATH=${ASSET_BASENAME}-windows-amd64.zip" - name: Build run: ./build.bat - name: Create assets - run: Compress-Archive -verbose -Path "amalgamate.exe", "README.md", "LICENSE" -DestinationPath "${env:archive}" + run: Compress-Archive -verbose -Path "amalgamate.exe", "README.md", "LICENSE" -DestinationPath "${ARCHIVE_PATH}" - name: Upload assets env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" } - run: gh release upload --clobber "${env:GH_TAG}" "${env:archive}" + run: gh release upload --clobber "${GH_TAG}" "${ARCHIVE_PATH}" finish: needs: [ source_code, linux_n_macos, windows ] @@ -86,10 +86,10 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} - AUTOGEN_RELNOTES_PATH: "${{github.workspace}}/autogen-release-notes.md" - RELNOTES_PATH: "${{github.workspace}}/relnotes.md" - ASSETS_DIR_PATH: "${{github.workspace}}/assets" - CHECKSUM_PATH: "${{github.workspace}}/sha256sum.txt" + AUTOGEN_RELNOTES_PATH: "${{ github.workspace }}/autogen-release-notes.md" + RELNOTES_PATH: "${{ github.workspace }}/relnotes.md" + ASSETS_DIR_PATH: "${{ github.workspace }}/assets" + CHECKSUM_PATH: "${{ github.workspace }}/${{env.ASSET_BASENAME}}-sha256sum.txt" steps: - name: "Download automatically generated release notes" run: gh release view --json body --jq .body "${GH_TAG}" > "${AUTOGEN_RELNOTES_PATH}" diff --git a/Makefile b/Makefile index a6df012..f19d201 100644 --- a/Makefile +++ b/Makefile @@ -87,11 +87,10 @@ git-tag: _git-tag-set-check git-tag-delete gh-upload: $(PROGRAM) @test -n "$(GH_TAG)" || (echo "Error: Variable 'GH_TAG' not set" >&2; exit 1) - @test -n "$(REL_TAG)" || (echo "Error: Variable 'REL_TAG' not set" >&2; exit 1) set -ex ;\ platform="$$(uname -s | tr '[:upper:]' '[:lower:]')" ;\ arch="$$(uname -m | tr '[:upper:]' '[:lower:]' | sed 's|x86_64|amd64|')" ;\ - archive_basename="$(PROGRAM)-$(REL_TAG)-$${platform}-$${arch}" ;\ + archive_basename="$(ASSET_BASENAME)-$${platform}-$${arch}" ;\ $(MKDIR) -v "$${archive_basename}" ;\ $(CP) -v -a $(GH_ASSETS) "$${archive_basename}" ;\ $(ZIP) -r "$${archive_basename}.zip" "$${archive_basename}" ;\ @@ -101,4 +100,5 @@ gh-upload: $(PROGRAM) .PHONY: all clean check .PHONY: _preflight _preflight-linux _preflight-macos -.PHONY: _git-tag-set-check git-tag-del git-tag gh-upload +.PHONY: _git-tag-set-check git-tag-del git-tag +.PHONY: gh-upload