Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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