Skip to content

Release Actions

Release Actions #15

Workflow file for this run

name: Release Actions
on:
workflow_dispatch:
inputs:
bump:
description: "Bump"
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
defaults:
run:
# Setting an explicit bash shell ensures GitHub Actions enables pipefail mode too,
# ratherthan 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
env:
CARGO_TERM_COLOR: always
jobs:
prepare:
name: 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:
# 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 }}
# This will ensure commits made from this workflow are attributed to the GH application user
- name: Configure git
run: |
git config --global user.name ${{ vars.LINGUIST_GH_APP_USERNAME }}
git config --global user.email ${{ vars.LINGUIST_GH_APP_EMAIL }}
- name: Update Rust toolchain
run: rustup update
- name: Rust cache
uses: Swatinem/rust-cache@v2.7.1
- name: Install cargo-bump
run: cargo install cargo-bump
- name: Get previous release version
id: previous-version
run: echo "value=$(gh release view --json tagName --jq '.tagName' | sed 's/^v//')" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ steps.generate-token.outputs.app_token }}
- name: Bump version
run: |
cargo bump ${{ steps.previous-version.outputs.value }}
cargo bump ${{ inputs.bump }}
- name: Build
run: cargo build --release
- name: Get release metadata
id: metadata
run: |
echo "name=$(cargo metadata --format-version=1 --no-deps | jq --exit-status -r '.packages[-1].targets[-1].name')" >> $GITHUB_OUTPUT
echo "version=$(cargo metadata --format-version=1 --no-deps | jq --exit-status -r '.packages[-1].version')" >> $GITHUB_OUTPUT
- name: Package binary
id: package-binary
run: |
ASSET_PATH=${{ runner.temp }}/${{ steps.metadata.outputs.name }}.tar.gz
tar -czf "${ASSET_PATH}" -C ./target/release ${{ steps.metadata.outputs.name }}
echo "path=${ASSET_PATH}" >> $GITHUB_OUTPUT
- name: Update actions/install-languages-cli/action.yml
run: |
yq -i '
.inputs.download_url.default = "https://github.com/${{ github.repository }}/releases/download/v${{ steps.metadata.outputs.version }}/${{ steps.metadata.outputs.name }}.tar.gz"
' .github/actions/install-languages-cli/action.yml
- name: Update workflows/_buildpacks-prepare-release.yml
run: |
yq -i '
(.jobs[].steps[] |
select(.uses == "${{ github.repository }}/.github/actions/install-languages-cli@main") |
.uses
) = "${{ github.repository }}/.github/actions/install-languages-cli@v${{ steps.metadata.outputs.version }}"
' .github/workflows/_buildpacks-prepare-release.yml
- name: Update workflows/_buildpacks-release.yml
run: |
yq -i '
(.jobs[].steps[] |
select(.uses == "${{ github.repository }}/.github/actions/install-languages-cli@main") |
.uses
) = "${{ github.repository }}/.github/actions/install-languages-cli@v${{ steps.metadata.outputs.version }}"
' .github/workflows/_buildpacks-release.yml
- name: Create a release tag with required changes
id: release-tag
run: |
git add .
git commit -m "Release v${{ steps.metadata.outputs.version }}"
git tag v${{ steps.metadata.outputs.version }}
git push origin refs/tags/v${{ steps.metadata.outputs.version }}
git tag -f latest
git push -f origin refs/tags/latest
echo "sha=$(git rev-list -n 1 v${{ steps.metadata.outputs.version }})" >> $GITHUB_OUTPUT
- name: Create release
uses: softprops/action-gh-release@v0.1.15
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.app_token }}
with:
target_commitish: ${{ steps.release-tag.outputs.sha }}
tag_name: v${{ steps.metadata.outputs.version }}
files: ${{ steps.package-binary.outputs.path }}
fail_on_unmatched_files: true
body: "Full Changelog: https://github.com/${{ github.repository }}/compare/v${{ steps.previous-version.outputs.value }}..v${{ steps.metadata.outputs.version }}"