1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: release-please
on:
push:
branches:
permissions:
contents: write
pull-requests: write
jobs:
# 1. Maintains a release PR from conventional commits. On merge it bumps
# Cargo.toml/Cargo.lock, updates CHANGELOG.md, tags the release, and
# creates the GitHub Release. Config lives in release-please-config.json
# + .release-please-manifest.json.
#
# `release_created` is true only on the push that merges the release PR;
# the publish job below gates on it, so it runs exactly once per release
# and never on ordinary pushes.
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
# PRs opened with the default GITHUB_TOKEN do not trigger other workflows,
# so CI won't auto-run on the release PR. Set a fine-grained PAT with
# contents+pull-requests write as RELEASE_PLEASE_TOKEN to get CI on it;
# falls back to GITHUB_TOKEN (release PR just won't get CI) if unset.
- id: release
uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
# 2. Publish the freshly-tagged version to crates.io. Runs in the same
# workflow invocation that created the release, so it never depends on a
# GITHUB_TOKEN-created event chain-firing.
publish-crate:
needs: release-please
if: ${{ needs.release-please.outputs.release_created == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Verify build/tests before publishing
run: cargo test --locked
- name: Publish to crates.io
run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}