Skip to content

Commit 7c20ead

Browse files
committed
chore:implement cargo dist
1 parent 83f186c commit 7c20ead

File tree

3 files changed

+556
-19
lines changed

3 files changed

+556
-19
lines changed

.github/workflows/release.yml

Lines changed: 298 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,307 @@
1+
# Copyright 2022-2024, 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.
13+
114
name: Release
215

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.
340
on:
441
push:
5-
# Sequence of patterns matched against refs/tags
642
tags:
7-
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
43+
- '**[0-9]+.[0-9]+.[0-9]+*'
44+
pull_request:
45+
846
jobs:
9-
build:
10-
runs-on: '${{ matrix.os }}'
11-
permissions:
12-
contents: write
47+
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
48+
plan:
49+
runs-on: ubuntu-latest
50+
outputs:
51+
val: ${{ steps.plan.outputs.manifest }}
52+
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
53+
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
54+
publishing: ${{ !github.event.pull_request }}
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
steps:
58+
- uses: actions/checkout@v4
59+
with:
60+
submodules: recursive
61+
- name: Install cargo-dist
62+
# we specify bash to get pipefail; it guards against the `curl` command
63+
# failing. otherwise `sh` won't catch that `curl` returned non-0
64+
shell: bash
65+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.0/cargo-dist-installer.sh | sh"
66+
# sure would be cool if github gave us proper conditionals...
67+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
68+
# functionality based on whether this is a pull_request, and whether it's from a fork.
69+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
70+
# but also really annoying to build CI around when it needs secrets to work right.)
71+
- id: plan
72+
run: |
73+
cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
74+
echo "cargo dist ran successfully"
75+
cat plan-dist-manifest.json
76+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
77+
- name: "Upload dist-manifest.json"
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: artifacts-plan-dist-manifest
81+
path: plan-dist-manifest.json
82+
83+
# Build and packages all the platform-specific things
84+
build-local-artifacts:
85+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
86+
# Let the initial task tell us to not run (currently very blunt)
87+
needs:
88+
- plan
89+
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') }}
1390
strategy:
14-
matrix:
15-
os: [ ubuntu-20.04, macos-latest ]
16-
include:
17-
- os: ubuntu-20.04
18-
uname: linux
19-
- os: macos-latest
20-
uname: osx
91+
fail-fast: false
92+
# Target platforms/runners are computed by cargo-dist in create-release.
93+
# Each member of the matrix has the following arguments:
94+
#
95+
# - runner: the github runner
96+
# - dist-args: cli flags to pass to cargo dist
97+
# - install-dist: expression to run to install cargo-dist on the runner
98+
#
99+
# Typically there will be:
100+
# - 1 "global" task that builds universal installers
101+
# - N "local" tasks that build each platform's binaries and platform-specific installers
102+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
103+
runs-on: ${{ matrix.runner }}
104+
env:
105+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
107+
steps:
108+
- uses: actions/checkout@v4
109+
with:
110+
submodules: recursive
111+
- uses: swatinem/rust-cache@v2
112+
- name: Install cargo-dist
113+
run: ${{ matrix.install_dist }}
114+
# Get the dist-manifest
115+
- name: Fetch local artifacts
116+
uses: actions/download-artifact@v4
117+
with:
118+
pattern: artifacts-*
119+
path: target/distrib/
120+
merge-multiple: true
121+
- name: Install dependencies
122+
run: |
123+
${{ matrix.packages_install }}
124+
- name: Build artifacts
125+
run: |
126+
# Actually do builds and make zips and whatnot
127+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
128+
echo "cargo dist ran successfully"
129+
- id: cargo-dist
130+
name: Post-build
131+
# We force bash here just because github makes it really hard to get values up
132+
# to "real" actions without writing to env-vars, and writing to env-vars has
133+
# inconsistent syntax between shell and powershell.
134+
shell: bash
135+
run: |
136+
# Parse out what we just built and upload it to scratch storage
137+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
138+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
139+
echo "EOF" >> "$GITHUB_OUTPUT"
140+
141+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
142+
- name: "Upload artifacts"
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
146+
path: |
147+
${{ steps.cargo-dist.outputs.paths }}
148+
${{ env.BUILD_MANIFEST_NAME }}
149+
150+
# Build and package all the platform-agnostic(ish) things
151+
build-global-artifacts:
152+
needs:
153+
- plan
154+
- build-local-artifacts
155+
runs-on: "ubuntu-20.04"
156+
env:
157+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
159+
steps:
160+
- uses: actions/checkout@v4
161+
with:
162+
submodules: recursive
163+
- name: Install cargo-dist
164+
shell: bash
165+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.0/cargo-dist-installer.sh | sh"
166+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
167+
- name: Fetch local artifacts
168+
uses: actions/download-artifact@v4
169+
with:
170+
pattern: artifacts-*
171+
path: target/distrib/
172+
merge-multiple: true
173+
- id: cargo-dist
174+
shell: bash
175+
run: |
176+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
177+
echo "cargo dist ran successfully"
178+
179+
# Parse out what we just built and upload it to scratch storage
180+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
181+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
182+
echo "EOF" >> "$GITHUB_OUTPUT"
183+
184+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
185+
- name: "Upload artifacts"
186+
uses: actions/upload-artifact@v4
187+
with:
188+
name: artifacts-build-global
189+
path: |
190+
${{ steps.cargo-dist.outputs.paths }}
191+
${{ env.BUILD_MANIFEST_NAME }}
192+
# Determines if we should publish/announce
193+
host:
194+
needs:
195+
- plan
196+
- build-local-artifacts
197+
- build-global-artifacts
198+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
199+
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') }}
200+
env:
201+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
202+
runs-on: "ubuntu-20.04"
203+
outputs:
204+
val: ${{ steps.host.outputs.manifest }}
205+
steps:
206+
- uses: actions/checkout@v4
207+
with:
208+
submodules: recursive
209+
- name: Install cargo-dist
210+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.13.0/cargo-dist-installer.sh | sh"
211+
# Fetch artifacts from scratch-storage
212+
- name: Fetch artifacts
213+
uses: actions/download-artifact@v4
214+
with:
215+
pattern: artifacts-*
216+
path: target/distrib/
217+
merge-multiple: true
218+
# This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
219+
- id: host
220+
shell: bash
221+
run: |
222+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
223+
echo "artifacts uploaded and released successfully"
224+
cat dist-manifest.json
225+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
226+
- name: "Upload dist-manifest.json"
227+
uses: actions/upload-artifact@v4
228+
with:
229+
# Overwrite the previous copy
230+
name: artifacts-dist-manifest
231+
path: dist-manifest.json
232+
233+
publish-homebrew-formula:
234+
needs:
235+
- plan
236+
- host
237+
runs-on: "ubuntu-20.04"
238+
env:
239+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
240+
PLAN: ${{ needs.plan.outputs.val }}
241+
GITHUB_USER: "axo bot"
242+
GITHUB_EMAIL: "[email protected]"
243+
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
21244
steps:
22-
- uses: actions/checkout@v2
23-
- run: ./build-release jira-terminal ${{ github.ref_name }}-${{ matrix.uname }}
24-
- uses: ncipollo/release-action@v1
245+
- uses: actions/checkout@v4
246+
with:
247+
repository: "amritghimire/homebrew-jira-terminal"
248+
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
249+
# So we have access to the formula
250+
- name: Fetch local artifacts
251+
uses: actions/download-artifact@v4
252+
with:
253+
pattern: artifacts-*
254+
path: Formula/
255+
merge-multiple: true
256+
# This is extra complex because you can make your Formula name not match your app name
257+
# so we need to find releases with a *.rb file, and publish with that filename.
258+
- name: Commit formula files
259+
run: |
260+
git config --global user.name "${GITHUB_USER}"
261+
git config --global user.email "${GITHUB_EMAIL}"
262+
263+
for release in $(echo "$PLAN" | jq --compact-output '.releases[] | select([.artifacts[] | endswith(".rb")] | any)'); do
264+
filename=$(echo "$release" | jq '.artifacts[] | select(endswith(".rb"))' --raw-output)
265+
name=$(echo "$filename" | sed "s/\.rb$//")
266+
version=$(echo "$release" | jq .app_version --raw-output)
267+
268+
git add "Formula/${filename}"
269+
git commit -m "${name} ${version}"
270+
done
271+
git push
272+
273+
# Create a GitHub Release while uploading all files to it
274+
announce:
275+
needs:
276+
- plan
277+
- host
278+
- publish-homebrew-formula
279+
# use "always() && ..." to allow us to wait for all publish jobs while
280+
# still allowing individual publish jobs to skip themselves (for prereleases).
281+
# "host" however must run to completion, no skipping allowed!
282+
if: ${{ always() && needs.host.result == 'success' && (needs.publish-homebrew-formula.result == 'skipped' || needs.publish-homebrew-formula.result == 'success') }}
283+
runs-on: "ubuntu-20.04"
284+
env:
285+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
286+
steps:
287+
- uses: actions/checkout@v4
288+
with:
289+
submodules: recursive
290+
- name: "Download GitHub Artifacts"
291+
uses: actions/download-artifact@v4
292+
with:
293+
pattern: artifacts-*
294+
path: artifacts
295+
merge-multiple: true
296+
- name: Cleanup
297+
run: |
298+
# Remove the granular manifests
299+
rm -f artifacts/*-dist-manifest.json
300+
- name: Create GitHub Release
301+
uses: ncipollo/release-action@v1
25302
with:
26-
artifacts: "jira-terminal,jira-terminal-*.*"
27-
allowUpdates: true
28-
draft: true
303+
tag: ${{ needs.plan.outputs.tag }}
304+
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
305+
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
306+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
307+
artifacts: "artifacts/*"

Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ keywords = ["jira","terminal","command-line"]
1111
license = "AGPL-3.0-only"
1212
categories = ["command-line-utilities"]
1313

14+
[package.metadata.wix]
15+
upgrade-guid = "A8ACB116-285E-4707-B21D-F7BEB7801849"
16+
path-guid = "9FB820A6-7BB9-4E7A-AC62-0F43AA2B7171"
17+
license = false
18+
eula = false
19+
1420
[dependencies]
1521
home = "0.5.3"
1622
json = "0.12.4"
@@ -20,3 +26,27 @@ clap = "2.33.3"
2026
chrono = "0.4.19"
2127
regex = "1.5.5"
2228
rpassword = "5.0.1"
29+
30+
# The profile that 'cargo dist' will build with
31+
[profile.dist]
32+
inherits = "release"
33+
lto = "thin"
34+
35+
# Config for 'cargo dist'
36+
[workspace.metadata.dist]
37+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
38+
cargo-dist-version = "0.13.0"
39+
# CI backends to support
40+
ci = ["github"]
41+
# The installers to generate for each app
42+
installers = ["shell", "powershell", "homebrew", "msi"]
43+
# A GitHub repo to push Homebrew formulas to
44+
tap = "amritghimire/homebrew-jira-terminal"
45+
# Target platforms to build apps for (Rust target-triple syntax)
46+
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-pc-windows-msvc"]
47+
# Publish jobs to run in CI
48+
publish-jobs = ["homebrew"]
49+
# Publish jobs to run in CI
50+
pr-run-mode = "plan"
51+
# Whether to install an updater program
52+
install-updater = true

0 commit comments

Comments
 (0)