From 935582bb98011c0a7bfa6ee0f6d433963f57c250 Mon Sep 17 00:00:00 2001 From: rindeal Date: Sun, 17 Mar 2024 19:49:54 +0000 Subject: [PATCH] CI: release update --- .github/relnotes-checksum-md.sh | 29 ++++++++++++++ .github/workflows/release.yml | 67 ++++++++++++++++++++++++--------- Makefile | 7 ++-- 3 files changed, 83 insertions(+), 20 deletions(-) create mode 100755 .github/relnotes-checksum-md.sh diff --git a/.github/relnotes-checksum-md.sh b/.github/relnotes-checksum-md.sh new file mode 100755 index 0000000..3c8ac04 --- /dev/null +++ b/.github/relnotes-checksum-md.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -evx + +test -n "${CHECKSUM_PATH}" + +echo +echo "
" +echo "" +echo "

Checksums

" +echo "(click here to toggle section visibility)" +echo "
" +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 "
" +echo diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4b9a8e5..f712722 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 }} @@ -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 ] @@ -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 @@ -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}" diff --git a/Makefile b/Makefile index 717676b..a6df012 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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}" ;\ @@ -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