Skip to content

Commit 2d9175f

Browse files
committed
ci: publish crates to crates.io on release (cargo-dist custom job)
Add a reusable workflow (.github/workflows/publish-crates.yml) that runs cargo publish for deepshrink-ffmpeg -> deepshrink-core -> deepshrink in dependency order, wired into the release pipeline via publish-jobs = ["homebrew", "./publish-crates"] and regenerated into release.yml by dist. It runs in the publish stage after the GitHub Release is created, with secrets: inherit — so it needs a CARGO_REGISTRY_TOKEN repo secret. cargo-dist did not publish crates before, which is why 0.3.4 had to be pushed by hand.
1 parent f6b6fdd commit 2d9175f

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Custom cargo-dist publish job: push the workspace crates to crates.io.
2+
#
3+
# Wired in via `publish-jobs = ["./publish-crates"]` in Cargo.toml's
4+
# `[workspace.metadata.dist]`; cargo-dist regenerates release.yml to call this
5+
# reusable workflow in the publish stage (after the GitHub Release is created)
6+
# and passes it the dist plan. cargo-dist invokes publish jobs with
7+
# `secrets: inherit`, so `CARGO_REGISTRY_TOKEN` (a repo secret) is available here.
8+
#
9+
# crates.io has no atomic multi-crate publish, so the members go up in dependency
10+
# order — deepshrink-ffmpeg, then deepshrink-core (depends on ffmpeg), then the
11+
# deepshrink binary (depends on both) — with `cargo publish` waiting for each to
12+
# appear in the index before returning.
13+
name: Publish to crates.io
14+
15+
on:
16+
workflow_call:
17+
# cargo-dist passes the plan; we don't read it, but the input must be declared.
18+
inputs:
19+
plan:
20+
required: true
21+
type: string
22+
# Allow a manual re-run from the Actions tab if a publish half-fails.
23+
workflow_dispatch:
24+
25+
jobs:
26+
publish-crates:
27+
runs-on: ubuntu-22.04
28+
env:
29+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
30+
steps:
31+
- uses: actions/checkout@v6
32+
with:
33+
persist-credentials: false
34+
- name: Install Rust
35+
run: rustup toolchain install stable --profile minimal
36+
- name: Publish deepshrink-ffmpeg
37+
run: cargo publish -p deepshrink-ffmpeg
38+
- name: Publish deepshrink-core
39+
run: cargo publish -p deepshrink-core
40+
- name: Publish deepshrink
41+
run: cargo publish -p deepshrink

.github/workflows/release.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,30 @@ jobs:
324324
done
325325
git push
326326
327+
custom-publish-crates:
328+
needs:
329+
- plan
330+
- host
331+
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
332+
uses: ./.github/workflows/publish-crates.yml
333+
with:
334+
plan: ${{ needs.plan.outputs.val }}
335+
secrets: inherit
336+
# publish jobs get escalated permissions
337+
permissions:
338+
"id-token": "write"
339+
"packages": "write"
340+
327341
announce:
328342
needs:
329343
- plan
330344
- host
331345
- publish-homebrew-formula
346+
- custom-publish-crates
332347
# use "always() && ..." to allow us to wait for all publish jobs while
333348
# still allowing individual publish jobs to skip themselves (for prereleases).
334349
# "host" however must run to completion, no skipping allowed!
335-
if: ${{ always() && needs.host.result == 'success' && (needs.publish-homebrew-formula.result == 'skipped' || needs.publish-homebrew-formula.result == 'success') }}
350+
if: ${{ always() && needs.host.result == 'success' && (needs.publish-homebrew-formula.result == 'skipped' || needs.publish-homebrew-formula.result == 'success') && (needs.custom-publish-crates.result == 'skipped' || needs.custom-publish-crates.result == 'success') }}
336351
runs-on: "ubuntu-22.04"
337352
env:
338353
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ ci = "github"
4242
installers = ["shell", "powershell", "homebrew"]
4343
# A GitHub repo to push Homebrew formulas to
4444
tap = "deeplabua/homebrew-tap"
45-
# Publish jobs to run in CI
46-
publish-jobs = ["homebrew"]
45+
# Publish jobs to run in CI. `./publish-crates` is the local reusable workflow
46+
# `.github/workflows/publish-crates.yml` (crates.io publish; needs the
47+
# CARGO_REGISTRY_TOKEN repo secret).
48+
publish-jobs = ["homebrew", "./publish-crates"]
4749
# Target platforms to build apps for (Rust target-triple syntax)
4850
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
4951
# Whether to install an updater program

0 commit comments

Comments
 (0)