Skip to content

Commit

Permalink
Add a Prepare Release GitHub Actions workflow
Browse files Browse the repository at this point in the history
Add a GitHub Actions workflow for preparing a new buildpack release,
similar to that used for CNBs and `libcnb.rs` releases:
https://github.com/heroku/languages-github-actions/blob/main/.github/workflows/_buildpacks-prepare-release.yml
https://github.com/heroku/libcnb.rs/blob/main/.github/workflows/prepare-release.yml

The changelog format has been updated in this PR to more closely match the
https://keepachangelog.com format (which allows reusing the regexes from
our other automation), however, to reduce churn I've not adopted the change
categories headings for now.

For now this is not being implemented as a shared workflow, since the
classic buildpacks (unlike the CNBs):
- do not have standardised changelog formats
- have differing approaches to versioning (some have the changelog version
  match the buildpack registry version, others do not)
- in some cases (eg Ruby) require additional edits for releases beyond just the
  changelog (such as updating version constants elsewhere in the codebase).

As such, it makes more sense to get something working for one buildpack first,
and if there is interest about adding this to other classic buildpacks, we can
discuss how we might standardise/implement generic automation.

GUS-W-14437037.
  • Loading branch information
edmorley committed Nov 6, 2023
1 parent 153a074 commit b85f6a2
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 126 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Prepare release

on: workflow_dispatch

jobs:
prepare-release:
name: Prepare Release
runs-on: pub-hk-ubuntu-22.04-small
steps:
- name: Get token for GH application (Linguist)
uses: heroku/use-app-token-action@main
id: generate-token
with:
app_id: ${{ vars.LINGUIST_GH_APP_ID }}
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
# Using the GH application token here will configure the local git config for this repo with credentials
# that can be used to make signed commits that are attributed to the GH application user
token: ${{ steps.generate-token.outputs.app_token }}

- name: Determine existing published version
id: existing-version
# This uses the buildpack registry API directly instead of the Heroku CLI, since the latter
# requires being logged in for version queries even though the registry API itself doesn't.
run: |
URI_ENCODED_BUILDPACK_NAME='heroku%2Fpython'
VERSION=$(
curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 10 \
-H 'Accept: application/vnd.heroku+json; version=3.buildpack-registry' \
"https://buildpack-registry.heroku.com/buildpacks/${URI_ENCODED_BUILDPACK_NAME}/revisions" \
| jq --exit-status --raw-output 'max_by(.release) | .release'
)
echo "version=${VERSION}" >> "${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}...HEAD"
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: Create pull request
id: pr
uses: peter-evans/create-pull-request@v5.0.2
with:
token: ${{ steps.generate-token.outputs.app_token }}
title: Prepare release v${{ steps.new-version.outputs.version }}
body: |
Changes:
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: Configure pull request
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.app_token }}
Loading

0 comments on commit b85f6a2

Please sign in to comment.