-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
448 lines (411 loc) · 17.4 KB
/
Copy pathaction.yml
File metadata and controls
448 lines (411 loc) · 17.4 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
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
---
name: 'Compile open firmware solution'
description: |
Compile a selected firmware solution like coreboot, EDKII, OpenBMC and more
author: '9elements'
inputs:
version:
description: |
Version of firmware-action to use. If not specified, latest release will be used.
Must be a tag if 'compile' is false, must be a branch is 'compile' is true.
required: false
default: 'v0.19.6'
config:
description: |
Path to the JSON configuration file.
required: true
target:
description: |
The firmware recipe to build. Use ID from JSON configuration file.
required: true
recursive:
description: |
Build target recursively, with all of its dependencies.
required: false
default: 'false'
prune:
description: |
Remove Dagger container and its volumes after each module (only in recursive mode).
Enable this when building complex firmware stack in single job recursively and you are running out of disk space.
required: false
default: 'false'
debug:
description: |
Run the action with increased verbosity.
required: false
default: 'false'
compile:
description: |
Compile the action from source instead of downloading pre-compiled binary from releases.
required: false
default: 'false'
# Options for automatic caches and artifacts
enable-cache:
description: |
Automatically cache the '.firmware-action' directory along with all existing output directories.
Firmware-action can automatically cache the produced files, by iterating over all 'output_dir'
entries in the confirmation file. These files, if exists, can be cached.
Because firmware-action has multiple methods of detecting changes in the sources, it can then
rebuild the files if needed. But it there was no change, it can greatly speed up the CI run.
required: false
default: 'false'
auto-download-artifacts:
description: |
Automatically download all artifacts for the current workflow run.
There is no easy convenient way to download all required artifacts, so firmware-action offers the
option to just automatically download all available artifacts. This does not mean that they will
be used during the build, but it means that you do not need to handle the downloading of artifacts
yourself.
Internally a actions/download-artifact@v8 is used
required: false
default: 'false'
auto-upload-artifacts:
description: |
Automatically upload all artifacts.inputs.auto-upload-artifacts-if-no-files-found
Firmware action can automatically upload the artifacts for the current target (upload the 'output_dir'
directory), so that you don't have it. Combined with the option 'auto-download-artifacts'
firmware-action should be able to built entire firmware stack in CI even if it is split into multiple
jobs and even if there are multiple matrix builds running in parallel.
Internally a actions/upload-artifact@v7 is used
required: false
default: 'false'
# Options passed over to artifact uploading
auto-upload-artifacts-if-no-files-found:
description: |
See 'if-no-files-found' at https://github.com/actions/upload-artifact
default: 'warn'
auto-upload-artifacts-retention-days:
description: |
See 'retention-days' at https://github.com/actions/upload-artifact
default: '0'
auto-upload-artifacts-compression-level:
description: |
See 'compression-level' at https://github.com/actions/upload-artifact
default: '6'
auto-upload-artifacts-overwrite:
description: |
See 'overwrite' at https://github.com/actions/upload-artifact
default: 'false'
# As for the only omitted input 'include-hidden-files', we do need this enabled
# because we are uploading the `./firmware-action` directory
# which would not get uploaded at all with this option set to 'false'
# We might change the behavior in the future if anyone needs it
# (maybe just renaming the directory before upload)
outputs:
artifact-name:
description: |
Name of the artifact which will be uploaded to GitHub
value: ${{ steps.get_artifact_name.outputs.artifact_name }}
# These outputs are just passing on outputs of 'upload-artifact'
# Docs: https://github.com/actions/upload-artifact
artifact-id:
description: |
GitHub ID of an Artifact, can be used by the REST API
value: ${{ steps.upload_artifact.outputs.artifact-id }}
artifact-url:
description: |
URL to download an Artifact.
Can be used in many scenarios such as linking to artifacts in issues or pull requests.
Users must be logged-in in order for this URL to work.
This URL is valid as long as the artifact has not expired or the artifact, run or repository have not been deleted.
value: ${{ steps.upload_artifact.outputs.artifact-url }}
artifact-digest:
description: |
SHA-256 digest of an Artifact
value: ${{ steps.upload_artifact.outputs.artifact-digest }}
runs:
using: 'composite'
steps:
- id: arch
# This ARCH is used to fetch correct executable of firmware-action
# GoReleaser uses 'x86_64' instead of 'amd64'
shell: bash
run: |
if [ ${{ runner.arch }} = "X64" ]; then
echo "arch=x86_64" >> "${GITHUB_OUTPUT}"
elif [ ${{ runner.arch }} = "amd64" ]; then
echo "arch=x86_64" >> "${GITHUB_OUTPUT}"
elif [ ${{ runner.arch }} = "X86" ]; then
echo "arch=i386" >> "${GITHUB_OUTPUT}"
elif [ ${{ runner.arch }} = "ARM64" ]; then
echo "arch=arm64" >> "${GITHUB_OUTPUT}"
else
echo "arch=${{ runner.arch }}" >> "${GITHUB_OUTPUT}"
fi
- id: os
shell: bash
run: |
if [ ${{ runner.os }} = "macOS" ]; then
echo "os=Darwin" >> "${GITHUB_OUTPUT}"
else
echo "os=${{ runner.os }}" >> "${GITHUB_OUTPUT}"
fi
# Because MacOS is named Darwin in golang releaser
- id: ext
shell: bash
run: |
if [ ${{ runner.os }} = "Windows" ]; then
echo "ext=zip" >> "${GITHUB_OUTPUT}"
else
echo "ext=tar.gz" >> "${GITHUB_OUTPUT}"
fi
# Both Linux and MacOS use 'tar.gz'
- id: filename
shell: bash
run: |
echo "filename=firmware-action_${{ steps.os.outputs.os }}_${{ steps.arch.outputs.arch }}.${{ steps.ext.outputs.ext }}" >> "${GITHUB_OUTPUT}"
- id: url
shell: bash
run: |
echo "url=https://github.com/9elements/firmware-action/releases/download/${{ inputs.version }}/${{ steps.filename.outputs.filename }}" >> "${GITHUB_OUTPUT}"
- name: setup_go
if: ${{ inputs.compile == 'true' }}
uses: actions/setup-go@v7
with:
go-version: stable
#==============================================
# Acquire firmware-action executable for Linux
#==============================================
# Download from release
- id: fetch_unix
if: ${{ ( runner.os == 'Linux' || runner.os == 'macOS' ) && inputs.compile == 'false' }}
shell: bash
run: |
echo "::group::curl firmware-action"
curl -L -o "${{ steps.filename.outputs.filename }}" "${{ steps.url.outputs.url }}"
tar -xvzf "${{ steps.filename.outputs.filename }}"
chmod +x firmware-action
echo "::endgroup::"
# chmod should not be necessary, but just to be safe
# Compile
- name: check_directory
if: ${{ inputs.compile == 'true' }}
shell: bash
id: check_dir
run: |
if [ -d "./cmd/firmware-action" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
# Compile / git clone
# this use-case is when users use firmware-action and want to use compilation to get
# early access to some new features on some experimental branch
- name: git_clone_for_compilation
if: ${{ inputs.compile == 'true' && steps.check_dir.outputs.exists == 'false' }}
shell: bash
run: |
echo "::group::git clone firmware-action"
git clone -n --depth=1 --filter=tree:0 --branch "${{ inputs.version }}" https://github.com/9elements/firmware-action.git ./firmware-action-compile
echo "::endgroup::"
- name: sparse_checkout
if: ${{ inputs.compile == 'true' && steps.check_dir.outputs.exists == 'false' }}
shell: bash
working-directory: ./firmware-action-compile
run: |
echo "::group::sparse checkout"
git sparse-checkout set --no-cone /cmd
git checkout
echo "::endgroup::"
# Compile / symlink
# this use-case is for firmware-action examples (the source-code is already in the working directory)
- name: create_symlink
if: ${{ inputs.compile == 'true' && steps.check_dir.outputs.exists == 'true' }}
shell: bash
run: |
echo "::group::create symlink"
mkdir -p ./firmware-action-compile/cmd
ln -s ../../cmd/firmware-action ./firmware-action-compile/cmd/
echo "::endgroup::"
# Compile / go build
- name: compile_unix
if: ${{ ( runner.os == 'Linux' || runner.os == 'macOS' ) && inputs.compile == 'true' }}
shell: bash
working-directory: ./firmware-action-compile/cmd/firmware-action
run: |
echo "::group::compile firmware-action"
go build -ldflags="-s -w" -o ../../../firmware-action
echo "::endgroup::"
#================================================
# Acquire firmware-action executable for Windows
#================================================
- id: fetch_windows
if: ${{ runner.os == 'Windows' && inputs.compile == 'false' }}
shell: pwsh
run: |
echo ##[group]fetch
Invoke-WebRequest -Uri "${{ steps.url.outputs.url }}" -OutFile "${{ steps.filename.outputs.filename }}"
Expand-Archive -Path "${{ steps.filename.outputs.filename }}" -DestinationPath .\
echo ##[endgroup]
# - name: git_clone_for_compilation
# TODO
- name: compile_windows
if: ${{ runner.os == 'Windows' && inputs.compile == 'true' }}
shell: pwsh
working-directory: ./cmd/firmware-action
run: |
echo ##[group]compile firmware-action
go build -ldflags="-s -w" -o ../../../firmware-action.exe
echo ##[endgroup]
#================
# CACHE: Restore
#================
#
# GitHub does not allow to run a single step in some sort of for-loop, nor does allow to call another
# reusable action to potentially use matrix strategy to achieve this.
# I also looked into GitHub CI commands (link to docs below), but there is no support for uploading
# cache or artifacts
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions
# The only way that I could come up with is to pack it (move all the files into single directory) and then upload.
# And upon download it is unpacked.
# One way might be to implement GitHub API interface right into the golang code, but that seems like too much
# overkill for what we want.
- name: restore_cache
uses: actions/cache/restore@v6
if: inputs.enable-cache == 'true'
id: cache
with:
path: .firmware-action/
key: firmware-action-${{ inputs.target }}-${{ hashFiles(inputs.config) }}-${{ github.sha }}-${{ github.run_id }}
restore-keys: |
firmware-action-${{ inputs.target }}-${{ hashFiles(inputs.config) }}-${{ github.sha }}-
firmware-action-${{ inputs.target }}-${{ hashFiles(inputs.config) }}-
firmware-action-${{ inputs.target }}-
- name: merge_config_files
shell: bash
id: merge_config
run: |
# Create temporary directory for merged config
TEMP_DIR=$(mktemp -d)
MERGED_CONFIG="${TEMP_DIR}/merged.json"
echo "merged_config=${MERGED_CONFIG}" >> "${GITHUB_OUTPUT}"
# Initialize empty JSON object
echo '{}' > "${MERGED_CONFIG}"
# Split config input into individual files
readarray -t CONFIG_FILES <<< "${{ inputs.config }}"
# Process and merge each config file
for CONFIG_FILE in "${CONFIG_FILES[@]}"; do
# Trim whitespace
CONFIG_FILE=$(echo "${CONFIG_FILE}" | xargs)
# Skip empty lines
[ -z "${CONFIG_FILE}" ] && continue
# Merge this config with accumulated config
jq -s '.[0] * .[1]' "${MERGED_CONFIG}" "${CONFIG_FILE}" > "${TEMP_DIR}/temp.json"
mv "${TEMP_DIR}/temp.json" "${MERGED_CONFIG}"
done
#=====================
# ARTIFACTS: Download
#=====================
#
# Download all artifacts for the current workflow run.
# Docs: https://github.com/actions/download-artifact?tab=readme-ov-file#download-all-artifacts
- name: download_artifacts
uses: actions/download-artifact@v8
if: inputs.auto-download-artifacts == 'true'
with:
path: .firmware-action2/
merge-multiple: true
- name: merge_firmware_action_directory
if: inputs.auto-download-artifacts == 'true'
shell: bash
run: |
echo "::group::merge"
mkdir -p .firmware-action/
# Check if firmware-action2 directory exists and has content
if [ -d ".firmware-action2/" ] && [ "$(ls -A .firmware-action2/ 2>/dev/null)" ]; then
# Copy all content from firmware-action2 to firmware-action, overwriting existing files
cp -rf .firmware-action2/. .firmware-action/
echo "Merged downloaded artifacts into .firmware-action directory"
rm -rf .firmware-action2/
else
echo "No downloaded artifacts found in .firmware-action2/"
fi
echo "::endgroup::"
- name: unpack_cached_files
shell: bash
if: ${{ steps.cache.outputs.cache-hit == 'true' || inputs.enable-cache == 'true' }}
run: |
if [ -d ".firmware-action/artifacts" ] && [ -n "$(ls -A .firmware-action/artifacts/ 2>/dev/null)" ]; then
echo "::group::Unpacking cached artifacts"
# Process each artifact directory
for ARTIFACT in .firmware-action/artifacts/*; do
# Skip if not a directory
if [ ! -d "${ARTIFACT}" ]; then
continue
fi
# Get the base name of the artifact directory
ARTIFACT_NAME=$(basename "${ARTIFACT}")
# Check if there's a corresponding text file with the original path
PATH_FILE=".firmware-action/artifacts/${ARTIFACT_NAME}.txt"
if [ -f "${PATH_FILE}" ]; then
# Read the original output_dir path from the file
ORIGINAL_PATH=$(cat "${PATH_FILE}")
echo "Restoring artifact '${ARTIFACT_NAME}' to original path: ${ORIGINAL_PATH}"
# Create parent directories if they don't exist
mkdir -p "$(dirname "${ORIGINAL_PATH}")"
# Move the artifact to its original location
mv "${ARTIFACT}" "${ORIGINAL_PATH}"
else
# Fallback to old behavior if no path file exists
echo "No path information found for '${ARTIFACT_NAME}', moving to root directory"
mv "${ARTIFACT}" ./
fi
done
echo "::endgroup::"
fi
#=================================
# RUN: firmware-action executable
#=================================
- name: run_unix
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
shell: bash
run: |
./firmware-action
env:
INPUT_CONFIG: ${{ inputs.config }}
INPUT_TARGET: ${{ inputs.target }}
INPUT_RECURSIVE: ${{ inputs.recursive }}
INPUT_PRUNE: ${{ inputs.prune }}
INPUT_DEBUG: ${{ inputs.debug == 'true' || env.RUNNER_DEBUG == '1' }}
- name: run_windows
if: ${{ runner.os == 'Windows' }}
shell: pwsh
run: |
.\firmware-action.exe
env:
INPUT_CONFIG: ${{ inputs.config }}
INPUT_TARGET: ${{ inputs.target }}
INPUT_RECURSIVE: ${{ inputs.recursive }}
INPUT_PRUNE: ${{ inputs.prune }}
INPUT_DEBUG: ${{ inputs.debug == 'true' || env.RUNNER_DEBUG == '1' }}
#===============
# CACHE: Create
#===============
- name: save_cache
if: ${{ always() && inputs.enable-cache == 'true' }}
uses: actions/cache/save@v6
with:
path: .firmware-action/
key: firmware-action-${{ inputs.target }}-${{ hashFiles(inputs.config) }}-${{ github.sha }}-${{ github.run_id }}
#===================
# ARTIFACTS: Upload
#===================
- name: get_artifact_name
if: ${{ always() && inputs.auto-upload-artifacts == 'true' }}
shell: bash
id: get_artifact_name
run: |
DATETIME=$(date "+%Y-%m-%d_%H-%M-%S.%N")
echo "artifact_name=artifacts--${{ inputs.target }}--${DATETIME}" >> "${GITHUB_OUTPUT}"
- name: upload_artifact
if: ${{ always() && inputs.auto-upload-artifacts == 'true' }}
uses: actions/upload-artifact@v7
id: upload_artifact
with:
name: ${{ steps.get_artifact_name.outputs.artifact_name }}
path: .firmware-action/
include-hidden-files: true
if-no-files-found: ${{ inputs.auto-upload-artifacts-if-no-files-found }}
retention-days: ${{ inputs.auto-upload-artifacts-retention-days }}
compression-level: ${{ inputs.auto-upload-artifacts-compression-level }}
overwrite: ${{ inputs.auto-upload-artifacts-overwrite }}