Skip to content

Commit d3e8f41

Browse files
committed
use self-hosted for release builds
1 parent b629f4d commit d3e8f41

File tree

2 files changed

+90
-90
lines changed

2 files changed

+90
-90
lines changed

.github/workflows/release.yml

+87-85
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
# * checks for a Git Tag that looks like a release
77
# * builds artifacts with cargo-dist (archives, installers, hashes)
88
# * uploads those artifacts to temporary workflow zip
9-
# * on success, uploads the artifacts to a Github Release
9+
# * on success, uploads the artifacts to a Github Release
1010
#
11-
# Note that the Github Release will be created with a generated
11+
# Note that the Github Release will be created with a generated
1212
# title/body based on your changelogs.
13+
1314
name: Release
1415

1516
permissions:
@@ -21,30 +22,31 @@ permissions:
2122
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
2223
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
2324
#
24-
# If PACKAGE_NAME is specified, then the release will be for that
25+
# If PACKAGE_NAME is specified, then the announcement will be for that
2526
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
2627
#
27-
# If PACKAGE_NAME isn't specified, then the release will be for all
28+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
2829
# (cargo-dist-able) packages in the workspace with that version (this mode is
2930
# intended for workspaces with only one dist-able package, or with all dist-able
3031
# packages versioned/released in lockstep).
3132
#
3233
# If you push multiple tags at once, separate instances of this workflow will
33-
# spin up, creating an independent Github Release™ for each one. However Github
34+
# spin up, creating an independent announcement for each one. However Github
3435
# will hard limit this to 3 tags per commit, as it will assume more tags is a
3536
# mistake.
3637
#
37-
# If there's a prerelease-style suffix to the version, then the Github Release™
38+
# If there's a prerelease-style suffix to the version, then the release(s)
3839
# will be marked as a prerelease.
3940
on:
4041
push:
4142
tags:
4243
- '**[0-9]+.[0-9]+.[0-9]+*'
44+
pull_request:
4345

4446
jobs:
45-
# Run 'cargo dist plan' to determine what tasks we need to do
47+
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
4648
plan:
47-
runs-on: self-hosted
49+
runs-on: ubuntu-latest
4850
outputs:
4951
val: ${{ steps.plan.outputs.manifest }}
5052
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
@@ -56,16 +58,20 @@ jobs:
5658
- uses: actions/checkout@v4
5759
with:
5860
submodules: recursive
59-
- name: Install toolchain
60-
uses: dtolnay/rust-toolchain@nightly
61-
with:
62-
toolchain: nightly
6361
- 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
6465
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.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.)
6571
- id: plan
6672
run: |
67-
cargo dist plan ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} --output-format=json > dist-manifest.json
68-
echo "cargo dist plan ran successfully"
73+
cargo dist ${{ !github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name) || (github.event.pull_request.head.repo.fork && 'plan' || 'host --steps=check') }} --output-format=json > dist-manifest.json
74+
echo "cargo dist ran successfully"
6975
cat dist-manifest.json
7076
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
7177
- name: "Upload dist-manifest.json"
@@ -75,10 +81,12 @@ jobs:
7581
path: dist-manifest.json
7682

7783
# Build and packages all the platform-specific things
78-
upload-local-artifacts:
84+
build-local-artifacts:
85+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
7986
# Let the initial task tell us to not run (currently very blunt)
80-
needs: plan
81-
if: ${{ fromJson(needs.plan.outputs.val).releases != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
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') }}
8290
strategy:
8391
fail-fast: false
8492
# Target platforms/runners are computed by cargo-dist in create-release.
@@ -92,7 +100,8 @@ jobs:
92100
# - 1 "global" task that builds universal installers
93101
# - N "local" tasks that build each platform's binaries and platform-specific installers
94102
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
95-
runs-on: ${{ matrix.runner }}
103+
# runs-on: ${{ matrix.runner }}
104+
runs-on: self-hosted
96105
env:
97106
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98107
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
@@ -103,24 +112,12 @@ jobs:
103112
- uses: swatinem/rust-cache@v2
104113
- name: Install cargo-dist
105114
run: ${{ matrix.install_dist }}
106-
107-
- uses: webfactory/ssh-agent@v0.5.4
108-
with:
109-
ssh-private-key: "${{ secrets.SSH_KEY }}"
110-
111-
- name: Install Protoc
112-
uses: arduino/setup-protoc@v1
113-
with:
114-
version: '3.9.1'
115-
116-
- name: Install toolchain
117-
uses: dtolnay/rust-toolchain@nightly
115+
# Get the dist-manifest
116+
- name: Fetch local artifacts
117+
uses: actions/download-artifact@v3
118118
with:
119-
toolchain: nightly
120-
121-
- name: Add wasm toolchain
122-
run: rustup target add wasm32-unknown-unknown
123-
119+
name: artifacts
120+
path: target/distrib/
124121
- name: Install dependencies
125122
run: |
126123
${{ matrix.packages_install }}
@@ -136,8 +133,7 @@ jobs:
136133
# inconsistent syntax between shell and powershell.
137134
shell: bash
138135
run: |
139-
cat dist-manifest.json
140-
# Parse out what we just built and upload it to the Github Release™
136+
# Parse out what we just built and upload it to scratch storage
141137
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
142138
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
143139
echo "EOF" >> "$GITHUB_OUTPUT"
@@ -152,11 +148,14 @@ jobs:
152148
${{ env.BUILD_MANIFEST_NAME }}
153149
154150
# Build and package all the platform-agnostic(ish) things
155-
upload-global-artifacts:
156-
needs: [plan, upload-local-artifacts]
151+
build-global-artifacts:
152+
needs:
153+
- plan
154+
- build-local-artifacts
157155
runs-on: "ubuntu-20.04"
158156
env:
159157
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
160159
steps:
161160
- uses: actions/checkout@v4
162161
with:
@@ -175,85 +174,88 @@ jobs:
175174
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
176175
echo "cargo dist ran successfully"
177176
178-
# Parse out what we just built and upload it to the Github Release™
177+
# Parse out what we just built and upload it to scratch storage
179178
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
180179
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
181180
echo "EOF" >> "$GITHUB_OUTPUT"
181+
182+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
182183
- name: "Upload artifacts"
183184
uses: actions/upload-artifact@v3
184185
with:
185186
name: artifacts
186-
path: ${{ steps.cargo-dist.outputs.paths }}
187-
188-
should-publish:
187+
path: |
188+
${{ steps.cargo-dist.outputs.paths }}
189+
${{ env.BUILD_MANIFEST_NAME }}
190+
# Determines if we should publish/announce
191+
host:
189192
needs:
190193
- plan
191-
- upload-local-artifacts
192-
- upload-global-artifacts
193-
if: ${{ needs.plan.outputs.publishing == 'true' }}
194-
runs-on: self-hosted
195-
steps:
196-
- name: print tag
197-
run: echo "ok we're publishing!"
198-
199-
publish-homebrew-formula:
200-
needs: [plan, should-publish]
201-
runs-on: "ubuntu-20.04"
194+
- build-local-artifacts
195+
- build-global-artifacts
196+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
197+
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') }}
202198
env:
203199
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
204-
PLAN: ${{ needs.plan.outputs.val }}
205-
GITHUB_USER: "axo bot"
206-
GITHUB_EMAIL: "admin+bot@axo.dev"
207-
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
200+
runs-on: "ubuntu-20.04"
201+
outputs:
202+
val: ${{ steps.host.outputs.manifest }}
208203
steps:
209204
- uses: actions/checkout@v4
210205
with:
211-
repository: "polytope-labs/hyperbridge"
212-
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
213-
# So we have access to the formula
214-
- name: Fetch local artifacts
206+
submodules: recursive
207+
- name: Install cargo-dist
208+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.8.0/cargo-dist-installer.sh | sh"
209+
# Fetch artifacts from scratch-storage
210+
- name: Fetch artifacts
215211
uses: actions/download-artifact@v3
216212
with:
217213
name: artifacts
218-
path: Formula/
219-
- name: Commit formula files
214+
path: target/distrib/
215+
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
216+
- id: host
217+
shell: bash
220218
run: |
221-
git config --global user.name "${GITHUB_USER}"
222-
git config --global user.email "${GITHUB_EMAIL}"
223-
224-
for release in $(echo "$PLAN" | jq --compact-output '.releases[]'); do
225-
name=$(echo "$release" | jq .app_name --raw-output)
226-
version=$(echo "$release" | jq .app_version --raw-output)
227-
228-
git add Formula/${name}.rb
229-
git commit -m "${name} ${version}"
230-
done
231-
git push
219+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
220+
echo "artifacts uploaded and released successfully"
221+
cat dist-manifest.json
222+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
223+
- name: "Upload dist-manifest.json"
224+
uses: actions/upload-artifact@v3
225+
with:
226+
name: artifacts
227+
path: dist-manifest.json
232228

233-
# Create a Github Release with all the results once everything is done
234-
publish-release:
235-
needs: [plan, should-publish]
236-
runs-on: self-hosted
229+
# Create a Github Release while uploading all files to it
230+
announce:
231+
needs:
232+
- plan
233+
- host
234+
# use "always() && ..." to allow us to wait for all publish jobs while
235+
# still allowing individual publish jobs to skip themselves (for prereleases).
236+
# "host" however must run to completion, no skipping allowed!
237+
if: ${{ always() && needs.host.result == 'success' }}
238+
runs-on: "ubuntu-20.04"
237239
env:
238240
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
239241
steps:
240242
- uses: actions/checkout@v4
241243
with:
242244
submodules: recursive
243-
- name: "Download artifacts"
245+
- name: "Download Github Artifacts"
244246
uses: actions/download-artifact@v3
245247
with:
246248
name: artifacts
247249
path: artifacts
248250
- name: Cleanup
249251
run: |
250252
# Remove the granular manifests
251-
rm artifacts/*-dist-manifest.json
252-
- name: Create Release
253+
rm -f artifacts/*-dist-manifest.json
254+
- name: Create Github Release
253255
uses: ncipollo/release-action@v1
254256
with:
255257
tag: ${{ needs.plan.outputs.tag }}
256-
name: ${{ fromJson(needs.plan.outputs.val).announcement_title }}
257-
body: ${{ fromJson(needs.plan.outputs.val).announcement_github_body }}
258-
prerelease: ${{ fromJson(needs.plan.outputs.val).announcement_is_prerelease }}
258+
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
259+
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
260+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
259261
artifacts: "artifacts/*"

Cargo.toml

+3-5
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,17 @@ cargo-dist-version = "0.8.0"
5050
# CI backends to support
5151
ci = ["github"]
5252
# The installers to generate for each app
53-
installers = ["shell", "homebrew"]
53+
installers = ["shell"]
5454
# A GitHub repo to push Homebrew formulas to
5555
tap = "polytope-labs/hyperbridge"
5656
# Target platforms to build apps for (Rust target-triple syntax)
57-
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]
57+
targets = ["x86_64-unknown-linux-gnu"]
5858
# The archive format to use for non-windows builds (defaults .tar.xz)
5959
unix-archive = ".tar.gz"
6060
# Publish jobs to run in CI
6161
pr-run-mode = "upload"
6262
# Skip checking whether the specified configuration files are up to date
63-
allow-dirty = ["ci", "msi"]
64-
# Publish jobs to run in CI
65-
publish-jobs = ["homebrew"]
63+
allow-dirty = ["ci"]
6664

6765
# The profile that 'cargo dist' will build with
6866
[profile.dist]

0 commit comments

Comments
 (0)