Skip to content

Commit a950aca

Browse files
committed
ci: Publish using a custom jobs instead of triggers
Github triggers can only be constrained by branches and not tags. Since we don't want the publish job to run on pull_requests, we use `dist`s custom `publish-jobs` instead.
1 parent 6e13d4f commit a950aca

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

.github/workflows/publish.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# This is triggered after the Release workflow successfully completes its run
22
name: Publish on crates.io
33
on:
4-
workflow_run:
5-
workflows:
6-
- Release
7-
types:
8-
- completed
4+
workflow_call:
5+
# dist exposes the plan from the plan step, as a JSON string,
6+
# to your job if it needs it
7+
inputs:
8+
plan:
9+
required: true
10+
type: string
11+
912
env:
1013
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
1114
jobs:

.github/workflows/release.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,29 @@ jobs:
274274
275275
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
276276
277+
custom-publish.yml:
278+
needs:
279+
- plan
280+
- host
281+
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
282+
uses: ./.github/workflows/publish.yml.yml
283+
with:
284+
plan: ${{ needs.plan.outputs.val }}
285+
secrets: inherit
286+
# publish jobs get escalated permissions
287+
permissions:
288+
"id-token": "write"
289+
"packages": "write"
290+
277291
announce:
278292
needs:
279293
- plan
280294
- host
295+
- custom-publish.yml
281296
# use "always() && ..." to allow us to wait for all publish jobs while
282297
# still allowing individual publish jobs to skip themselves (for prereleases).
283298
# "host" however must run to completion, no skipping allowed!
284-
if: ${{ always() && needs.host.result == 'success' }}
299+
if: ${{ always() && needs.host.result == 'success' && (needs.custom-publish.yml.result == 'skipped' || needs.custom-publish.yml.result == 'success') }}
285300
runs-on: "ubuntu-22.04"
286301
env:
287302
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

dist-workspace.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pr-run-mode = "plan"
1919
install-updater = false
2020
# Path that installers should place binaries in
2121
install-path = "CARGO_HOME"
22+
# Publish jobs to run in CI
23+
publish-jobs = ["./publish.yml"]
2224

2325
[dist.github-custom-runners]
2426
global = "ubuntu-22.04"

0 commit comments

Comments
 (0)