Skip to content

Prepare release

Prepare release #13

name: Prepare release
on:
workflow_dispatch:
inputs:
bump:
description: "Which component of the version to increment"
required: true
default: "patch"
type: choice
options:
- major
- minor
- patch
env:
CARGO_TERM_COLOR: always
jobs:
prepare-release:
name: Prepare Release
runs-on: pub-hk-ubuntu-24.04-ip
steps:
- name: Get token for GH application (Linguist)
uses: actions/create-github-app-token@v1
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.token }}
- name: Update Rust toolchain
run: rustup update
- name: Rust Cache
uses: Swatinem/rust-cache@v2.7.5
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Record old crate version
id: old-version
run: echo "version=$(yq '.workspace.package.version' Cargo.toml)" >> "${GITHUB_OUTPUT}"
- name: Bump crate versions
# We use `--package libcnb` here to prevent the example and test buildpack crates from
# having their versions bumped too. Since the libcnb package's version is set via the
# root Cargo.toml's `workspace.package.version` field, all other publishable crates will
# still have their versions bumped, even though they are not explicitly listed here.
run: cargo set-version --package libcnb --bump '${{ inputs.bump }}'
- name: Record new crate version
id: new-version
run: echo "version=$(yq '.workspace.package.version' Cargo.toml)" >> "${GITHUB_OUTPUT}"
- name: Update changelog
run: |
OLD_VERSION='${{ steps.old-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${OLD_VERSION}...v${NEW_VERSION}"
sed --in-place --regexp-extended \
--expression "s~(^## \[Unreleased\])$~\1\n\n\n## [${NEW_VERSION}] - ${DATE_TODAY}~" \
--expression "s~(^\[unreleased\]:) .*$~\1 ${UNRELEASED_URL}\n[${NEW_VERSION}]: ${NEW_VERSION_URL}~" \
CHANGELOG.md
- name: Upgrade in-range dependency versions
run: cargo upgrade
- name: Create pull request
id: pr
uses: peter-evans/create-pull-request@v7.0.5
with:
token: ${{ steps.generate-token.outputs.token }}
title: Prepare release v${{ steps.new-version.outputs.version }}
body: |
Changes:
https://github.com/${{ github.repository }}/compare/v${{ steps.old-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.token }}