Skip to content

Release

Release #10

Workflow file for this run

name: Release
on: workflow_dispatch
env:
CARGO_TERM_COLOR: always
jobs:
release:
name: Release
# Prevent accidentally performing a release from a branch other than `main`.
if: github.ref == 'refs/heads/main'
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:
# 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/[email protected]
- name: Install cargo-release
run: cargo install cargo-release
- name: Record new crate version
id: new-version
run: echo "version=$(yq '.workspace.package.version' Cargo.toml)" >> "${GITHUB_OUTPUT}"
- name: Check GitHub release does not already exist
run: |
if gh release view 'v${{ steps.new-version.outputs.version }}' --json url --jq '.url'; then
echo "Aborting since a GitHub release already exists for v${{ steps.new-version.outputs.version }}!" >&2
echo "If you are sure you want to recreate the release, delete the existing one first." >&2
exit 1
fi
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Extract changelog entry
id: changelog-entry
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
run: |
{
echo 'content<<CHANGELOG_END'
awk '/^## \[${{ steps.new-version.outputs.version }}\]/{flag=1; next} /^## /{flag=0} flag' CHANGELOG.md
echo CHANGELOG_END
} >> "${GITHUB_OUTPUT}"
- name: Publish to crates.io
# cargo-release calculates the dependency graph for us, and also skips any already
# published packages - preventing overwrites and allowing for retrying the job.
run: cargo release publish --execute --no-confirm
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Create GitHub Release
uses: softprops/[email protected]
with:
token: ${{ steps.generate-token.outputs.token }}
tag_name: v${{ steps.new-version.outputs.version }}
body: ${{ steps.changelog-entry.outputs.content }}