Skip to content

Commit 966b31b

Browse files
committed
ci: release system for generate preview binary
1 parent 9744349 commit 966b31b

File tree

7 files changed

+397
-0
lines changed

7 files changed

+397
-0
lines changed

Diff for: β€Ž.github/workflows/changelog.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Generate CHANGELOG
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
plan:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
changelog:
12+
name: Generate changelog
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Generate a changelog
21+
uses: orhun/git-cliff-action@v3
22+
with:
23+
config: cliff.toml
24+
args: -vv --latest
25+
env:
26+
OUTPUT: CHANGELOG.md
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
GITHUB_REPO: ${{ github.repository }}
29+
30+
- name: Commit
31+
run: |
32+
git config user.name 'github-actions[bot]'
33+
git config user.email 'github-actions[bot]@users.noreply.github.com'
34+
set +e
35+
git add CHANGELOG.md
36+
git commit -m "Update changelog"
37+
git push origin main

Diff for: β€Ž.github/workflows/release.yml

+266
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
# Copyright 2022-2023, 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+
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+
pull_request:
45+
46+
jobs:
47+
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
48+
plan:
49+
runs-on: ubuntu-latest
50+
outputs:
51+
val: ${{ steps.plan.outputs.manifest }}
52+
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
53+
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
54+
publishing: ${{ !github.event.pull_request }}
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
steps:
58+
- uses: actions/checkout@v4
59+
with:
60+
submodules: recursive
61+
- 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
65+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.11.1/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.)
71+
- id: plan
72+
run: |
73+
cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
74+
echo "cargo dist ran successfully"
75+
cat plan-dist-manifest.json
76+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
77+
- name: "Upload dist-manifest.json"
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: artifacts-plan-dist-manifest
81+
path: plan-dist-manifest.json
82+
83+
# Build and packages all the platform-specific things
84+
build-local-artifacts:
85+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
86+
# Let the initial task tell us to not run (currently very blunt)
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') }}
90+
strategy:
91+
fail-fast: false
92+
# Target platforms/runners are computed by cargo-dist in create-release.
93+
# Each member of the matrix has the following arguments:
94+
#
95+
# - runner: the github runner
96+
# - dist-args: cli flags to pass to cargo dist
97+
# - install-dist: expression to run to install cargo-dist on the runner
98+
#
99+
# Typically there will be:
100+
# - 1 "global" task that builds universal installers
101+
# - N "local" tasks that build each platform's binaries and platform-specific installers
102+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
103+
runs-on: ${{ matrix.runner }}
104+
env:
105+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
107+
steps:
108+
- uses: actions/checkout@v4
109+
with:
110+
submodules: recursive
111+
- uses: swatinem/rust-cache@v2
112+
- name: Install cargo-dist
113+
run: ${{ matrix.install_dist }}
114+
# Get the dist-manifest
115+
- name: Fetch local artifacts
116+
uses: actions/download-artifact@v4
117+
with:
118+
pattern: artifacts-*
119+
path: target/distrib/
120+
merge-multiple: true
121+
- name: Install dependencies
122+
run: |
123+
${{ matrix.packages_install }}
124+
- name: Build artifacts
125+
run: |
126+
# Actually do builds and make zips and whatnot
127+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
128+
echo "cargo dist ran successfully"
129+
- id: cargo-dist
130+
name: Post-build
131+
# We force bash here just because github makes it really hard to get values up
132+
# to "real" actions without writing to env-vars, and writing to env-vars has
133+
# inconsistent syntax between shell and powershell.
134+
shell: bash
135+
run: |
136+
# Parse out what we just built and upload it to scratch storage
137+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
138+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
139+
echo "EOF" >> "$GITHUB_OUTPUT"
140+
141+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
142+
- name: "Upload artifacts"
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
146+
path: |
147+
${{ steps.cargo-dist.outputs.paths }}
148+
${{ env.BUILD_MANIFEST_NAME }}
149+
150+
# Build and package all the platform-agnostic(ish) things
151+
build-global-artifacts:
152+
needs:
153+
- plan
154+
- build-local-artifacts
155+
runs-on: "ubuntu-20.04"
156+
env:
157+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
159+
steps:
160+
- uses: actions/checkout@v4
161+
with:
162+
submodules: recursive
163+
- name: Install cargo-dist
164+
shell: bash
165+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.11.1/cargo-dist-installer.sh | sh"
166+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
167+
- name: Fetch local artifacts
168+
uses: actions/download-artifact@v4
169+
with:
170+
pattern: artifacts-*
171+
path: target/distrib/
172+
merge-multiple: true
173+
- id: cargo-dist
174+
shell: bash
175+
run: |
176+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
177+
echo "cargo dist ran successfully"
178+
179+
# Parse out what we just built and upload it to scratch storage
180+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
181+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
182+
echo "EOF" >> "$GITHUB_OUTPUT"
183+
184+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
185+
- name: "Upload artifacts"
186+
uses: actions/upload-artifact@v4
187+
with:
188+
name: artifacts-build-global
189+
path: |
190+
${{ steps.cargo-dist.outputs.paths }}
191+
${{ env.BUILD_MANIFEST_NAME }}
192+
# Determines if we should publish/announce
193+
host:
194+
needs:
195+
- plan
196+
- build-local-artifacts
197+
- build-global-artifacts
198+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
199+
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') }}
200+
env:
201+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
202+
runs-on: "ubuntu-20.04"
203+
outputs:
204+
val: ${{ steps.host.outputs.manifest }}
205+
steps:
206+
- uses: actions/checkout@v4
207+
with:
208+
submodules: recursive
209+
- name: Install cargo-dist
210+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.11.1/cargo-dist-installer.sh | sh"
211+
# Fetch artifacts from scratch-storage
212+
- name: Fetch artifacts
213+
uses: actions/download-artifact@v4
214+
with:
215+
pattern: artifacts-*
216+
path: target/distrib/
217+
merge-multiple: true
218+
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
219+
- id: host
220+
shell: bash
221+
run: |
222+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
223+
echo "artifacts uploaded and released successfully"
224+
cat dist-manifest.json
225+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
226+
- name: "Upload dist-manifest.json"
227+
uses: actions/upload-artifact@v4
228+
with:
229+
# Overwrite the previous copy
230+
name: artifacts-dist-manifest
231+
path: dist-manifest.json
232+
233+
# Create a Github Release while uploading all files to it
234+
announce:
235+
needs:
236+
- plan
237+
- host
238+
# use "always() && ..." to allow us to wait for all publish jobs while
239+
# still allowing individual publish jobs to skip themselves (for prereleases).
240+
# "host" however must run to completion, no skipping allowed!
241+
if: ${{ always() && needs.host.result == 'success' }}
242+
runs-on: "ubuntu-20.04"
243+
env:
244+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
245+
steps:
246+
- uses: actions/checkout@v4
247+
with:
248+
submodules: recursive
249+
- name: "Download Github Artifacts"
250+
uses: actions/download-artifact@v4
251+
with:
252+
pattern: artifacts-*
253+
path: artifacts
254+
merge-multiple: true
255+
- name: Cleanup
256+
run: |
257+
# Remove the granular manifests
258+
rm -f artifacts/*-dist-manifest.json
259+
- name: Create Github Release
260+
uses: ncipollo/release-action@v1
261+
with:
262+
tag: ${{ needs.plan.outputs.tag }}
263+
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
264+
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
265+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
266+
artifacts: "artifacts/*"

Diff for: β€ŽCargo.toml

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22
name = "rustmap"
33
version = "0.1.0"
44
edition = "2021"
5+
repository = "https://github.com/RustLangES/rustmap"
6+
7+
# Config for 'cargo dist'
8+
[workspace.metadata.dist]
9+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
10+
cargo-dist-version = "0.11.1"
11+
# CI backends to support
12+
ci = ["github"]
13+
# The installers to generate for each app
14+
installers = ["shell"]
15+
# Target platforms to build apps for (Rust target-triple syntax)
16+
targets = ["x86_64-unknown-linux-gnu"]
17+
# This setting determines which custom jobs to run during the "host" phase
18+
host-jobs = ["./changelog"]
19+
# Publish jobs to run in CI
20+
pr-run-mode = "plan"
21+
22+
# The profile that 'cargo dist' will build with
23+
[profile.dist]
24+
inherits = "release"
25+
lto = "thin"
526

627
[workspace]
728
members = ["crates/preview"]

Diff for: β€Žcliff.toml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# https://git-cliff.org/docs/configuration
2+
[changelog]
3+
header = ""
4+
# template for the changelog body
5+
# https://keats.github.io/tera/docs/#introduction
6+
body = """
7+
{% if version %}\
8+
## New Version [{{ version | trim_start_matches(pat="v") }}]
9+
{% else %}\
10+
## [UNRELEASED]
11+
{% endif %}\
12+
{% for group, commits in commits | group_by(attribute="group") %}
13+
### {{ group | striptags | trim | upper_first }}
14+
{% for commit in commits %}
15+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
16+
{% if commit.breaking %}[**breaking**] {% endif %}\
17+
{{ commit.message | upper_first }} ({% if commit.github.username %} by @{{ commit.github.username }}{%- endif %}\
18+
{% if commit.github.pr_number %} in #{{ commit.github.pr_number }}{%- endif %})
19+
{% endfor %}
20+
{% endfor %}\n
21+
"""
22+
footer = """
23+
{% for release in releases -%}
24+
{% if release.version %}\
25+
## [{{ release.version | trim_start_matches(pat="v") }}]
26+
{% else %}\
27+
## [UNRELEASED]
28+
{% endif %}\
29+
{% for group, commits in commits | group_by(attribute="group") %}
30+
### {{ group | striptags | trim | upper_first }}
31+
{% for commit in commits %}
32+
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
33+
{% if commit.breaking %}[**breaking**] {% endif %}\
34+
{{ commit.message | upper_first }} ({% if commit.github.username %} by @{{ commit.github.username }}{%- endif %}\
35+
{% if commit.github.pr_number %} in #{{ commit.github.pr_number }}{%- endif %})
36+
{% endfor %}
37+
{% endfor %}\n
38+
{% endfor %}
39+
"""
40+
trim = true
41+
42+
[git]
43+
# parse the commits based on https://www.conventionalcommits.org
44+
conventional_commits = true
45+
# filter out the commits that are not conventional
46+
filter_unconventional = true
47+
split_commits = false
48+
# sort the commits inside sections by oldest/newest order
49+
sort_commits = "newest"
50+
commit_parsers = [
51+
{ message = "^feat", group = "<!-- 0 -->πŸš€ Features" },
52+
{ message = "^fix", group = "<!-- 1 -->πŸ› Bug Fixes" },
53+
{ message = "^doc", group = "<!-- 3 -->πŸ“š Documentation" },
54+
{ message = "^perf", group = "<!-- 4 -->⚑ Performance" },
55+
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
56+
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
57+
{ message = "^test", group = "<!-- 6 -->πŸ§ͺ Testing" },
58+
{ message = "^chore\\(release\\): prepare for", skip = true },
59+
{ message = "^chore\\(deps.*\\)", skip = true },
60+
{ message = "^chore\\(pr\\)", skip = true },
61+
{ message = "^chore\\(pull\\)", skip = true },
62+
{ message = "^chore|^ci", group = "<!-- 7 -->βš™οΈ Miscellaneous Tasks" },
63+
{ body = ".*security", group = "<!-- 8 -->πŸ›‘οΈ Security" },
64+
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
65+
]

0 commit comments

Comments
Β (0)