Publish Crate #9
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: Publish Crate | |
on: | |
workflow_dispatch: | |
inputs: | |
package_path: | |
description: Path to directory with package to release | |
required: true | |
type: string | |
level: | |
description: Level | |
required: true | |
default: patch | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
- version | |
version: | |
description: Version (used with level "version") | |
required: false | |
type: string | |
dry_run: | |
description: Dry run | |
required: true | |
default: true | |
type: boolean | |
create_release: | |
description: Create a GitHub release | |
required: true | |
type: boolean | |
default: true | |
jobs: | |
sanity: | |
name: Sanity checks | |
runs-on: ubuntu-latest | |
steps: | |
- name: Git Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # full history to check for whitespace / conflict markers | |
- name: Setup Environment | |
uses: ./.github/actions/setup | |
with: | |
stable-toolchain: true | |
cargo-cache-key: cargo-stable-sanity | |
cargo-cache-fallback-key: cargo-stable | |
- name: Check repo is in porcelain state | |
run: ./scripts/check-porcelain.sh | |
- name: Check code nits | |
run: ./scripts/check-nits.sh | |
format: | |
name: Format | |
runs-on: ubuntu-latest | |
needs: [sanity] | |
steps: | |
- name: Git Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Environment | |
uses: ./.github/actions/setup | |
with: | |
rustfmt: true | |
cargo-cache-key: cargo-nightly-fmt | |
cargo-cache-fallback-key: cargo-nightly | |
- name: Check formatting | |
run: ./scripts/check-fmt.sh | |
clippy: | |
name: Clippy | |
needs: [sanity] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Git Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Environment | |
uses: ./.github/actions/setup | |
with: | |
clippy: true | |
cargo-cache-key: cargo-nightly-clippy | |
cargo-cache-fallback-key: cargo-nightly | |
- name: Run clippy | |
run: ./scripts/check-clippy.sh | |
publish-crate: | |
name: Publish crate | |
runs-on: ubuntu-latest | |
needs: [format, clippy] | |
permissions: | |
contents: write | |
steps: | |
- name: Git Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.ANZA_TEAM_PAT }} | |
fetch-depth: 0 # get the whole history for git-cliff | |
- name: Setup Environment | |
uses: ./.github/actions/setup | |
with: | |
stable-toolchain: true | |
cargo-cache-key: cargo-stable-publish | |
cargo-cache-fallback-key: cargo-stable | |
- name: Install cargo-release | |
uses: taiki-e/cache-cargo-install-action@v2 | |
with: | |
tool: cargo-release | |
- name: Ensure CARGO_REGISTRY_TOKEN variable is set | |
env: | |
token: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
if: ${{ env.token == '' }} | |
run: | | |
echo "The CARGO_REGISTRY_TOKEN secret variable is not set" | |
echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"." | |
exit 1 | |
- name: Set Git Author | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
- name: Publish Crate | |
id: publish | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
run: | | |
if [ "${{ inputs.level }}" == "version" ]; then | |
LEVEL=${{ inputs.version }} | |
else | |
LEVEL=${{ inputs.level }} | |
fi | |
if [ "${{ inputs.dry_run }}" == "true" ]; then | |
OPTIONS="--dry-run" | |
else | |
OPTIONS="" | |
fi | |
./scripts/publish-rust.sh "${{ inputs.package_path }}" $LEVEL $OPTIONS | |
- name: Generate a changelog | |
if: github.event.inputs.create_release == 'true' | |
uses: orhun/git-cliff-action@v3 | |
with: | |
config: "scripts/cliff.toml" | |
args: | | |
"${{ steps.publish.outputs.old_git_tag }}"..master | |
--include-path "${{ inputs.package_path }}/**" | |
--github-repo "${{ github.repository }}" | |
env: | |
OUTPUT: TEMP_CHANGELOG.md | |
GITHUB_REPO: ${{ github.repository }} | |
- name: Create GitHub release | |
if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true' | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ steps.publish.outputs.new_git_tag }} | |
bodyFile: TEMP_CHANGELOG.md |