Skip to content

Commit 53d3f5d

Browse files
committed
Use docker export for artifact extraction and upload build log
1 parent a8f591b commit 53d3f5d

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

.github/actions/docker-build-artifacts/action.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ inputs:
1515
description: Package maintainer
1616
WORKING_DIRECTORY:
1717
required: true
18-
default: '.'
18+
default: "."
1919
description: Working directory
2020
ARTIFACTS_PATTERN:
2121
required: false
2222
default: '.*\.(deb|rpm)$'
2323
description: Regexp that matches artifacts
2424
ARTIFACTS_DIR:
2525
required: false
26-
default: 'BUILD'
26+
default: "BUILD"
2727
description: Output directory for artifacts
2828
BUILD_LOG_FILENAME:
2929
required: false
30-
default: 'build.log'
30+
default: "build.log"
3131
description: Build log filename
3232

3333
runs:
@@ -74,28 +74,30 @@ runs:
7474
--pull \
7575
. 2>&1 | tee -a ${{ inputs.BUILD_LOG_FILENAME }}
7676
77+
- name: Upload build log
78+
if: always()
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: build-log-${{ github.run_id }}-${{ github.sha }}
82+
path: ${{ inputs.WORKING_DIRECTORY }}/${{ inputs.BUILD_LOG_FILENAME }}
83+
retention-days: 7
84+
if-no-files-found: ignore
85+
7786
- name: Extract artifacts from image
7887
shell: bash
7988
working-directory: ${{ inputs.WORKING_DIRECTORY }}
8089
run: |
8190
set -euo pipefail
8291
83-
export TEMP_DIR=$(mktemp -d)
84-
85-
# dump Docker image blobs
86-
docker save artifacts-${GITHUB_RUN_ID}:${GITHUB_SHA} --output "${TEMP_DIR}/artifacts-${GITHUB_RUN_ID}-${GITHUB_SHA}.tar" && \
87-
tar -xf "${TEMP_DIR}/artifacts-${GITHUB_RUN_ID}-${GITHUB_SHA}.tar" -C "${TEMP_DIR}" && \
88-
rm -f "${TEMP_DIR}/artifacts-${GITHUB_RUN_ID}-${GITHUB_SHA}.tar"
89-
90-
# extract blobs content
91-
mkdir -p "${{ inputs.ARTIFACTS_DIR }}" && find "${TEMP_DIR}/" -type f -exec file {} + \
92-
| grep -E ":.*tar archive" \
93-
| cut -d: -f1 \
94-
| xargs -rI{} tar --keep-newer-files -xf {} -C "${{ inputs.ARTIFACTS_DIR }}"
92+
# create container from image and export filesystem
93+
container_id=$(docker create artifacts-${GITHUB_RUN_ID}:${GITHUB_SHA} sh)
94+
mkdir -p "${{ inputs.ARTIFACTS_DIR }}"
95+
docker export "$container_id" | tar -xf - -C "${{ inputs.ARTIFACTS_DIR }}"
96+
find "${{ inputs.ARTIFACTS_DIR }}" -type d -empty -delete
9597
9698
# cleanup
97-
docker image rm artifacts-${GITHUB_RUN_ID}:${GITHUB_SHA} && \
98-
rm -rf "${TEMP_DIR}"
99+
docker rm "$container_id"
100+
docker image rm artifacts-${GITHUB_RUN_ID}:${GITHUB_SHA}
99101
100102
if [ "$(find "${{ inputs.ARTIFACTS_DIR }}" -type f | wc -l)" -lt 1 ]; then
101103
echo "No files found in ${{ inputs.ARTIFACTS_DIR }}."

0 commit comments

Comments
 (0)