-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (184 loc) · 6.58 KB
/
Copy pathrelease.yml
File metadata and controls
213 lines (184 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Release
on:
push:
tags:
- "v*.*.*"
# Least privilege by default; jobs that push the version bump or touch the
# GitHub release escalate to contents: write at the job level.
permissions:
contents: read
# Never cancel a release mid-flight (a cancelled publish can leave a half-done
# release); serialise per-ref instead.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
prepare-release:
name: Bump version from tag
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
# The release version (tag minus its leading "v") and the SHA of the bump
# commit. Every downstream job checks out `sha` so it builds/publishes the
# bumped tree exactly, regardless of where main moves afterwards.
version: ${{ steps.bump.outputs.version }}
sha: ${{ steps.bump.outputs.sha }}
steps:
- uses: actions/checkout@v7
with:
ref: main
- name: Write tag version into manifests and push to main
id: bump
run: |
version="${GITHUB_REF_NAME#v}"
# The tag is the single source of truth: stamp it into both manifests.
# Cargo.toml's [package] version is the only line starting with
# `version = `; mix.exs has exactly one `version: "..."` (the project
# version). `0,/re/` rewrites just the first match.
sed -i -E "0,/^version = \"[^\"]*\"/s//version = \"${version}\"/" native/suidhelper/Cargo.toml
sed -i -E "0,/version: \"[^\"]*\"/s//version: \"${version}\"/" mix.exs
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add native/suidhelper/Cargo.toml mix.exs
# Idempotent: a re-run after the bump already landed has nothing to commit.
if git diff --cached --quiet; then
echo "manifests already at ${version}; nothing to commit"
else
git commit -m "release: v${version}"
git push origin HEAD:main
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
build-suidhelper:
name: Build suidhelper (${{ matrix.target }})
needs: prepare-release
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
target:
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl
defaults:
run:
working-directory: native/suidhelper
steps:
- uses: actions/checkout@v7
with:
ref: ${{ needs.prepare-release.outputs.sha }}
# rustup reads native/suidhelper/rust-toolchain.toml on the first cargo
# call and installs the pinned nightly + both musl targets.
- name: Show toolchain
run: rustup show
- uses: Swatinem/rust-cache@v2
with:
workspaces: native/suidhelper
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Stage renamed artifact
run: |
v="${{ needs.prepare-release.outputs.version }}"
out="hyper-suidhelper-${v}-${{ matrix.target }}"
mkdir -p dist
cp "target/${{ matrix.target }}/release/hyper-suidhelper" "dist/${out}"
- uses: actions/upload-artifact@v7
with:
name: suidhelper-${{ matrix.target }}
path: native/suidhelper/dist/*
if-no-files-found: error
build-hex:
name: Build Hex package
needs: prepare-release
runs-on: ubuntu-latest
env:
MIX_ENV: dev
steps:
- uses: actions/checkout@v7
with:
ref: ${{ needs.prepare-release.outputs.sha }}
- uses: erlef/setup-beam@v1
id: beam
with:
elixir-version: "1.20"
otp-version: "28"
- name: Cache deps and _build
uses: actions/cache@v6
with:
path: |
deps
_build
key: ${{ runner.os }}-release-mix-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-release-mix-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-
- name: Install dependencies
run: mix deps.get
- name: Build package tarball
run: mix hex.build --output "hypervm-${{ needs.prepare-release.outputs.version }}.tar"
- uses: actions/upload-artifact@v7
with:
name: hex-package
path: hypervm-*.tar
if-no-files-found: error
github-release:
name: Draft GitHub release
needs: [build-suidhelper, build-hex]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all build artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
- name: Collect assets and compute checksums
run: |
mkdir -p release
find artifacts -type f \( -name 'hyper-suidhelper-*' -o -name 'hypervm-*.tar' \) \
-exec cp {} release/ \;
( cd release && sha256sum hyper-suidhelper-* hypervm-*.tar > SHA256SUMS )
ls -la release
- name: Create draft release
uses: softprops/action-gh-release@v3
with:
draft: true
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
generate_release_notes: true
files: release/*
publish-hex:
name: Publish to Hex
needs: [prepare-release, build-hex, github-release]
runs-on: ubuntu-latest
environment: release
env:
MIX_ENV: dev
steps:
- uses: actions/checkout@v7
with:
ref: ${{ needs.prepare-release.outputs.sha }}
- uses: erlef/setup-beam@v1
with:
elixir-version: "1.20"
otp-version: "28"
- name: Install dependencies
run: mix deps.get
# HEX_API_KEY authenticates non-interactively; --yes skips the prompt.
# Publishes both the package and its docs.
- name: hex publish
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
run: mix hex.publish --yes
finalize-release:
name: Publish GitHub release
needs: [publish-hex]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Flip the draft (created earlier) to live only after both registries
# have the new version. github.token has the contents:write granted above.
- name: Mark release as published
env:
GH_TOKEN: ${{ github.token }}
run: gh release edit "${{ github.ref_name }}" --draft=false