From 9a35de05deb190fd48d0ae2972db054a2c80dc43 Mon Sep 17 00:00:00 2001 From: Prestasafe Date: Fri, 10 Jul 2026 16:25:12 +0200 Subject: [PATCH] Publish versioned GitHub releases --- .github/workflows/build-release.yml | 84 +++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 4d40d24..da944e3 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -30,3 +30,87 @@ jobs: path: dist/*.zip if-no-files-found: error retention-days: 14 + + publish-release: + name: Publish GitHub release + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + needs: build-release + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Download release package + uses: actions/download-artifact@v8 + with: + name: prettyblocks-${{ github.sha }} + path: dist + + - name: Prepare release metadata + id: release + env: + GH_TOKEN: ${{ github.token }} + run: | + set -Eeuo pipefail + + version=$(awk -F"'" '/\$this->version[[:space:]]*=/{print $2; exit}' prettyblocks.php) + if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+([.+-][0-9A-Za-z.-]+)?$ ]]; then + echo "Unable to read a valid semantic version from prettyblocks.php." >&2 + exit 1 + fi + + test -s dist/prettyblocks.zip + sha256sum dist/prettyblocks.zip > dist/prettyblocks.zip.sha256 + + previous_tag=$(gh release list \ + --exclude-drafts \ + --exclude-pre-releases \ + --limit 1 \ + --json tagName \ + --jq '.[0].tagName // empty') + + if [ -n "$previous_tag" ]; then + commit_range="${previous_tag}..${GITHUB_SHA}" + else + commit_range="$GITHUB_SHA" + fi + + { + echo '## Contributors' + echo + git log --format='%aN%x09%aE' "$commit_range" \ + | awk -F '\t' '!seen[tolower($2)]++ { print $1 }' \ + | sort -fu \ + | while IFS= read -r contributor; do + printf -- '- %s\n' "$contributor" + done + } > release-notes-prefix.md + + echo "version=$version" >> "$GITHUB_OUTPUT" + + - name: Publish release + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ steps.release.outputs.version }} + run: | + set -Eeuo pipefail + + if gh release view "$VERSION" >/dev/null 2>&1; then + echo "Release $VERSION already exists; nothing to publish." + exit 0 + fi + + gh release create "$VERSION" \ + 'dist/prettyblocks.zip#PrettyBlocks module ZIP' \ + 'dist/prettyblocks.zip.sha256#SHA-256 checksum' \ + --target "$GITHUB_SHA" \ + --title "$VERSION" \ + --generate-notes \ + --notes "$(cat release-notes-prefix.md)" \ + --fail-on-no-commits