Skip to content

Commit 67f76b3

Browse files
committed
feat(action): automatically upload artifacts
- just like we automatically cache, we can now automatically upload artifacts Signed-off-by: AtomicFS <vojtech.vesely@9elements.com>
1 parent 9a776a5 commit 67f76b3

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

.github/workflows/example.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ jobs:
154154
compile: ${{ needs.changes.outputs.compile }}
155155
env:
156156
UROOT_VERSION: ${{ matrix.uroot-version }}
157-
158-
- name: Get artifacts
159-
uses: actions/upload-artifact@v4
160-
with:
161-
name: uroot-${{ matrix.uroot-version }}-${{ matrix.arch }}
162-
path: output-uroot
163-
retention-days: 14
164157
# ANCHOR_END: example_build_uroot
165158

166159
# Example of building u-boot
@@ -221,13 +214,6 @@ jobs:
221214
compile: ${{ needs.changes.outputs.compile }}
222215
env:
223216
UBOOT_VERSION: ${{ matrix.uboot-version }}
224-
225-
- name: Get artifacts
226-
uses: actions/upload-artifact@v4
227-
with:
228-
name: uboot-${{ matrix.uboot-version }}-${{ matrix.arch }}
229-
path: output-uboot
230-
retention-days: 14
231217
# ANCHOR_END: example_build_uboot
232218

233219
# Example of running on non-Linux systems

action.yml

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,35 @@ runs:
125125
uses: actions/cache/restore@v4
126126
with:
127127
path: .firmware-action/
128-
key: firmware-action-${{ hashFiles(inputs.config) }}-${{ github.sha }}
128+
key: firmware-action-${{ hashFiles(inputs.config) }}-${{ github.sha }}-${{ github.run_id }}
129129
restore-keys: |
130+
firmware-action-${{ hashFiles(inputs.config) }}-${{ github.sha }}-
130131
firmware-action-${{ hashFiles(inputs.config) }}-
131132
firmware-action-
132133
133134
- name: unpack_cached_files
134135
shell: bash
135136
run: |
137+
# Get output directories from config
136138
mapfile -t OUTPUT_DIRS < <(jq -r '[.. | objects | ."output_dir"? | select(. != null)][]' tests/example_config.json)
139+
140+
# For each output directory
137141
for DIR in "${OUTPUT_DIRS[@]}"; do
138-
if [ -d ".firmware-action/${DIR}" ]; then
139-
mv ".firmware-action/${DIR}" ./
142+
if [ -d ".firmware-action/artifacts/${DIR}" ]; then
143+
mv ".firmware-action/artifacts/${DIR}" ./
140144
fi
141145
done
142146
147+
#=====================
148+
# ARTIFACTS: Download
149+
#=====================
150+
151+
#- name: download_artifacts
152+
# uses: actions/download-artifact@v4
153+
# with:
154+
# name: artifacts-${{ inputs.target }}
155+
# path: .firmware-action2/
156+
143157
#=================================
144158
# RUN: firmware-action executable
145159
#=================================
@@ -168,14 +182,19 @@ runs:
168182
# CACHE: Create
169183
#===============
170184

171-
- name: pack_files_for_cache
185+
- name: copy_artifacts
172186
if: always()
173187
shell: bash
174188
run: |
175-
mapfile -t OUTPUT_DIRS < <(jq -r '[.. | objects | ."output_dir"? | select(. != null)][]' tests/example_config.json)
189+
mkdir -p .firmware-action/artifacts/
190+
191+
# Get output directories from config
192+
mapfile -t OUTPUT_DIRS < <(jq -r '[.. | objects | ."output_dir"? | select(. != null)][]' "${{ inputs.config }}")
193+
194+
# For each output directory
176195
for DIR in "${OUTPUT_DIRS[@]}"; do
177196
if [ -d "${DIR}" ]; then
178-
cp -r "${DIR}" .firmware-action/
197+
cp -r "${DIR}" .firmware-action/artifacts/
179198
fi
180199
done
181200
@@ -184,4 +203,26 @@ runs:
184203
uses: actions/cache/save@v4
185204
with:
186205
path: .firmware-action/
187-
key: firmware-action-${{ hashFiles(inputs.config) }}-${{ github.sha }}
206+
key: firmware-action-${{ hashFiles(inputs.config) }}-${{ github.sha }}-${{ github.run_id }}
207+
208+
#===================
209+
# ARTIFACTS: Upload
210+
#===================
211+
212+
- name: get_output_dir
213+
if: always()
214+
shell: bash
215+
id: get_output_dir
216+
run: |
217+
# Extract output_dir for the specific target from config
218+
OUTPUT_DIR=$(jq -r --arg TARGET "${{ inputs.target }}" 'to_entries[] | select(.value | to_entries[].key == $TARGET) | .value[$TARGET].output_dir' "${{ inputs.config }}" | sed -E 's/\/$//g')
219+
echo "output_dir=${OUTPUT_DIR}" >> "${GITHUB_OUTPUT}"
220+
221+
- name: upload_artifacts
222+
if: always()
223+
uses: actions/upload-artifact@v4
224+
with:
225+
name: artifacts--${{ inputs.target }}--${{ steps.get_output_dir.outputs.output_dir }}
226+
path: .firmware-action/
227+
include-hidden-files: true
228+
overwrite: true

0 commit comments

Comments
 (0)