Skip to content

Commit a7f8e06

Browse files
authored
Merge pull request #93 from Ph0enixKM/92-automate-the-process-of-creating-new-releases
Automate the process of creating new releases #92
2 parents 4f5b458 + 726a808 commit a7f8e06

File tree

7 files changed

+375
-11
lines changed

7 files changed

+375
-11
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release Linux ARM
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
release:
8+
types: [released]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Install dependencies
19+
run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev
20+
21+
- name: Install cross
22+
run: cargo install cross
23+
24+
- name: Build with cross
25+
run: cross build --release --target aarch64-unknown-linux-gnu
26+
27+
- name: Create .tar.xz archive
28+
run: |
29+
cd target/aarch64-unknown-linux-gnu/release
30+
tar -cJf amber-aarch64-unknown-linux-gnu.tar.xz amber
31+
32+
- name: Upload Release Asset
33+
uses: softprops/action-gh-release@v2
34+
with:
35+
files: target/aarch64-unknown-linux-gnu/release/amber-aarch64-unknown-linux-gnu.tar.xz

.github/workflows/release.yml

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
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 a GitHub Release with this tag is assumed to exist as a draft
12+
# with the appropriate title/body, and will be undrafted for you.
13+
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.
40+
on:
41+
push:
42+
tags:
43+
- '**[0-9]+.[0-9]+.[0-9]+*'
44+
45+
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 }}
56+
steps:
57+
- uses: actions/checkout@v4
58+
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.14.1/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
71+
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@v4
78+
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
106+
steps:
107+
- name: enable windows longpaths
108+
run: |
109+
git config --global core.longpaths true
110+
- uses: actions/checkout@v4
111+
with:
112+
submodules: recursive
113+
- uses: swatinem/rust-cache@v2
114+
with:
115+
key: ${{ join(matrix.targets, '-') }}
116+
- name: Install cargo-dist
117+
run: ${{ matrix.install_dist }}
118+
# Get the dist-manifest
119+
- name: Fetch local artifacts
120+
uses: actions/download-artifact@v4
121+
with:
122+
pattern: artifacts-*
123+
path: target/distrib/
124+
merge-multiple: true
125+
- name: Install dependencies
126+
run: |
127+
${{ matrix.packages_install }}
128+
- name: Build artifacts
129+
run: |
130+
# Actually do builds and make zips and whatnot
131+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
132+
echo "cargo dist ran successfully"
133+
- id: cargo-dist
134+
name: Post-build
135+
# We force bash here just because github makes it really hard to get values up
136+
# to "real" actions without writing to env-vars, and writing to env-vars has
137+
# inconsistent syntax between shell and powershell.
138+
shell: bash
139+
run: |
140+
# Parse out what we just built and upload it to scratch storage
141+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
142+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
143+
echo "EOF" >> "$GITHUB_OUTPUT"
144+
145+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
146+
- name: "Upload artifacts"
147+
uses: actions/upload-artifact@v4
148+
with:
149+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
150+
path: |
151+
${{ steps.cargo-dist.outputs.paths }}
152+
${{ env.BUILD_MANIFEST_NAME }}
153+
154+
# Build and package all the platform-agnostic(ish) things
155+
build-global-artifacts:
156+
needs:
157+
- plan
158+
- build-local-artifacts
159+
runs-on: "ubuntu-20.04"
160+
env:
161+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
162+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
163+
steps:
164+
- uses: actions/checkout@v4
165+
with:
166+
submodules: recursive
167+
- name: Install cargo-dist
168+
shell: bash
169+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.14.1/cargo-dist-installer.sh | sh"
170+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
171+
- name: Fetch local artifacts
172+
uses: actions/download-artifact@v4
173+
with:
174+
pattern: artifacts-*
175+
path: target/distrib/
176+
merge-multiple: true
177+
- id: cargo-dist
178+
shell: bash
179+
run: |
180+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
181+
echo "cargo dist ran successfully"
182+
183+
# Parse out what we just built and upload it to scratch storage
184+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
185+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
186+
echo "EOF" >> "$GITHUB_OUTPUT"
187+
188+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
189+
- name: "Upload artifacts"
190+
uses: actions/upload-artifact@v4
191+
with:
192+
name: artifacts-build-global
193+
path: |
194+
${{ steps.cargo-dist.outputs.paths }}
195+
${{ env.BUILD_MANIFEST_NAME }}
196+
# Determines if we should publish/announce
197+
host:
198+
needs:
199+
- plan
200+
- build-local-artifacts
201+
- build-global-artifacts
202+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
203+
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') }}
204+
env:
205+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206+
runs-on: "ubuntu-20.04"
207+
outputs:
208+
val: ${{ steps.host.outputs.manifest }}
209+
steps:
210+
- uses: actions/checkout@v4
211+
with:
212+
submodules: recursive
213+
- name: Install cargo-dist
214+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.14.1/cargo-dist-installer.sh | sh"
215+
# Fetch artifacts from scratch-storage
216+
- name: Fetch artifacts
217+
uses: actions/download-artifact@v4
218+
with:
219+
pattern: artifacts-*
220+
path: target/distrib/
221+
merge-multiple: true
222+
# This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
223+
- id: host
224+
shell: bash
225+
run: |
226+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
227+
echo "artifacts uploaded and released successfully"
228+
cat dist-manifest.json
229+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
230+
- name: "Upload dist-manifest.json"
231+
uses: actions/upload-artifact@v4
232+
with:
233+
# Overwrite the previous copy
234+
name: artifacts-dist-manifest
235+
path: dist-manifest.json
236+
237+
# Create a GitHub Release while uploading all files to it
238+
announce:
239+
needs:
240+
- plan
241+
- host
242+
# use "always() && ..." to allow us to wait for all publish jobs while
243+
# still allowing individual publish jobs to skip themselves (for prereleases).
244+
# "host" however must run to completion, no skipping allowed!
245+
if: ${{ always() && needs.host.result == 'success' }}
246+
runs-on: "ubuntu-20.04"
247+
env:
248+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
249+
steps:
250+
- uses: actions/checkout@v4
251+
with:
252+
submodules: recursive
253+
- name: "Download GitHub Artifacts"
254+
uses: actions/download-artifact@v4
255+
with:
256+
pattern: artifacts-*
257+
path: artifacts
258+
merge-multiple: true
259+
- name: Cleanup
260+
run: |
261+
# Remove the granular manifests
262+
rm -f artifacts/*-dist-manifest.json
263+
- name: Create GitHub Release
264+
uses: ncipollo/release-action@v1
265+
with:
266+
tag: ${{ needs.plan.outputs.tag }}
267+
allowUpdates: true
268+
updateOnlyUnreleased: false
269+
omitBodyDuringUpdate: true
270+
omitNameDuringUpdate: true
271+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
272+
artifacts: "artifacts/*"

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
22
name = "amber"
3-
version = "0.3.1-alpha"
3+
version = "0.3.2-alpha"
44
edition = "2021"
5+
repository = "https://github.com/Ph0enixKM/Amber"
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

@@ -17,3 +18,25 @@ tempfile = "3.10.1"
1718
strip = true
1819
lto = true
1920
opt-level = 3
21+
22+
# The profile that 'cargo dist' will build with
23+
[profile.dist]
24+
inherits = "release"
25+
lto = "thin"
26+
27+
# Config for 'cargo dist'
28+
[workspace.metadata.dist]
29+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
30+
cargo-dist-version = "0.14.1"
31+
# CI backends to support
32+
ci = "github"
33+
# The installers to generate for each app
34+
installers = []
35+
# Target platforms to build apps for (Rust target-triple syntax)
36+
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]
37+
# Publish jobs to run in CI
38+
pr-run-mode = "skip"
39+
# Whether cargo-dist should create a Github Release or use an existing draft
40+
create-release = false
41+
# Allow modifying the release.yml
42+
allow-dirty = ["ci"]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ AMBER_DEBUG_TIME=true cargo run <file.ab>
8383
// Flamegraph is a profiling tool that is used to visualize the time each function took to execute
8484
sudo cargo flamegraph -- <file.ab> <file.sh>
8585
```
86+
87+
## Github Actions
88+
We are using `cargo-dist` to build the binaries for all the platforms. The binaries are then uploaded to the release page once a new release a tag is created.

0 commit comments

Comments
 (0)