Skip to content

Commit 534cf87

Browse files
committed
feat: add dist, update README
1 parent bb08517 commit 534cf87

File tree

5 files changed

+554
-112
lines changed

5 files changed

+554
-112
lines changed

.github/workflows/release.yml

Lines changed: 272 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,293 @@
1-
name: Release
1+
# This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/
2+
#
3+
# Copyright 2022-2024, axodotdev
4+
# SPDX-License-Identifier: MIT or Apache-2.0
5+
#
6+
# CI that:
7+
#
8+
# * checks for a Git Tag that looks like a release
9+
# * builds artifacts with dist (archives, installers, hashes)
10+
# * uploads those artifacts to temporary workflow zip
11+
# * on success, uploads the artifacts to a GitHub Release
12+
#
13+
# Note that the GitHub Release will be created with a generated
14+
# title/body based on your changelogs.
215

3-
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/
4-
# https://mateuscosta.me/rust-releases-with-github-actions
16+
name: Release
17+
permissions:
18+
"contents": "write"
519

20+
# This task will run whenever you push a git tag that looks like a version
21+
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
22+
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, 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 (must have at least major.minor.patch).
25+
#
26+
# If PACKAGE_NAME is specified, then the announcement will be for that
27+
# package (erroring out if it doesn't have the given version or isn't dist-able).
28+
#
29+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
30+
# (dist-able) packages in the workspace with that version (this 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 announcement for each one. However, GitHub
36+
# will hard limit this to 3 tags per commit, as it will assume more tags is a
37+
# mistake.
38+
#
39+
# If there's a prerelease-style suffix to the version, then the release(s)
40+
# will be marked as a prerelease.
641
on:
42+
pull_request:
743
push:
844
tags:
9-
- 'v[0-9]+.*'
45+
- '**[0-9]+.[0-9]+.[0-9]+*'
1046

1147
jobs:
12-
security_audit:
13-
runs-on: ubuntu-latest
48+
# Run 'dist plan' (or host) to determine what tasks we need to do
49+
plan:
50+
runs-on: "ubuntu-20.04"
51+
outputs:
52+
val: ${{ steps.plan.outputs.manifest }}
53+
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
54+
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
55+
publishing: ${{ !github.event.pull_request }}
56+
env:
57+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1458
steps:
1559
- uses: actions/checkout@v4
16-
- uses: actions-rs/audit-check@v1
1760
with:
18-
token: ${{ secrets.GITHUB_TOKEN }}
61+
submodules: recursive
62+
- name: Install dist
63+
# we specify bash to get pipefail; it guards against the `curl` command
64+
# failing. otherwise `sh` won't catch that `curl` returned non-0
65+
shell: bash
66+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.27.0/cargo-dist-installer.sh | sh"
67+
- name: Cache dist
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: cargo-dist-cache
71+
path: ~/.cargo/bin/dist
72+
# sure would be cool if github gave us proper conditionals...
73+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
74+
# functionality based on whether this is a pull_request, and whether it's from a fork.
75+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
76+
# but also really annoying to build CI around when it needs secrets to work right.)
77+
- id: plan
78+
run: |
79+
dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
80+
echo "dist ran successfully"
81+
cat plan-dist-manifest.json
82+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
83+
- name: "Upload dist-manifest.json"
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: artifacts-plan-dist-manifest
87+
path: plan-dist-manifest.json
1988

20-
create_release:
21-
name: Create release
22-
runs-on: ubuntu-latest
23-
# Note this. We are going to use that in further jobs.
24-
outputs:
25-
upload_url: ${{ steps.create_release.outputs.upload_url }}
89+
# Build and packages all the platform-specific things
90+
build-local-artifacts:
91+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
92+
# Let the initial task tell us to not run (currently very blunt)
93+
needs:
94+
- plan
95+
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') }}
96+
strategy:
97+
fail-fast: false
98+
# Target platforms/runners are computed by dist in create-release.
99+
# Each member of the matrix has the following arguments:
100+
#
101+
# - runner: the github runner
102+
# - dist-args: cli flags to pass to dist
103+
# - install-dist: expression to run to install dist on the runner
104+
#
105+
# Typically there will be:
106+
# - 1 "global" task that builds universal installers
107+
# - N "local" tasks that build each platform's binaries and platform-specific installers
108+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
109+
runs-on: ${{ matrix.runner }}
110+
container: ${{ matrix.container && matrix.container.image || null }}
111+
env:
112+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
26114
steps:
27-
- name: Set variables
28-
id: vars
29-
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
30-
31-
- name: Create release
32-
id: create_release
33-
uses: actions/create-release@v1
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
with:
37-
tag_name: ${{ github.ref }}
38-
release_name: Release ${{ github.ref }}
39-
draft: false
40-
prerelease: false
41-
body: |
42-
This is a new release of Pomsky. See what's new in the [changelog](https://github.com/pomsky-lang/pomsky/blob/${{ steps.vars.outputs.tag }}/CHANGELOG.md).
43-
44-
### Installation
45-
If you're running on Linux, macOS or Windows, you can use the binaries below.
46-
47-
On Arch Linux, you can install `pomsky-bin` from the AUR with
48-
```shell
49-
$ yay -S pomsky-bin
50-
```
51-
52-
You can also build Pomsky with Cargo, Rusts package manager. To install the Rust toolchain, see the [installation manual](https://www.rust-lang.org/tools/install). Then run
53-
```shell
54-
$ cargo install pomsky-bin
55-
```
56-
57-
You might have to add the `.cargo/bin` folder to your `PATH` afterwards.
58-
Please file issues if you run into any problems or have suggestions.
115+
- name: enable windows longpaths
116+
run: |
117+
git config --global core.longpaths true
118+
- uses: actions/checkout@v4
119+
with:
120+
submodules: recursive
121+
- name: Install Rust non-interactively if not already installed
122+
if: ${{ matrix.container }}
123+
run: |
124+
if ! command -v cargo > /dev/null 2>&1; then
125+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
126+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
127+
fi
128+
- name: Install dist
129+
run: ${{ matrix.install_dist.run }}
130+
# Get the dist-manifest
131+
- name: Fetch local artifacts
132+
uses: actions/download-artifact@v4
133+
with:
134+
pattern: artifacts-*
135+
path: target/distrib/
136+
merge-multiple: true
137+
- name: Install cargo-auditable
138+
run: ${{ matrix.install_cargo_auditable.run }}
139+
- name: Install dependencies
140+
run: |
141+
${{ matrix.packages_install }}
142+
- name: Build artifacts
143+
run: |
144+
# Actually do builds and make zips and whatnot
145+
dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
146+
echo "dist ran successfully"
147+
- id: cargo-dist
148+
name: Post-build
149+
# We force bash here just because github makes it really hard to get values up
150+
# to "real" actions without writing to env-vars, and writing to env-vars has
151+
# inconsistent syntax between shell and powershell.
152+
shell: bash
153+
run: |
154+
# Parse out what we just built and upload it to scratch storage
155+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
156+
dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
157+
echo "EOF" >> "$GITHUB_OUTPUT"
59158
60-
release_assets:
61-
name: Release assets
62-
needs: create_release
63-
runs-on: ${{ matrix.os }}
64-
strategy:
65-
matrix:
66-
include:
67-
- os: ubuntu-latest
68-
platform: linux
69-
file_ending: ''
70-
- os: macos-latest
71-
platform: macos
72-
file_ending: ''
73-
- os: windows-latest
74-
platform: windows
75-
file_ending: '.exe'
159+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
160+
- name: "Upload artifacts"
161+
uses: actions/upload-artifact@v4
162+
with:
163+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
164+
path: |
165+
${{ steps.cargo-dist.outputs.paths }}
166+
${{ env.BUILD_MANIFEST_NAME }}
76167
168+
# Build and package all the platform-agnostic(ish) things
169+
build-global-artifacts:
170+
needs:
171+
- plan
172+
- build-local-artifacts
173+
runs-on: "ubuntu-20.04"
174+
env:
175+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
77177
steps:
78-
- name: Checkout
79-
uses: actions/checkout@v4
178+
- uses: actions/checkout@v4
179+
with:
180+
submodules: recursive
181+
- name: Install cached dist
182+
uses: actions/download-artifact@v4
183+
with:
184+
name: cargo-dist-cache
185+
path: ~/.cargo/bin/
186+
- run: chmod +x ~/.cargo/bin/dist
187+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
188+
- name: Fetch local artifacts
189+
uses: actions/download-artifact@v4
190+
with:
191+
pattern: artifacts-*
192+
path: target/distrib/
193+
merge-multiple: true
194+
- id: cargo-dist
195+
shell: bash
196+
run: |
197+
dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
198+
echo "dist ran successfully"
80199
81-
- name: Install Rust toolchain
82-
uses: dtolnay/rust-toolchain@stable
200+
# Parse out what we just built and upload it to scratch storage
201+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
202+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
203+
echo "EOF" >> "$GITHUB_OUTPUT"
83204
84-
- name: Print information
205+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
206+
- name: "Upload artifacts"
207+
uses: actions/upload-artifact@v4
208+
with:
209+
name: artifacts-build-global
210+
path: |
211+
${{ steps.cargo-dist.outputs.paths }}
212+
${{ env.BUILD_MANIFEST_NAME }}
213+
# Determines if we should publish/announce
214+
host:
215+
needs:
216+
- plan
217+
- build-local-artifacts
218+
- build-global-artifacts
219+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
220+
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') }}
221+
env:
222+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
223+
runs-on: "ubuntu-20.04"
224+
outputs:
225+
val: ${{ steps.host.outputs.manifest }}
226+
steps:
227+
- uses: actions/checkout@v4
228+
with:
229+
submodules: recursive
230+
- name: Install cached dist
231+
uses: actions/download-artifact@v4
232+
with:
233+
name: cargo-dist-cache
234+
path: ~/.cargo/bin/
235+
- run: chmod +x ~/.cargo/bin/dist
236+
# Fetch artifacts from scratch-storage
237+
- name: Fetch artifacts
238+
uses: actions/download-artifact@v4
239+
with:
240+
pattern: artifacts-*
241+
path: target/distrib/
242+
merge-multiple: true
243+
- id: host
244+
shell: bash
85245
run: |
86-
rustup show active-toolchain
87-
rustc --version
88-
cargo tree
89-
- name: Set variables
90-
id: vars
91-
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
92-
93-
- name: Install build dependencies
94-
run: cargo install cargo-auditable
246+
dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
247+
echo "artifacts uploaded and released successfully"
248+
cat dist-manifest.json
249+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
250+
- name: "Upload dist-manifest.json"
251+
uses: actions/upload-artifact@v4
252+
with:
253+
# Overwrite the previous copy
254+
name: artifacts-dist-manifest
255+
path: dist-manifest.json
256+
# Create a GitHub Release while uploading all files to it
257+
- name: "Download GitHub Artifacts"
258+
uses: actions/download-artifact@v4
259+
with:
260+
pattern: artifacts-*
261+
path: artifacts
262+
merge-multiple: true
263+
- name: Cleanup
264+
run: |
265+
# Remove the granular manifests
266+
rm -f artifacts/*-dist-manifest.json
267+
- name: Create GitHub Release
268+
env:
269+
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
270+
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
271+
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
272+
RELEASE_COMMIT: "${{ github.sha }}"
273+
run: |
274+
# Write and read notes from a file to avoid quoting breaking things
275+
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
95276
96-
- name: Build project
97-
run: PCRE2_SYS_STATIC=1 cargo auditable build --profile dist --locked
277+
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
98278
99-
- name: Upload release assets
100-
uses: actions/upload-release-asset@v1
101-
env:
102-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
279+
announce:
280+
needs:
281+
- plan
282+
- host
283+
# use "always() && ..." to allow us to wait for all publish jobs while
284+
# still allowing individual publish jobs to skip themselves (for prereleases).
285+
# "host" however must run to completion, no skipping allowed!
286+
if: ${{ always() && needs.host.result == 'success' }}
287+
runs-on: "ubuntu-20.04"
288+
env:
289+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
290+
steps:
291+
- uses: actions/checkout@v4
103292
with:
104-
upload_url: ${{ needs.create_release.outputs.upload_url }}
105-
asset_name: pomsky_${{ matrix.platform }}_${{ steps.vars.outputs.tag }}${{ matrix.file_ending }}
106-
asset_path: target/dist/pomsky${{ matrix.file_ending }}
107-
asset_content_type: application/octet-stream
293+
submodules: recursive

0 commit comments

Comments
 (0)