Skip to content

Commit 7aabf5b

Browse files
committed
Add github actions for the future
1 parent 928e211 commit 7aabf5b

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

.github/workflows/release.yml

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# CI that:
2+
#
3+
# * checks for a Git Tag that looks like a release
4+
# * creates a Github Release™ and fills in its text
5+
# * builds artifacts with cargo-dist (executable-zips, installers)
6+
# * uploads those artifacts to the Github Release™
7+
#
8+
# Note that the Github Release™ will be created before the artifacts,
9+
# so there will be a few minutes where the release has no artifacts
10+
# and then they will slowly trickle in, possibly failing. To make
11+
# this more pleasant we mark the release as a "draft" until all
12+
# artifacts have been successfully uploaded. This allows you to
13+
# choose what to do with partial successes and avoids spamming
14+
# anyone with notifications before the release is actually ready.
15+
name: Release
16+
17+
permissions:
18+
contents: write
19+
20+
# This task will run whenever you push a git tag that looks like a version
21+
# like "v1", "v1.2.0", "v0.1.0-prerelease01", "my-app-v1.0.0", etc.
22+
# The version will be roughly parsed as ({PACKAGE_NAME}-)?v{VERSION}, where
23+
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
24+
# must be a Cargo-style SemVer Version.
25+
#
26+
# If PACKAGE_NAME is specified, then we will create a Github Release™ for that
27+
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
28+
#
29+
# If PACKAGE_NAME isn't specified, then we will create a Github Release™ for all
30+
# (cargo-dist-able) packages in the workspace with that version (this is mode is
31+
# intended for workspaces with only one dist-able package, or with all dist-able
32+
# packages versioned/released in lockstep).
33+
#
34+
# If you push multiple tags at once, separate instances of this workflow will
35+
# spin up, creating an independent Github Release™ for each one.
36+
#
37+
# If there's a prerelease-style suffix to the version then the Github Release™
38+
# will be marked as a prerelease.
39+
on:
40+
push:
41+
tags:
42+
- '*-?v[0-9]+*'
43+
44+
jobs:
45+
# Create the Github Release™ so the packages have something to be uploaded to
46+
create-release:
47+
runs-on: ubuntu-latest
48+
outputs:
49+
has-releases: ${{ steps.create-release.outputs.has-releases }}
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
steps:
53+
- uses: actions/checkout@v3
54+
- name: Install Rust
55+
run: rustup update 1.67.1 --no-self-update && rustup default 1.67.1
56+
- name: Install cargo-dist
57+
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.6/cargo-dist-installer.sh | sh
58+
- id: create-release
59+
run: |
60+
cargo dist plan --tag=${{ github.ref_name }} --output-format=json > dist-manifest.json
61+
echo "dist plan ran successfully"
62+
cat dist-manifest.json
63+
64+
# Create the Github Release™ based on what cargo-dist thinks it should be
65+
ANNOUNCEMENT_TITLE=$(jq --raw-output ".announcement_title" dist-manifest.json)
66+
IS_PRERELEASE=$(jq --raw-output ".announcement_is_prerelease" dist-manifest.json)
67+
jq --raw-output ".announcement_github_body" dist-manifest.json > new_dist_announcement.md
68+
gh release create ${{ github.ref_name }} --draft --prerelease="$IS_PRERELEASE" --title="$ANNOUNCEMENT_TITLE" --notes-file=new_dist_announcement.md
69+
echo "created announcement!"
70+
71+
# Upload the manifest to the Github Release™
72+
gh release upload ${{ github.ref_name }} dist-manifest.json
73+
echo "uploaded manifest!"
74+
75+
# Disable all the upload-artifacts tasks if we have no actual releases
76+
HAS_RELEASES=$(jq --raw-output ".releases != null" dist-manifest.json)
77+
echo "has-releases=$HAS_RELEASES" >> "$GITHUB_OUTPUT"
78+
79+
# Build and packages all the things
80+
upload-artifacts:
81+
# Let the initial task tell us to not run (currently very blunt)
82+
needs: create-release
83+
if: ${{ needs.create-release.outputs.has-releases == 'true' }}
84+
strategy:
85+
matrix:
86+
# For these target platforms
87+
include:
88+
- os: macos-11
89+
dist-args: --artifacts=local --target=aarch64-apple-darwin --target=x86_64-apple-darwin
90+
install-dist: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.6/cargo-dist-installer.sh | sh
91+
- os: ubuntu-20.04
92+
dist-args: --artifacts=local --target=x86_64-unknown-linux-gnu
93+
install-dist: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.0.6/cargo-dist-installer.sh | sh
94+
95+
runs-on: ${{ matrix.os }}
96+
env:
97+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
steps:
99+
- uses: actions/checkout@v3
100+
- name: Install Rust
101+
run: rustup update 1.67.1 --no-self-update && rustup default 1.67.1
102+
- name: Install cargo-dist
103+
run: ${{ matrix.install-dist }}
104+
- name: Run cargo-dist
105+
# This logic is a bit janky because it's trying to be a polyglot between
106+
# powershell and bash since this will run on windows, macos, and linux!
107+
# The two platforms don't agree on how to talk about env vars but they
108+
# do agree on 'cat' and '$()' so we use that to marshal values between commands.
109+
run: |
110+
# Actually do builds and make zips and whatnot
111+
cargo dist build --tag=${{ github.ref_name }} --output-format=json ${{ matrix.dist-args }} > dist-manifest.json
112+
echo "dist ran successfully"
113+
cat dist-manifest.json
114+
115+
# Parse out what we just built and upload it to the Github Release™
116+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt
117+
echo "uploading..."
118+
cat uploads.txt
119+
gh release upload ${{ github.ref_name }} $(cat uploads.txt)
120+
echo "uploaded!"
121+
122+
# Mark the Github Release™ as a non-draft now that everything has succeeded!
123+
publish-release:
124+
# Only run after all the other tasks, but it's ok if upload-artifacts was skipped
125+
needs: [create-release, upload-artifacts]
126+
if: ${{ always() && needs.create-release.result == 'success' && (needs.upload-artifacts.result == 'skipped' || needs.upload-artifacts.result == 'success') }}
127+
runs-on: ubuntu-latest
128+
env:
129+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130+
steps:
131+
- uses: actions/checkout@v3
132+
- name: mark release as non-draft
133+
run: |
134+
gh release edit ${{ github.ref_name }} --draft=false

.github/workflows/rust.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Prepare cargo-lambda
20+
run: pip3 install ziglang && cargo install cargo-lambda
21+
- name: Build
22+
run: cargo lambda build
23+
- name: Run tests
24+
run: cargo test --verbose

0 commit comments

Comments
 (0)