Prepare Release #45
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Prepare Release | |
on: | |
workflow_dispatch: | |
# Disable all GITHUB_TOKEN permissions, since the GitHub App token is used instead. | |
permissions: {} | |
defaults: | |
run: | |
# Setting an explicit bash shell ensures GitHub Actions enables pipefail mode too, | |
# rather than only error on exit (improving failure UX when pipes are used). See: | |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell | |
shell: bash | |
jobs: | |
prepare-release: | |
name: Prepare Release | |
runs-on: pub-hk-ubuntu-24.04-ip | |
steps: | |
# We use our GitHub App's access token instead of GITHUB_TOKEN since otherwise other | |
# workflows (such as CI) won't automatically run on any PRs opened by this workflow: | |
# https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow | |
- name: Generate access token for Linguist GitHub App | |
uses: actions/create-github-app-token@v1 | |
id: generate-token | |
with: | |
app-id: ${{ vars.LINGUIST_GH_APP_ID }} | |
# Note: The calling workflow must enable secrets inheritance for this variable to be accessible: | |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idsecretsinherit | |
private-key: ${{ secrets.LINGUIST_GH_PRIVATE_KEY }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
# We always want the version bump/changelog and resultant PR to target main, not the branch of the workflow_dispatch. | |
ref: main | |
# Tags are not fetched by default, but we need them to determine the existing buildpack version. | |
fetch-tags: true | |
# Force a full clone, otherwise fetch-tags doesn't actually fetch any tags: | |
# https://github.com/actions/checkout/issues/1471 | |
fetch-depth: 0 | |
token: ${{ steps.generate-token.outputs.token }} | |
- name: Determine existing tagged version | |
id: existing-version | |
run: echo "version=$(git tag --list 'v*' --sort '-version:refname' | head --lines 1 | tr --delete 'v')" >> "${GITHUB_OUTPUT}" | |
- name: Calculate new version | |
id: new-version | |
run: echo "version=$(( ${{ steps.existing-version.outputs.version }} + 1 ))" >> "${GITHUB_OUTPUT}" | |
- name: Update changelog | |
run: | | |
EXISTING_VERSION='${{ steps.existing-version.outputs.version }}' | |
NEW_VERSION='${{ steps.new-version.outputs.version }}' | |
DATE_TODAY="$(date --utc --iso-8601)" | |
UNRELEASED_URL="https://github.com/${{ github.repository }}/compare/v${NEW_VERSION}...main" | |
NEW_VERSION_URL="https://github.com/${{ github.repository }}/compare/v${EXISTING_VERSION}...v${NEW_VERSION}" | |
sed --in-place --regexp-extended \ | |
--expression "s~(^## \[Unreleased\])$~\1\n\n\n## [v${NEW_VERSION}] - ${DATE_TODAY}~" \ | |
--expression "s~(^\[unreleased\]:) .*$~\1 ${UNRELEASED_URL}\n[v${NEW_VERSION}]: ${NEW_VERSION_URL}~" \ | |
CHANGELOG.md | |
- name: Generate list of unreleased commits | |
id: unreleased-commits | |
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings | |
run: | | |
{ | |
echo 'commits<<COMMITS_LIST_END' | |
git log --topo-order --reverse --format='- %s' v${{ steps.existing-version.outputs.version }}...main | |
echo COMMITS_LIST_END | |
} >> "${GITHUB_OUTPUT}" | |
- name: Create pull request | |
id: pr | |
uses: peter-evans/create-pull-request@v7.0.6 | |
with: | |
token: ${{ steps.generate-token.outputs.token }} | |
title: Prepare release v${{ steps.new-version.outputs.version }} | |
body: | | |
Commits since the last release: | |
${{ steps.unreleased-commits.outputs.commits }} | |
For the full diff, see the compare view: | |
https://github.com/${{ github.repository }}/compare/v${{ steps.existing-version.outputs.version }}...main | |
commit-message: Prepare release v${{ steps.new-version.outputs.version }} | |
branch: prepare-release | |
delete-branch: true | |
committer: ${{ vars.LINGUIST_GH_APP_USERNAME }} <${{ vars.LINGUIST_GH_APP_EMAIL }}> | |
author: ${{ vars.LINGUIST_GH_APP_USERNAME }} <${{ vars.LINGUIST_GH_APP_EMAIL }}> | |
- name: PR link for GitHub summary | |
if: ${{ steps.pr.outputs.pull-request-number }} | |
run: echo '## PR [#${{ steps.pr.outputs.pull-request-number }}](${{ steps.pr.outputs.pull-request-url }}) ${{ steps.pr.outputs.pull-request-operation }}' >> "$GITHUB_STEP_SUMMARY" | |
- name: Enable pull request auto-merge | |
if: steps.pr.outputs.pull-request-operation == 'created' | |
run: gh pr merge --auto --squash "${{ steps.pr.outputs.pull-request-number }}" | |
env: | |
GH_TOKEN: ${{ steps.generate-token.outputs.token }} |