Skip to content

Commit 743ff08

Browse files
committed
Updat release workflow
1 parent 7f604be commit 743ff08

File tree

1 file changed

+52
-242
lines changed

1 file changed

+52
-242
lines changed

.github/workflows/release.yml

Lines changed: 52 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -1,265 +1,75 @@
1-
# Copyright 2022-2023, axodotdev
2-
# SPDX-License-Identifier: MIT or Apache-2.0
3-
#
4-
# CI that:
5-
#
6-
# * checks for a Git Tag that looks like a release
7-
# * builds artifacts with cargo-dist (archives, installers, hashes)
8-
# * uploads those artifacts to temporary workflow zip
9-
# * on success, uploads the artifacts to a Github Release
10-
#
11-
# Note that the Github Release will be created with a generated
12-
# title/body based on your changelogs.
1+
name: Release CLI
132

14-
name: Release
15-
16-
permissions:
17-
contents: write
18-
19-
# This task will run whenever you push a git tag that looks like a version
20-
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
21-
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
22-
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
23-
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
24-
#
25-
# If PACKAGE_NAME is specified, then the announcement will be for that
26-
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
27-
#
28-
# If PACKAGE_NAME isn't specified, then the announcement will be for all
29-
# (cargo-dist-able) packages in the workspace with that version (this mode is
30-
# intended for workspaces with only one dist-able package, or with all dist-able
31-
# packages versioned/released in lockstep).
32-
#
33-
# If you push multiple tags at once, separate instances of this workflow will
34-
# spin up, creating an independent announcement for each one. However Github
35-
# will hard limit this to 3 tags per commit, as it will assume more tags is a
36-
# mistake.
37-
#
38-
# If there's a prerelease-style suffix to the version, then the release(s)
39-
# will be marked as a prerelease.
403
on:
414
push:
425
tags:
436
- '**[0-9]+.[0-9]+.[0-9]+*'
447

458
jobs:
46-
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
47-
plan:
48-
runs-on: ubuntu-latest
49-
outputs:
50-
val: ${{ steps.plan.outputs.manifest }}
51-
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
52-
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
53-
publishing: ${{ !github.event.pull_request }}
54-
env:
55-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9+
release-linux:
10+
runs-on: ubuntu-24.04
11+
permissions:
12+
contents: write
5613
steps:
57-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
14+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
15+
16+
- name: Install Rust
17+
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
5818
with:
59-
submodules: recursive
60-
- name: Install cargo-dist
61-
# we specify bash to get pipefail; it guards against the `curl` command
62-
# failing. otherwise `sh` won't catch that `curl` returned non-0
63-
shell: bash
64-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.2/cargo-dist-installer.sh | sh"
65-
# sure would be cool if github gave us proper conditionals...
66-
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
67-
# functionality based on whether this is a pull_request, and whether it's from a fork.
68-
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
69-
# but also really annoying to build CI around when it needs secrets to work right.)
70-
- id: plan
19+
toolchain: stable
20+
targets: x86_64-unknown-linux-gnu
21+
22+
- name: Build Release Binary
7123
run: |
72-
cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
73-
echo "cargo dist ran successfully"
74-
cat plan-dist-manifest.json
75-
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
76-
- name: "Upload dist-manifest.json"
77-
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
24+
cargo build --release --package rfd-cli
25+
mv target/release/rfd-cli target/release/rfd-cli-x86_64-unknown-linux-gnu
26+
27+
- uses: ncipollo/release-action@bcfe5470707e8832e12347755757cec0eb3c22af # v1
7828
with:
79-
name: artifacts-plan-dist-manifest
80-
path: plan-dist-manifest.json
81-
82-
# Build and packages all the platform-specific things
83-
build-local-artifacts:
84-
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
85-
# Let the initial task tell us to not run (currently very blunt)
86-
needs:
87-
- plan
88-
if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
89-
strategy:
90-
fail-fast: false
91-
# Target platforms/runners are computed by cargo-dist in create-release.
92-
# Each member of the matrix has the following arguments:
93-
#
94-
# - runner: the github runner
95-
# - dist-args: cli flags to pass to cargo dist
96-
# - install-dist: expression to run to install cargo-dist on the runner
97-
#
98-
# Typically there will be:
99-
# - 1 "global" task that builds universal installers
100-
# - N "local" tasks that build each platform's binaries and platform-specific installers
101-
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
102-
runs-on: ${{ matrix.runner }}
103-
env:
104-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105-
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
29+
allowUpdates: true
30+
artifacts: "target/release/rfd-cli-x86_64-unknown-linux-gnu"
31+
release-macos:
32+
runs-on: macos-15
33+
permissions:
34+
contents: write
10635
steps:
107-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
108-
with:
109-
submodules: recursive
110-
- uses: swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2
111-
- name: Install cargo-dist
112-
run: ${{ matrix.install_dist }}
113-
# Get the dist-manifest
114-
- name: Fetch local artifacts
115-
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
116-
with:
117-
pattern: artifacts-*
118-
path: target/distrib/
119-
merge-multiple: true
120-
- name: Install dependencies
121-
run: |
122-
${{ matrix.packages_install }}
123-
- name: Build artifacts
124-
run: |
125-
# Actually do builds and make zips and whatnot
126-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
127-
echo "cargo dist ran successfully"
128-
- id: cargo-dist
129-
name: Post-build
130-
# We force bash here just because github makes it really hard to get values up
131-
# to "real" actions without writing to env-vars, and writing to env-vars has
132-
# inconsistent syntax between shell and powershell.
133-
shell: bash
134-
run: |
135-
# Parse out what we just built and upload it to scratch storage
136-
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
137-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
138-
echo "EOF" >> "$GITHUB_OUTPUT"
36+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
13937

140-
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
141-
- name: "Upload artifacts"
142-
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
38+
- name: Install Rust
39+
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
14340
with:
144-
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
145-
path: |
146-
${{ steps.cargo-dist.outputs.paths }}
147-
${{ env.BUILD_MANIFEST_NAME }}
41+
toolchain: stable
42+
targets: aarch64-apple-darwin
14843

149-
# Build and package all the platform-agnostic(ish) things
150-
build-global-artifacts:
151-
needs:
152-
- plan
153-
- build-local-artifacts
154-
runs-on: "ubuntu-20.04"
155-
env:
156-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157-
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
158-
steps:
159-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
160-
with:
161-
submodules: recursive
162-
- name: Install cargo-dist
163-
shell: bash
164-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.2/cargo-dist-installer.sh | sh"
165-
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
166-
- name: Fetch local artifacts
167-
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
168-
with:
169-
pattern: artifacts-*
170-
path: target/distrib/
171-
merge-multiple: true
172-
- id: cargo-dist
173-
shell: bash
44+
- name: Build Release Binary
17445
run: |
175-
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
176-
echo "cargo dist ran successfully"
177-
178-
# Parse out what we just built and upload it to scratch storage
179-
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
180-
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
181-
echo "EOF" >> "$GITHUB_OUTPUT"
46+
cargo build --release --package rfd-cli
47+
mv target/release/rfd-cli target/release/rfd-cli-aarch64-apple-darwin
18248
183-
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
184-
- name: "Upload artifacts"
185-
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
49+
- uses: ncipollo/release-action@bcfe5470707e8832e12347755757cec0eb3c22af # v1
18650
with:
187-
name: artifacts-build-global
188-
path: |
189-
${{ steps.cargo-dist.outputs.paths }}
190-
${{ env.BUILD_MANIFEST_NAME }}
191-
# Determines if we should publish/announce
192-
host:
193-
needs:
194-
- plan
195-
- build-local-artifacts
196-
- build-global-artifacts
197-
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
198-
if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }}
199-
env:
200-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201-
runs-on: "ubuntu-20.04"
202-
outputs:
203-
val: ${{ steps.host.outputs.manifest }}
51+
allowUpdates: true
52+
artifacts: "target/release/rfd-cli-aarch64-apple-darwin"
53+
54+
release-windows:
55+
runs-on: windows-2025
56+
permissions:
57+
contents: write
20458
steps:
205-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
206-
with:
207-
submodules: recursive
208-
- name: Install cargo-dist
209-
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.2/cargo-dist-installer.sh | sh"
210-
# Fetch artifacts from scratch-storage
211-
- name: Fetch artifacts
212-
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
213-
with:
214-
pattern: artifacts-*
215-
path: target/distrib/
216-
merge-multiple: true
217-
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
218-
- id: host
219-
shell: bash
220-
run: |
221-
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
222-
echo "artifacts uploaded and released successfully"
223-
cat dist-manifest.json
224-
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
225-
- name: "Upload dist-manifest.json"
226-
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
227-
with:
228-
# Overwrite the previous copy
229-
name: artifacts-dist-manifest
230-
path: dist-manifest.json
59+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
23160

232-
# Create a Github Release while uploading all files to it
233-
announce:
234-
needs:
235-
- plan
236-
- host
237-
# use "always() && ..." to allow us to wait for all publish jobs while
238-
# still allowing individual publish jobs to skip themselves (for prereleases).
239-
# "host" however must run to completion, no skipping allowed!
240-
if: ${{ always() && needs.host.result == 'success' }}
241-
runs-on: "ubuntu-20.04"
242-
env:
243-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
244-
steps:
245-
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
246-
with:
247-
submodules: recursive
248-
- name: "Download Github Artifacts"
249-
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4
61+
- name: Install Rust
62+
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
25063
with:
251-
pattern: artifacts-*
252-
path: artifacts
253-
merge-multiple: true
254-
- name: Cleanup
64+
toolchain: stable
65+
targets: x86_64-pc-windows-msvc
66+
67+
- name: Build Release Binary
25568
run: |
256-
# Remove the granular manifests
257-
rm -f artifacts/*-dist-manifest.json
258-
- name: Create Github Release
259-
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1
69+
cargo build --release --package rfd-cli
70+
move target\release\rfd-cli.exe target\release\rfd-cli-x86_64-pc-windows-msvc.exe
71+
72+
- uses: ncipollo/release-action@bcfe5470707e8832e12347755757cec0eb3c22af # v1
26073
with:
261-
tag: ${{ needs.plan.outputs.tag }}
262-
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
263-
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
264-
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
265-
artifacts: "artifacts/*"
74+
allowUpdates: true
75+
artifacts: "target\\/release\\/rfd-cli-x86_64-pc-windows-msvc.exe"

0 commit comments

Comments
 (0)