Skip to content

Commit e2af121

Browse files
committed
Init nrev project
0 parents  commit e2af121

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+16242
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scripts/* linguist-vendored

.github/workflows/release.yml

Lines changed: 322 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,322 @@
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+
14+
name: Release
15+
permissions:
16+
"contents": "write"
17+
18+
# This task will run whenever you push a git tag that looks like a version
19+
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
20+
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
21+
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
22+
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
23+
#
24+
# If PACKAGE_NAME is specified, then the announcement will be for that
25+
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
26+
#
27+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
28+
# (cargo-dist-able) packages in the workspace with that version (this mode is
29+
# intended for workspaces with only one dist-able package, or with all dist-able
30+
# packages versioned/released in lockstep).
31+
#
32+
# If you push multiple tags at once, separate instances of this workflow will
33+
# spin up, creating an independent announcement for each one. However, GitHub
34+
# will hard limit this to 3 tags per commit, as it will assume more tags is a
35+
# mistake.
36+
#
37+
# If there's a prerelease-style suffix to the version, then the release(s)
38+
# will be marked as a prerelease.
39+
on:
40+
pull_request:
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-20.04"
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.18.0/cargo-dist-installer.sh | sh"
65+
- name: Cache cargo-dist
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: cargo-dist-cache
69+
path: ~/.cargo/bin/cargo-dist
70+
# sure would be cool if github gave us proper conditionals...
71+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
72+
# functionality based on whether this is a pull_request, and whether it's from a fork.
73+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
74+
# but also really annoying to build CI around when it needs secrets to work right.)
75+
- id: plan
76+
run: |
77+
cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
78+
echo "cargo dist ran successfully"
79+
cat plan-dist-manifest.json
80+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
81+
- name: "Upload dist-manifest.json"
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: artifacts-plan-dist-manifest
85+
path: plan-dist-manifest.json
86+
87+
# Build and packages all the platform-specific things
88+
build-local-artifacts:
89+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
90+
# Let the initial task tell us to not run (currently very blunt)
91+
needs:
92+
- plan
93+
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') }}
94+
strategy:
95+
fail-fast: false
96+
# Target platforms/runners are computed by cargo-dist in create-release.
97+
# Each member of the matrix has the following arguments:
98+
#
99+
# - runner: the github runner
100+
# - dist-args: cli flags to pass to cargo dist
101+
# - install-dist: expression to run to install cargo-dist on the runner
102+
#
103+
# Typically there will be:
104+
# - 1 "global" task that builds universal installers
105+
# - N "local" tasks that build each platform's binaries and platform-specific installers
106+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
107+
runs-on: ${{ matrix.runner }}
108+
env:
109+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
111+
steps:
112+
- name: enable windows longpaths
113+
run: |
114+
git config --global core.longpaths true
115+
- uses: actions/checkout@v4
116+
with:
117+
submodules: recursive
118+
- name: Install cargo-dist
119+
run: ${{ matrix.install_dist }}
120+
# Get the dist-manifest
121+
- name: Fetch local artifacts
122+
uses: actions/download-artifact@v4
123+
with:
124+
pattern: artifacts-*
125+
path: target/distrib/
126+
merge-multiple: true
127+
- name: Install dependencies
128+
run: |
129+
${{ matrix.packages_install }}
130+
- name: Build artifacts
131+
run: |
132+
# Actually do builds and make zips and whatnot
133+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
134+
echo "cargo dist ran successfully"
135+
- id: cargo-dist
136+
name: Post-build
137+
# We force bash here just because github makes it really hard to get values up
138+
# to "real" actions without writing to env-vars, and writing to env-vars has
139+
# inconsistent syntax between shell and powershell.
140+
shell: bash
141+
run: |
142+
# Parse out what we just built and upload it to scratch storage
143+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
144+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
145+
echo "EOF" >> "$GITHUB_OUTPUT"
146+
147+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
148+
- name: "Upload artifacts"
149+
uses: actions/upload-artifact@v4
150+
with:
151+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
152+
path: |
153+
${{ steps.cargo-dist.outputs.paths }}
154+
${{ env.BUILD_MANIFEST_NAME }}
155+
156+
# Build and package all the platform-agnostic(ish) things
157+
build-global-artifacts:
158+
needs:
159+
- plan
160+
- build-local-artifacts
161+
runs-on: "ubuntu-20.04"
162+
env:
163+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
165+
steps:
166+
- uses: actions/checkout@v4
167+
with:
168+
submodules: recursive
169+
- name: Install cached cargo-dist
170+
uses: actions/download-artifact@v4
171+
with:
172+
name: cargo-dist-cache
173+
path: ~/.cargo/bin/
174+
- run: chmod +x ~/.cargo/bin/cargo-dist
175+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
176+
- name: Fetch local artifacts
177+
uses: actions/download-artifact@v4
178+
with:
179+
pattern: artifacts-*
180+
path: target/distrib/
181+
merge-multiple: true
182+
- id: cargo-dist
183+
shell: bash
184+
run: |
185+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
186+
echo "cargo dist ran successfully"
187+
188+
# Parse out what we just built and upload it to scratch storage
189+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
190+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
191+
echo "EOF" >> "$GITHUB_OUTPUT"
192+
193+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
194+
- name: "Upload artifacts"
195+
uses: actions/upload-artifact@v4
196+
with:
197+
name: artifacts-build-global
198+
path: |
199+
${{ steps.cargo-dist.outputs.paths }}
200+
${{ env.BUILD_MANIFEST_NAME }}
201+
# Determines if we should publish/announce
202+
host:
203+
needs:
204+
- plan
205+
- build-local-artifacts
206+
- build-global-artifacts
207+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
208+
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') }}
209+
env:
210+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
211+
runs-on: "ubuntu-20.04"
212+
outputs:
213+
val: ${{ steps.host.outputs.manifest }}
214+
steps:
215+
- uses: actions/checkout@v4
216+
with:
217+
submodules: recursive
218+
- name: Install cached cargo-dist
219+
uses: actions/download-artifact@v4
220+
with:
221+
name: cargo-dist-cache
222+
path: ~/.cargo/bin/
223+
- run: chmod +x ~/.cargo/bin/cargo-dist
224+
# Fetch artifacts from scratch-storage
225+
- name: Fetch artifacts
226+
uses: actions/download-artifact@v4
227+
with:
228+
pattern: artifacts-*
229+
path: target/distrib/
230+
merge-multiple: true
231+
- id: host
232+
shell: bash
233+
run: |
234+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
235+
echo "artifacts uploaded and released successfully"
236+
cat dist-manifest.json
237+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
238+
- name: "Upload dist-manifest.json"
239+
uses: actions/upload-artifact@v4
240+
with:
241+
# Overwrite the previous copy
242+
name: artifacts-dist-manifest
243+
path: dist-manifest.json
244+
# Create a GitHub Release while uploading all files to it
245+
- name: "Download GitHub Artifacts"
246+
uses: actions/download-artifact@v4
247+
with:
248+
pattern: artifacts-*
249+
path: artifacts
250+
merge-multiple: true
251+
- name: Cleanup
252+
run: |
253+
# Remove the granular manifests
254+
rm -f artifacts/*-dist-manifest.json
255+
- name: Create GitHub Release
256+
env:
257+
PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}"
258+
ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}"
259+
ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}"
260+
RELEASE_COMMIT: "${{ github.sha }}"
261+
run: |
262+
# Write and read notes from a file to avoid quoting breaking things
263+
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
264+
265+
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*
266+
267+
publish-homebrew-formula:
268+
needs:
269+
- plan
270+
- host
271+
runs-on: "ubuntu-20.04"
272+
env:
273+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
274+
PLAN: ${{ needs.plan.outputs.val }}
275+
GITHUB_USER: "axo bot"
276+
GITHUB_EMAIL: "[email protected]"
277+
if: ${{ !fromJson(needs.plan.outputs.val).announcement_is_prerelease || fromJson(needs.plan.outputs.val).publish_prereleases }}
278+
steps:
279+
- uses: actions/checkout@v4
280+
with:
281+
repository: "shellrow/homebrew-tap-nrev"
282+
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
283+
# So we have access to the formula
284+
- name: Fetch homebrew formulae
285+
uses: actions/download-artifact@v4
286+
with:
287+
pattern: artifacts-*
288+
path: Formula/
289+
merge-multiple: true
290+
# This is extra complex because you can make your Formula name not match your app name
291+
# so we need to find releases with a *.rb file, and publish with that filename.
292+
- name: Commit formula files
293+
run: |
294+
git config --global user.name "${GITHUB_USER}"
295+
git config --global user.email "${GITHUB_EMAIL}"
296+
297+
for release in $(echo "$PLAN" | jq --compact-output '.releases[] | select([.artifacts[] | endswith(".rb")] | any)'); do
298+
filename=$(echo "$release" | jq '.artifacts[] | select(endswith(".rb"))' --raw-output)
299+
name=$(echo "$filename" | sed "s/\.rb$//")
300+
version=$(echo "$release" | jq .app_version --raw-output)
301+
302+
git add "Formula/${filename}"
303+
git commit -m "${name} ${version}"
304+
done
305+
git push
306+
307+
announce:
308+
needs:
309+
- plan
310+
- host
311+
- publish-homebrew-formula
312+
# use "always() && ..." to allow us to wait for all publish jobs while
313+
# still allowing individual publish jobs to skip themselves (for prereleases).
314+
# "host" however must run to completion, no skipping allowed!
315+
if: ${{ always() && needs.host.result == 'success' && (needs.publish-homebrew-formula.result == 'skipped' || needs.publish-homebrew-formula.result == 'success') }}
316+
runs-on: "ubuntu-20.04"
317+
env:
318+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
319+
steps:
320+
- uses: actions/checkout@v4
321+
with:
322+
submodules: recursive

.github/workflows/rust.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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: Build
20+
run: cargo build --verbose
21+

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk
12+
13+
# MSVC Windows builds of rustc generate these, which store debugging information
14+
*.pdb
15+
16+
# macOS
17+
.DS_Store
18+
19+
# dist
20+
dist/

0 commit comments

Comments
 (0)