-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
360 lines (320 loc) · 13.1 KB
/
action.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
name: Create a binary artifact
description: |
Create a binary artifact for a cargo crate
author: "rustic-rs maintainers"
inputs:
toolchain:
description: |
The rust toolchain to use
required: true
target:
description: |
The target to build for
required: true
use-cross:
description: |
Use cross to build the binary
required: false
default: "false"
describe-tag-suffix:
description: |
Suffix for the git describe tag
required: false
default: ""
binary-postfix:
description: |
Postfix for the binary name
required: false
default: ""
os:
description: |
The operating system to build for
required: true
binary-name:
description: |
The name of the binary
required: true
package-secondary-name:
description: |
The secondary name for the package
required: true
github-token:
description: |
The github token to use
required: true
gpg-release-private-key:
description: |
The private key to use for signing the release
required: false
gpg-passphrase:
description: |
The passphrase to use for signing the release
required: false
architecture:
description: |
The architecture to build for
required: false
default: ""
sign-release:
description: |
Sign the release
required: true
default: "false"
hash-release:
description: |
Hash the release
required: true
default: "false"
github-ref:
description: |
The github ref in use
required: true
use-project-version:
description: |
Get the project version
required: false
default: "false"
use-release-profile:
description: |
Use the release profile to build the binary
required: false
default: "false"
rsign-release-private-key:
description: |
The rsign private key to use for signing the release
required: false
rsign-passphrase:
description: |
The rsign passphrase to use for signing the release
required: false
use-tag-version:
description: |
Use the tag as version in filename for a release
required: false
default: "false"
extra-cargo-build-args:
description: |
Extra arguments to pass to the cargo build command
required: false
default: ""
runs:
using: "composite"
steps:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1482605bfc5719782e1267fd0c0cc350fe7646b8 # v1
with:
toolchain: ${{ inputs.toolchain }}
targets: ${{ inputs.target }}
- name: install just command runner
uses: taiki-e/install-action@c6dc131d2c4291552cafb840290190a53b2cd937 # v2
with:
tool: just,toml-cli
- name: Check if default dependencies just recipe exists
shell: bash
id: check-recipe
run: |
if ! just -f ${GITHUB_WORKSPACE:?}/build-dependencies.just -s install-default-${{ inputs.target }}; then
echo "Failed to install default dependencies, recipe doesn't exist"
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Install default dependencies
shell: bash
if: steps.check-recipe.outputs.exists != 'false'
run: |
just -f ${GITHUB_WORKSPACE:?}/build-dependencies.just install-default-${{ inputs.target }}
# FIXME: Brew compilation doesn't work currently?
# - name: install compiler on macos
# shell: bash
# if: inputs.target == 'x86_64-apple-darwin' && inputs.use-cross == 'false'
# run: |
# brew install michaeleisel/zld/zld
# Doesn't work with cargo auditable build
# - name: install mold linker on linux gnu
# if: inputs.target == 'x86_64-unknown-linux-gnu' && inputs.use-cross == 'false'
# uses: rui314/setup-mold@v1
- name: install cargo-auditable for non-cross builds
if: inputs.use_cross != true
uses: taiki-e/install-action@c6dc131d2c4291552cafb840290190a53b2cd937 # v2
with:
tool: cargo-auditable,cargo-audit
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2
with:
key: ${{ inputs.target }}
- name: install rsign2 for signing binaries
uses: taiki-e/install-action@c6dc131d2c4291552cafb840290190a53b2cd937 # v2
if: inputs.sign-release == 'true'
with:
tool: rsign2
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2
with:
key: ${{ inputs.target }}
- name: Get additional features specified in platform-settings.toml
shell: bash
id: additional-features
run: |
# Exit gracefully if the platform-settings.toml doesn't have additional features
if ! toml get ${GITHUB_WORKSPACE:?}/platform-settings.toml platforms.${{ inputs.target }}.additional-features; then
echo "features=false" >> $GITHUB_OUTPUT
exit 0
else
features=$(toml get ${GITHUB_WORKSPACE:?}/platform-settings.toml platforms.${{ inputs.target }}.additional-features | jq -r 'join(" ")')
echo "features=$features" >> $GITHUB_OUTPUT
fi
- name: Install feature dependencies with just command runner
shell: bash
if: steps.additional-features.outputs.features != 'false'
run: |
target=${{ inputs.target }}
features=${{ steps.additional-features.outputs.features }}
for feature in $features; do
# check if recipe is existing
if ! just -f ${GITHUB_WORKSPACE:?}/build-dependencies.just -s install-$feature-$target; then
echo "Failed to install $feature dependencies, recipe doesn't exist"
echo "Please make sure, that the recipe exists in the build-dependencies.just file"
exit 1
fi
just -f ${GITHUB_WORKSPACE:?}/build-dependencies.just install-$feature-$target
done
- name: Set Version
if: inputs.use-project-version == 'true'
shell: bash
run: |
echo "PROJECT_VERSION=$(git describe --tags)${{ inputs.describe-tag-suffix }}" >> $GITHUB_ENV
- name: Use win config
shell: bash
if: inputs.target == 'x86_64-pc-windows-msvc'
run: |
cp -T ${GITHUB_ACTION_PATH:?}/.config/config-win.toml ${GITHUB_WORKSPACE:?}/.cargo/config.toml
- name: Use linux config
shell: bash
if: inputs.target == 'x86_64-unknown-linux-gnu' && inputs.use-cross == 'false'
run: |
cp -T ${GITHUB_ACTION_PATH:?}/.config/config-linux.toml ${GITHUB_WORKSPACE:?}/.cargo/config.toml
- name: Use darwin config
shell: bash
if: inputs.target == 'x86_64-apple-darwin' && inputs.use-cross == 'false'
run: |
cp ${GITHUB_ACTION_PATH:?}/.config/config-darwin.toml ${GITHUB_WORKSPACE:?}/.cargo/config.toml
- name: Get default features specified in platform-settings.toml
shell: bash
id: default-features
run: |
# Exit gracefully if the platform-settings.toml doesn't have default features
if ! toml get ${GITHUB_WORKSPACE:?}/platform-settings.toml platforms.defaults.release-features; then
echo "features=false" >> $GITHUB_OUTPUT
exit 0
else
features=$(toml get ${GITHUB_WORKSPACE:?}/platform-settings.toml platforms.defaults.release-features | jq -r 'join(" ")')
echo "features=$features" >> $GITHUB_OUTPUT
fi
- name: Collect features for cargo build
shell: bash
id: collect-features
run: |
if [[ ${{ steps.default-features.outputs.features }} != 'false' ]]; then
# join the features with a comma
echo "default_features=-F $(echo ${{ steps.default-features.outputs.features }} | tr ' ' ',')" >> $GITHUB_OUTPUT
else
echo "default_features=" >> $GITHUB_OUTPUT
fi
if [[ ${{ steps.additional-features.outputs.features }} != 'false' ]]; then
# join the features with a comma
echo "additional_features=-F $(echo ${{ steps.additional-features.outputs.features }} | tr ' ' ',')" >> $GITHUB_OUTPUT
else
echo "additional_features=" >> $GITHUB_OUTPUT
fi
- name: Cargo build
uses: clechasseur/rs-cargo@34eb9ee3e4186e5c7820a54393fbf081f78bc102 # v2 (attention: this should be double checked for security issues)
if: inputs.use-cross == 'true'
with:
command: build
use-cross: ${{ inputs.use-cross }}
toolchain: ${{ inputs.toolchain }}
args: --release --target ${{ inputs.target }} ${{ steps.collect-features.outputs.default_features }} ${{ steps.collect-features.outputs.additional_features }} ${{ inputs.extra-cargo-build-args }}
- name: Cargo auditable build
uses: clechasseur/rs-cargo@34eb9ee3e4186e5c7820a54393fbf081f78bc102 # v2 (attention: this should be double checked for security issues)
if: inputs.use-cross == 'false'
with:
command: auditable
use-cross: ${{ inputs.use-cross }}
toolchain: ${{ inputs.toolchain }}
args: build --release --target ${{ inputs.target }} ${{ steps.collect-features.outputs.default_features }} ${{ steps.collect-features.outputs.additional_features }} ${{ inputs.extra-cargo-build-args }}
- name: Determining Release name and working dir
shell: bash
id: package
run: |
if [[ ${{ inputs.use-tag-version }} == 'false' ]]; then
PACKAGE_NAME=${{ inputs.binary-name }}-${{ inputs.package-secondary-name }}.tar.gz
WORKING_DIR=${{ inputs.binary-name }}-${{ inputs.target }}
else
PACKAGE_NAME=${{ inputs.binary-name }}-${{ env.PROJECT_VERSION }}-${{ inputs.package-secondary-name }}.tar.gz
WORKING_DIR=${{ inputs.binary-name }}-${{ env.PROJECT_VERSION }}-${{ inputs.target }}
fi
echo "name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "dir=$WORKING_DIR" >> $GITHUB_OUTPUT
- name: Copy assets
shell: bash
run: |
WORKING_DIR=${{ steps.package.outputs.dir }}
mkdir -p $WORKING_DIR
# We need to account for the fact that the scheduler has two binaries
if [[ ${{ inputs.binary-name }} == 'rustic-scheduler' ]]; then
cp -a target/${{ inputs.target }}/release/${{ inputs.binary-name }}-server${{ inputs.binary-postfix }} $WORKING_DIR
cp -a target/${{ inputs.target }}/release/${{ inputs.binary-name }}-client${{ inputs.binary-postfix }} $WORKING_DIR
else
cp -a target/${{ inputs.target }}/release/${{ inputs.binary-name }}${{ inputs.binary-postfix }} $WORKING_DIR
fi
# Copy configuration files and documentation
# rustic, rustic-server, and rustic-scheduler all have config/* files
mkdir -p $WORKING_DIR/config
cp -a config/ $WORKING_DIR/
# Download and copy rustic user documentation
if [[ ${{ inputs.binary-name }} == 'rustic' ]]; then
mkdir -p $WORKING_DIR/docs
curl https://rustic.cli.rs/docs/rustic-user-docs.pdf -o $WORKING_DIR/docs/rustic-user-docs.pdf
fi
- name: Create package
shell: bash
run: |
RELEASE_NAME=${{ steps.package.outputs.name }}
# FIXME: This doesn't work with the current version of self-update
# See https://github.com/jaemk/self_update/issues/122
# tar czvf $RELEASE_NAME ${{ steps.package.outputs.dir }}/*
# FIXME: We actually need to implement the fix from above issue, when it's available
# Then after a few versions we should be able to remove the workaround below.
# Hacky workaround to only pack the binary and the config without the parent directory
cd ${{ steps.package.outputs.dir }} && tar czvf ../$RELEASE_NAME * && cd -
- name: Create SHA256
shell: bash
if: inputs.hash-release == 'true'
run: |
RELEASE_NAME=${{ steps.package.outputs.name }}
if [[ ${{ inputs.os }} == 'Windows' ]]; then
certutil -hashfile $RELEASE_NAME sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
else
shasum -a 256 $RELEASE_NAME > $RELEASE_NAME.sha256
fi
- name: Create GPG signature
shell: bash
if: inputs.sign-release == 'true'
run: |
RELEASE_NAME=${{ steps.package.outputs.name }}
echo "${{ inputs.gpg-release-private-key }}" > private.key
echo "${{ inputs.gpg-passphrase }}" | gpg --pinentry-mode=loopback \
--passphrase-fd 0 --import private.key
echo "${{ inputs.gpg-passphrase }}" | gpg --pinentry-mode=loopback \
--passphrase-fd 0 --local-user 12B7166D9FD59124416952E34018C5DE3BF8C081 \
--armor --output $RELEASE_NAME.asc --detach-sign $RELEASE_NAME
- name: Create Minisign/rsign2 signature
shell: bash
if: inputs.sign-release == 'true'
run: |
RELEASE_NAME=${{ steps.package.outputs.name }}
echo "${{ inputs.rsign-release-private-key }}" > private.key
### FIXME: Add password to key when input from stdin is available https://github.com/jedisct1/rsign2/issues/26
rsign sign -W -t "Signed by rustic Maintainers" -x $RELEASE_NAME.sig -s private.key $RELEASE_NAME
- name: Storing package as artefact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: binary-${{ inputs.target }}
path: ${{ steps.package.outputs.name }}*