Skip to content

Commit

Permalink
CI: update
Browse files Browse the repository at this point in the history
  • Loading branch information
rindeal committed Apr 13, 2024
1 parent bb1c61e commit 923f175
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
40 changes: 40 additions & 0 deletions .github/source-code.sh
Original file line number Diff line number Diff line change
@@ -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
30 changes: 15 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
GH_TAG: ${{ github.ref_name }}
REL_TAG: ${{ github.ref_name }}
ASSET_BASENAME: "amalgamate-${{ github.ref_name }}"

jobs:
draft:
Expand All @@ -22,27 +22,27 @@ jobs:
GH_REPO: ${{ github.repository }}
run: >
gh release create "${GH_TAG}"
--title "amalgamate ${REL_TAG}"
--title "amalgamate ${GH_TAG}"
--draft
--generate-notes
--verify-tag
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 ]
Expand All @@ -68,28 +68,28 @@ 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 ]
runs-on: ubuntu-latest
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}"
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}" ;\
Expand All @@ -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

0 comments on commit 923f175

Please sign in to comment.