Skip to content

Commit e09de16

Browse files
committed
ci: add release pipeline
1 parent 3bca29f commit e09de16

File tree

4 files changed

+332
-33
lines changed

4 files changed

+332
-33
lines changed

.github/workflows/release.yml

Lines changed: 305 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,322 @@
1-
name: Release Version
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.
213

14+
name: Release
315
permissions:
4-
contents: write
16+
"contents": "write"
517

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.
639
on:
7-
workflow_dispatch:
40+
pull_request:
841
push:
9-
paths-ignore:
10-
- "release.toml"
11-
- "LICENS**"
12-
- "README.md"
1342
tags:
14-
- "**"
43+
- '**[0-9]+.[0-9]+.[0-9]+*'
1544

1645
jobs:
17-
publish:
18-
id: changelog
19-
name: Publish Changelog
20-
runs-on: ubuntu-latest
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 }}
2156
steps:
2257
- uses: actions/checkout@v4
23-
- name: Generate a Changelog
24-
uses: orhun/git-cliff-action@v3
25-
id: git-cliff
2658
with:
27-
args: -vv --latest
28-
env:
29-
OUTPUT: CHANGES.md
30-
GITHUB_REPO: ${{ github.repository }}
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.21.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
3186

32-
- name: Release
33-
uses: softprops/action-gh-release@v2
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
34116
with:
35-
prerelease: ${{ contains(github.ref_name, 'a') }}
36-
body: ${{ steps.git-cliff.outputs.content }}
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 }}
37155
38-
release-extension:
39-
name: Release Zed Extension
40-
needs: [changelog]
41-
runs-on: ubuntu-latest
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
42165
steps:
43-
- uses: huacnlee/zed-extension-action@v1
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
44216
with:
45-
extension-name: zed-dotenv
46-
push-to: RustLangES/extensions
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
47256
env:
48-
# the personal access token should have "repo" & "workflow" scopes
49-
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
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: "RustLangES/homebrew-tap"
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

Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ authors = ["Sergio Ribera <[email protected]>"]
55
edition = "2021"
66
publish = false
77
license = "MIT OR Apache-2.0"
8+
repository = "https://github.com/RustLangES/zed-dotenv"
89

910
[lib]
1011
path = "src/dotenv-lsp.rs"
@@ -15,3 +16,27 @@ members = ["lsp"]
1516

1617
[dependencies]
1718
zed_extension_api = "0.1"
19+
20+
# The profile that 'cargo dist' will build with
21+
[profile.dist]
22+
inherits = "release"
23+
lto = "thin"
24+
25+
# Config for 'cargo dist'
26+
[workspace.metadata.dist]
27+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
28+
cargo-dist-version = "0.21.0"
29+
# CI backends to support
30+
ci = "github"
31+
# The installers to generate for each app
32+
installers = ["shell", "homebrew"]
33+
# A GitHub repo to push Homebrew formulas to
34+
tap = "RustLangES/homebrew-tap"
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", "x86_64-pc-windows-msvc"]
37+
# Path that installers should place binaries in
38+
install-path = "CARGO_HOME"
39+
# Publish jobs to run in CI
40+
publish-jobs = ["homebrew"]
41+
# Whether to install an updater program
42+
install-updater = false

lsp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "dotenv-lsp"
33
version = "0.1.0"
44
edition = "2021"
5+
repository = "https://github.com/RustLangES/zed-dotenv"
56

67
[dependencies]
78
dashmap = "6.1.0"

0 commit comments

Comments
 (0)