name: release
permissions: {}
on:
push:
branches: [master, 'release/**']
jobs:
release-request:
if: github.repository_owner == 'OWNER'
runs-on: ubuntu-latest
permissions:
contents: read
concurrency:
group: release-request-${{ github.ref }}
cancel-in-progress: false
steps:
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 id: app-token
with:
app-id: ${{ secrets.RELEASE_BOT_APP_ID }}
private-key: ${{ secrets.RELEASE_BOT_APP_PRIVATE_KEY }}
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: install git-cliff
run: pipx install git-cliff==2.13.1
- name: maintain the release request
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
REF: ${{ github.ref_name }}
RELEASE_STYLE: RK_STYLE
run: |
set -eu
current="$(cat VERSION)"
next="$(git cliff --bumped-version | sed 's/^v//')"
if [ "$next" = "$current" ]; then
echo "no release-worthy commits since v$current; no request to maintain."
exit 0
fi
if [ -n "$(git ls-remote --tags origin "refs/tags/v$next")" ]; then
echo "v$next is already tagged; no request to maintain."
exit 0
fi
branch="chore/release-v$next"
git switch -c "$branch"
printf '%s\n' "$next" > VERSION
git cliff --bump -o CHANGELOG.md
uid="$(gh api "/users/${APP_SLUG}[bot]" -q .id)"
git config user.name "${APP_SLUG}[bot]"
git config user.email "${uid}+${APP_SLUG}[bot]@users.noreply.github.com"
git add VERSION CHANGELOG.md
git commit -m "chore(release): v$next"
git push -f origin "$branch"
open="$(gh pr list --base "$REF" --head "$branch" --state open --json number -q 'length')"
if [ "$open" -eq 0 ]; then
gh pr create --base "$REF" --head "$branch" \
--title "chore(release): v$next" \
--body "Bumps VERSION to $next and rewrites the changelog. Merging this request is the release: the bump push tags v$next and attaches the tarball."
fi
# The trunk style's standing arm, re-applied on every refresh; the
# app token is what keeps the eventual merge able to start this
# workflow's release half, and the lines style leaves the merge a
# human's.
if [ "$RELEASE_STYLE" != "trunk" ]; then
echo "the lines style merges each release by hand; not arming."
exit 0
fi
if [ "$REF" != "master" ]; then
echo "a line's request is never armed; its candidate is what a human validated."
exit 0
fi
gh pr merge "$branch" --auto --squash --delete-branch
echo "armed the release request for v$next."
tag-and-attach:
if: github.repository_owner == 'OWNER'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
artifact-metadata: write
steps:
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 id: app-token
with:
app-id: ${{ secrets.RELEASE_BOT_APP_ID }}
private-key: ${{ secrets.RELEASE_BOT_APP_PRIVATE_KEY }}
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with:
fetch-depth: 0
persist-credentials: false
- name: install git-cliff
run: pipx install git-cliff==2.13.1
- name: tag and build
id: build
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
GH_REPO: ${{ github.repository }}
SHA: ${{ github.sha }}
run: |
set -eu
version="$(cat VERSION)"
previous="$(git show "$SHA^:VERSION" 2>/dev/null || echo "")"
if [ "$previous" = "$version" ]; then
echo "this commit does not bump the version; nothing to release."
exit 0
fi
if [ -z "$(git ls-remote --tags origin "refs/tags/v$version")" ]; then
gh api -X POST "repos/$GH_REPO/git/refs" \
-f "ref=refs/tags/v$version" -f "sha=$SHA" >/dev/null
echo "tagged v$version at $SHA."
fi
git fetch origin "refs/tags/v$version:refs/tags/v$version"
make dist
git cliff --latest -o notes.md
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "built=true" >> "$GITHUB_OUTPUT"
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 if: steps.build.outputs.built == 'true'
with:
subject-path: dist/*.tar.gz
- name: attach
if: steps.build.outputs.built == 'true'
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
VERSION: ${{ steps.build.outputs.version }}
run: |
set -eu
if gh release view "v$VERSION" >/dev/null 2>&1; then
echo "the release page already exists; leaving it as it is."
exit 0
fi
gh release create "v$VERSION" dist/*.tar.gz dist/*.sha256 \
--title "v$VERSION" --notes-file notes.md