Skip to content

Commit

Permalink
CI: release update
Browse files Browse the repository at this point in the history
  • Loading branch information
rindeal committed Mar 17, 2024
1 parent 927abd7 commit 935582b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 20 deletions.
29 changes: 29 additions & 0 deletions .github/relnotes-checksum-md.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

set -evx

test -n "${CHECKSUM_PATH}"

echo
echo "<details>"
echo "<summary>"
echo "<h2>Checksums</h2>"
echo "<sub><sup>(click here to toggle section visibility)</sup></sub>"
echo "</summary>"
echo
echo "Verify donwloaded files using this command:"
echo '```sh'
echo 'sha256sum --check --ignore-missing '"$(basename "${CHECKSUM_PATH}")"
echo '```'
echo
echo "Or directly using a checksum value from the table below like this:"
echo '```sh'
echo 'echo $HASH $FILEPATH | sha256sum --check -'
echo '```'
echo
echo "File | SHA-256"
echo "--- | ---"
awk '{print $2, "|", $1}' < "${CHECKSUM_PATH}"
echo
echo "</details>"
echo
67 changes: 50 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ on:
tags:
- 'v*.*.*'

env:
GH_TAG: ${{ github.ref_name }}
REL_TAG: ${{ github.ref_name }}

jobs:
draft:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { submodules: true }

- name: Create draft release
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }
run: gh release create "${{ github.ref_name }}" --title "amalgamate ${{ github.ref_name }}" --draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: >
gh release create "${GH_TAG}"
--title "amalgamate ${REL_TAG}"
--draft
--generate-notes
--verify-tag
source:
source_code:
needs: [ draft ]
runs-on: ubuntu-latest
steps:
Expand All @@ -34,9 +42,9 @@ jobs:

- name: Upload assets
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }
run: gh release upload --clobber "${{ github.ref_name }}" ${archives}
run: gh release upload --clobber "${GH_TAG}" ${archives}

linux_macos:
linux_n_macos:
needs: [ draft ]
strategy: { matrix: { os: [ ubuntu-latest, macos-13, macos-14 ] } }
runs-on: ${{ matrix.os }}
Expand All @@ -49,7 +57,7 @@ jobs:

- name: Create and upload assets
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }
run: make GH_TAG="${{ github.ref_name }}" gh-upload
run: make gh-upload

windows:
needs: [ draft ]
Expand All @@ -60,7 +68,7 @@ jobs:
- uses: ilammy/msvc-dev-cmd@v1

- name: Initialize environment
run: Add-Content "${env:GITHUB_ENV}" "archive=amalgamate-${{ github.ref_name }}-windows-amd64.zip"
run: Add-Content "${env:GITHUB_ENV}" "archive=amalgamate-${env:REL_TAG}-windows-amd64.zip"

- name: Build
run: ./build.bat
Expand All @@ -70,14 +78,39 @@ jobs:

- name: Upload assets
env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }
run: gh release upload --clobber "${{ github.ref_name }}" "${env:archive}"
run: gh release upload --clobber "${env:GH_TAG}" "${env:archive}"

finish:
needs: [ linux_macos, windows, source ]
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"
steps:
- name: Finish release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: gh release edit "${{ github.ref_name }}" --draft=false
- name: "Download automatically generated release notes"
run: gh release view --json body --jq .body "${GH_TAG}" > "${AUTOGEN_RELNOTES_PATH}"
- name: "Download assets"
run: gh release download --dir "${ASSETS_DIR_PATH}" "${GH_TAG}"
- name: "Generate checksum file"
run: |
set -evx
cd "${ASSETS_DIR_PATH}"
sha256sum * > "${CHECKSUM_PATH}"
- name: "Upload checksum file"
run: gh release upload --clobber "${GH_TAG}" "${CHECKSUM_PATH}"
- name: "Relnotes: init"
run: |
set -evx
br(){ echo "" >> "${RELNOTES_PATH}";}
- name: "Relnotes: append auto notes"
run: cat "${AUTOGEN_RELNOTES_PATH}" >> "${RELNOTES_PATH}"
- name: "Relnotes: checksum section"
run: |
wget "https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/.github/relnotes-checksum-md.sh"
. "relnotes-checksum-md.sh" >> "${RELNOTES_PATH}"
- name: "Finish release"
run: gh release edit --draft=false --notes-file "${RELNOTES_PATH}" "${GH_TAG}"
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ check: $(PROGRAM)
_git-tag-set-check:
@test -n "$(GIT_TAG)" || (echo "Error: Variable 'GIT_TAG' not set" >&2; exit 1)

git-tag-delete: _git-tag-set-check
git-tag-del: _git-tag-set-check
-git tag --delete $(GIT_TAG)
-git push --delete origin $(GIT_TAG)

Expand All @@ -87,10 +87,11 @@ 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)-$(GH_TAG)-$${platform}-$${arch}" ;\
archive_basename="$(PROGRAM)-$(REL_TAG)-$${platform}-$${arch}" ;\
$(MKDIR) -v "$${archive_basename}" ;\
$(CP) -v -a $(GH_ASSETS) "$${archive_basename}" ;\
$(ZIP) -r "$${archive_basename}.zip" "$${archive_basename}" ;\
Expand All @@ -100,4 +101,4 @@ gh-upload: $(PROGRAM)

.PHONY: all clean check
.PHONY: _preflight _preflight-linux _preflight-macos
.PHONY: _git-tag-set-check git-tag-delete git-tag gh-upload
.PHONY: _git-tag-set-check git-tag-del git-tag gh-upload

0 comments on commit 935582b

Please sign in to comment.