-
Notifications
You must be signed in to change notification settings - Fork 25
374 lines (332 loc) · 12.1 KB
/
builds.yml
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
name: ⚃ Builds
# TODO: brew formula (Macs), cargo-wix (Windows Installs), cargo-aur (Arch)
on:
workflow_dispatch:
inputs:
force-builds:
required: true
type: boolean
description: Publish Builds at Anytime
release:
types: [published]
# for debugging
# pull_request:
# branches: ["**"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
binary-builds:
if: >
startsWith(github.event.release.name, 'homestar-runtime') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.force-builds)
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-unknown-linux-gnu
- target: aarch64-unknown-linux-musl
npm: linux-arm64
- target: aarch64-apple-darwin
os: macos-latest
npm: darwin-arm64
- target: x86_64-unknown-linux-gnu
- target: x86_64-unknown-linux-musl
npm: linux-x64
- target: x86_64-apple-darwin
os: macos-latest
npm: darwin-x64
- target: x86_64-pc-windows-msvc
os: windows-latest
npm: windows-x64
- target: x86_64-unknown-freebsd
permissions:
contents: write
timeout-minutes: 60
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install musl-tools
run: sudo apt update && sudo apt install -y musl-dev musl-tools
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl'
- name: Install Rust Toolchain
id: toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache Project
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
shared-key: check-${{ matrix.target }}-${{ matrix.os }}
- name: cross-build
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- name: crt-static
run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >>"${GITHUB_ENV}"
if: endsWith(matrix.target, 'windows-msvc')
- name: Compile
run: cargo build -p homestar-runtime --locked --release --target ${{ matrix.target }}
- name: Upload Release Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: target/${{ matrix.target }}/release/homestar*
if-no-files-found: error
- name: Publish Binary in Release
if: github.event_name == 'release' && github.event.action == 'published'
uses: taiki-e/upload-rust-binary-action@v1
with:
bin: homestar
target: ${{ matrix.target }}
tar: all
zip: windows
include: LICENSE,README.md
token: ${{ secrets.GITHUB_TOKEN }}
npm-publish-arch:
needs: binary-builds
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-unknown-linux-musl
os: linux
arch: arm64
bin: homestar
- target: x86_64-unknown-linux-musl
os: linux
arch: x64
bin: homestar
- target: aarch64-apple-darwin
os: darwin
arch: arm64
bin: homestar
- target: x86_64-apple-darwin
os: darwin
arch: x64
bin: homestar
- target: x86_64-pc-windows-msvc
os: windows
arch: x64
bin: homestar.exe
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: "https://registry.npmjs.org"
- name: Install cargo-get
run: cargo install cargo-get
- name: Prepare os/arch packages
shell: bash
env:
node_os: ${{ matrix.os }}
node_arch: ${{ matrix.arch }}
node_pkg: homestar-${{ matrix.os }}-${{ matrix.arch }}
run: |
export node_version=$(cargo get workspace.package.version)
echo "node_pkg=${node_pkg}" >> "$GITHUB_ENV"
cd homestar-runtime/npm
mkdir -p "${node_pkg}/bin"
envsubst < package-json-arch.tmpl > "${node_pkg}/package.json"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: ${{ matrix.target }}
path: "homestar-runtime/npm/${{ env.node_pkg }}/bin"
- name: Publish arch packages to production
if: github.event_name == 'release' && github.event.action == 'published'
run: |
cp homestar-runtime/README.md "homestar-runtime/npm/${{ env.node_pkg }}"
cd "homestar-runtime/npm/${{ env.node_pkg }}"
chmod +x bin/${{ matrix.bin }}
npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Publish arch packages RC
if: github.event_name == 'workflow_dispatch'
run: |
cp homestar-runtime/README.md "homestar-runtime/npm/${{ env.node_pkg }}"
cd "homestar-runtime/npm/${{ env.node_pkg }}"
chmod +x bin/${{ matrix.bin }}
npm version $(cargo get package.version)-rc.$(date +%s) --git-tag-version false
npm publish --access public --tag rc
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
npm-publish-main:
needs: npm-publish-arch
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: "https://registry.npmjs.org"
- name: Install cargo get
run: cargo install cargo-get
- name: Publish main package to production
if: github.event_name == 'release' && github.event.action == 'published'
run: |
export node_version=$(cargo get workspace.package.version)
cp homestar-runtime/README.md homestar-runtime/npm/base
cd homestar-runtime/npm
envsubst < package-json-base.tmpl > "base/package.json"
cd base
npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Publish main package RC
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.force-builds)
run: |
export node_version="$(cargo get workspace.package.version)-rc.$(date +%s)"
cp homestar-runtime/README.md homestar-runtime/npm/base
cd homestar-runtime/npm
envsubst < package-json-baserc.tmpl > "base/package.json"
cd base
npm publish --access public --tag rc
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
build-packages:
needs: binary-builds
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
- target: x86_64-unknown-linux-musl
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install musl-tools
run: sudo apt update && sudo apt install -y musl-dev musl-tools
if: matrix.target == 'x86_64-unknown-linux-musl'
- name: Install Rust toolchain
id: toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Override rust-toolchain.toml
run: rustup override set ${{steps.toolchain.outputs.name}}
- name: Install cargo-deb
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cargo-deb
- name: Install cargo-generate-rpm
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cargo-generate-rpm
- name: Cache Project
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
shared-key: check-${{ matrix.target }}-ubuntu-latest
- name: Create .deb
run: cargo deb -p homestar-runtime --target ${{ matrix.target }} --variant ${{ matrix.target }} --output homestar-${{ matrix.target }}.deb
- name: Create .rpm
run: cargo generate-rpm -p homestar-runtime --target ${{ matrix.target }} --variant ${{ matrix.target }} --output homestar-${{ matrix.target }}.rpm
- name: Upload Release Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}-packages
path: |
*.deb
*.rpm
if-no-files-found: error
- name: Publish Package in Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'release' && github.event.action == 'published'
with:
files: |
*.deb
*.rpm
docker-build:
if: >
startsWith(github.event.release.name, 'homestar-runtime') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.force-builds)
runs-on: ubuntu-latest
env:
DOCKER_BUILDKIT: "1"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
id-token: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cleanup
run: |
# Workaround to provide additional free space for testing.
# https://github.com/actions/virtual-environments/issues/2840
rm -rf /opt/hostedtoolcache
rm -rf /usr/share/dotnet
rm -rf /opt/ghc
rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get clean
sudo rm -rf /usr/share/dotnet
- name: Install cargo-get
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.force-builds)
run: cargo install cargo-get
- name: Set Current Version
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.force-builds)
id: crate-version
run: echo version=$(cargo get workspace.package.version)-rc.$(date +%s) >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Metadata
if: github.event_name != 'workflow_dispatch'
id: meta-release
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest
type=sha
- name: Metadata
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.force-builds)
id: meta-dispatch
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=${{ steps.crate-version.outputs.version }}
type=raw,value=latest
type=sha
- name: Docker Build & Push
if: github.event_name != 'workflow_dispatch'
uses: docker/build-push-action@v5
with:
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-to: type=inline
file: docker/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-release.outputs.tags }}
labels: ${{ steps.meta-release.outputs.labels }}
- name: Docker Build & Push
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.force-builds)
uses: docker/build-push-action@v5
with:
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-to: type=inline
file: docker/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-dispatch.outputs.tags }}
labels: ${{ steps.meta-dispatch.outputs.labels }}