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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
name: Release
# Two entry points:
#
# * `workflow_run` on CI: a green `dev` run refreshes the release-plz pull
# request; a green `main` run (a merged dev→main release PR) tags the
# released version `v<version>` and creates the GitHub release.
# release-plz only computes versions, updates the changelog and pushes
# the tag — `publish = false` in release-plz.toml; crates.io publishing
# is the `publish` job below.
# * `workflow_dispatch` with a `tag` input: re-runs the publish, dist and
# asset jobs for an existing release tag (recovery after a failed leg).
#
# release-plz runs under the workflow's own GITHUB_TOKEN, and nothing here
# depends on a tag push firing another workflow: the tag release-plz just
# created is read out of its JSON report into a job output, and the
# publish/dist/asset jobs chain off it with `needs:` in this same run —
# the shape the framework's release pipeline uses, and the only one that
# works, because a tag pushed under GITHUB_TOKEN triggers no workflow.
on:
workflow_run:
workflows:
branches:
types:
workflow_dispatch:
inputs:
tag:
description: "Existing release tag to re-run, e.g. v0.2.2"
required: true
type: string
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
DIST_VERSION: 0.30.2
jobs:
release:
name: Tag the released version
runs-on: ubuntu-latest
if: >-
github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'
concurrency:
group: release-main
cancel-in-progress: false
permissions:
contents: write
outputs:
# The `v<version>` tag release-plz created this run, empty when it
# released nothing.
tag: ${{ steps.cli_tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- uses: ./.github/actions/setup-rust
with:
cache: "false"
# `release-plz release` verify-builds the manifest it tags.
- uses: ./.github/actions/setup-linux-deps
- uses: ./.github/actions/release-plz
id: release_plz
with:
command: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Read the tag out of release-plz's own report rather than looking
# for one on this job's HEAD — the tag lands on the release branch's
# tip, not on the merge commit this job checked out.
- name: Detect CLI release tag
id: cli_tag
shell: bash
env:
REPORT: ${{ steps.release_plz.outputs.report }}
run: |
set -euo pipefail
TAG="$(jq -r '[.releases[]? | select(.package_name == "waterui-cli") | .tag] | last // ""' <<< "$REPORT")"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
if [[ -n "${TAG}" ]]; then
echo "release-plz released waterui-cli as ${TAG}."
else
echo "release-plz released no waterui-cli this run."
fi
release-pr:
name: Prepare the next release
runs-on: ubuntu-latest
if: >-
github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'dev'
concurrency:
group: release-plz-dev
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: dev
fetch-depth: 0
- uses: ./.github/actions/setup-rust
with:
cache: "false"
- uses: ./.github/actions/setup-linux-deps
- uses: ./.github/actions/release-plz
with:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: release
if: always() && (needs.release.outputs.tag || inputs.tag)
permissions:
contents: read
id-token: write
env:
TAG: ${{ needs.release.outputs.tag || inputs.tag }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.TAG }}
- uses: ./.github/actions/setup-rust
with:
cache: "false"
# `cargo publish` verify-builds the package.
- uses: ./.github/actions/setup-linux-deps
# Mint a short-lived crates.io token from the GitHub OIDC identity
# instead of a stored CARGO_REGISTRY_TOKEN (trusted publishing is
# configured per crate on crates.io).
- uses: rust-lang/crates-io-auth-action@v1
id: crates-io-auth
# Idempotent so `workflow_dispatch` can re-run a release whose publish
# leg already landed: only the version on crates.io decides.
- name: Publish the crate
shell: bash
env:
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
run: |
set -euo pipefail
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
if curl -sf -o /dev/null "https://crates.io/api/v1/crates/waterui-cli/${version}"; then
echo "waterui-cli ${version} is already published — nothing to do"
else
cargo publish --locked
fi
dist:
name: dist / ${{ matrix.target }}
runs-on: ${{ matrix.os }}
needs: release
if: always() && (needs.release.outputs.tag || inputs.tag)
permissions:
contents: read
env:
TAG: ${{ needs.release.outputs.tag || inputs.tag }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: aarch64-pc-windows-msvc
os: windows-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.TAG }}
- uses: ./.github/actions/setup-rust
with:
shared-key: dist-${{ matrix.target }}
- uses: ./.github/actions/setup-linux-deps
if: runner.os == 'Linux'
- uses: ./.github/actions/install-dxc
if: runner.os == 'Windows'
- name: Install cargo-dist
uses: taiki-e/install-action@v2
with:
tool: cargo-dist@${{ env.DIST_VERSION }}
- name: Build artifacts
shell: bash
run: |
dist build \
--tag "${{ env.TAG }}" \
--artifacts=local \
--target "${{ matrix.target }}"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.target }}
if-no-files-found: error
path: |
target/distrib/*${{ matrix.target }}*.tar.*
target/distrib/*${{ matrix.target }}*.zip*
target/distrib/*${{ matrix.target }}*-dist-manifest.json
release-assets:
name: Upload release assets
needs:
# `always()` so a skipped `release` on workflow_dispatch still resolves;
# the publish/dist results are what actually gate this job.
if: always() && needs.publish.result == 'success' && needs.dist.result == 'success'
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG: ${{ needs.release.outputs.tag || inputs.tag }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.TAG }}
- name: Install cargo-dist
uses: taiki-e/install-action@v2
with:
tool: cargo-dist@${{ env.DIST_VERSION }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
pattern: artifacts-*
path: target/distrib
merge-multiple: true
- name: Build global release artifacts
run: dist build --tag "${{ env.TAG }}" --artifacts=global
# The patterns must not overlap. `*.tar.*` also matched every
# `…tar.xz.sha256`, which `*.sha256` matched again, so each checksum
# beside a tarball was listed twice; the action then issued two deletes
# for the one existing asset of that name and the second answered
# `Not Found`, failing the step. Invisible on a first release, where
# there is nothing to delete — and fatal on the re-run that recovers
# one. `.tar.xz`, `.tar.gz`, `.zip`, `.sha256` and `sha256.sum` are
# disjoint suffixes, so each file is named once.
- name: Upload assets to release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
files: |
target/distrib/*.tar.xz
target/distrib/*.tar.gz
target/distrib/*.zip
target/distrib/*.sha256
target/distrib/sha256.sum
- name: Checkout Homebrew tap
uses: actions/checkout@v4
with:
repository: water-rs/homebrew-water
token: ${{ secrets.HOMEBREW_PAT }}
path: homebrew-water
- name: Stage dist-generated Homebrew formula
run: cp target/distrib/water.rb homebrew-water/Formula/water.rb
# The tap's `dev` is ruled like every other branch in the organisation:
# changes arrive through a pull request and commits carry a verified
# signature. This job can satisfy neither directly — a commit made on a
# runner is unsigned, and `HOMEBREW_PAT` may write contents there but
# not pull requests (`Resource not accessible by personal access
# token`). So it pushes the branch and stops. water-rs/homebrew-water's
# own `publish-formula.yml` picks it up, opens the pull request and
# merges it under that repository's `GITHUB_TOKEN`, and the squash
# commit GitHub writes is signed.
#
# `--force` because a re-run of a release pushes the same branch again.
- name: Push the Homebrew formula branch
shell: bash
run: |
set -euo pipefail
version="${TAG#v}"
cd homebrew-water
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add Formula/water.rb
if git diff --cached --quiet; then
echo "No Homebrew changes to publish."
exit 0
fi
git commit -m "water ${version}"
git push --force origin "HEAD:refs/heads/water-${version}"