Skip to content

Commit

Permalink
Don't upload multiple times to same artifact in "Manage PRs" workflow
Browse files Browse the repository at this point in the history
The `check-submissions` job of the "Run integration tests" GitHub Actions workflow is configured to generate multiple
parallel jobs, one for each of the submitted libraries. The subsequent jobs must be able to determine whether any of the
libraries failed the checks. This is done by the matrix jobs in which checks failed uploading a flag file to a GitHub
Actions workflow artifact, then the subsequent jobs checking for the presence of an artifact. The
"actions/upload-artifact" and "actions/download-artifact" actions are used for this purpose.

Previously, a single artifact was used for all flag files, with each of the parallel jobs uploading its flag file to
that single artifact. However, support for uploading multiple times to a single artifact was dropped in version 4.0.0 of
the "actions/upload-artifact" action. So it is now necessary to use a dedicated artifact for each of the parallel jobs.
These artifacts  can be downloaded in aggregate by using the artifact name globbing feature which was introduced in
version 4.1.0 of the "actions/download-artifact" action.
  • Loading branch information
per1234 committed Nov 1, 2024
1 parent 4a42992 commit 5d935c3
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions .github/workflows/manage-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env:
MAINTAINERS: |
# GitHub user names to request reviews from in cases where PRs can't be managed automatically.
- per1234
CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT: check-submissions-failed
CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PREFIX: check-submissions-failed-
ERROR_MESSAGE_PREFIX: ":x: **ERROR:** "

on:
Expand Down Expand Up @@ -376,6 +376,13 @@ jobs:
if: env.PASS == 'false'
run: touch ${{ env.FAIL_FLAG_PATH }} # Arbitrary file to provide content for the flag artifact

# Each workflow artifact must have a unique name. The job matrix doesn't provide a guaranteed unique string to use
# for a name so it is necessary to generate one.
- name: Generate unique artifact suffix
if: env.PASS == 'false'
run: |
echo "CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_SUFFIX=$(cat /proc/sys/kernel/random/uuid)" >> "$GITHUB_ENV"
# The value of a job matrix output is set by whichever job happened to run last, not of use for this application.
# So it's necessary to use an alternative means of indicating that at least one submission failed the checks.
- name: Upload failure flag artifact
Expand All @@ -385,7 +392,7 @@ jobs:
if-no-files-found: error
include-hidden-files: true
path: ${{ env.FAIL_FLAG_PATH }}
name: ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT }}
name: ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PREFIX }}${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_SUFFIX }}

check-submissions-result:
needs: check-submissions
Expand All @@ -394,13 +401,22 @@ jobs:
outputs:
pass: ${{ steps.failure-flag-exists.outcome == 'failure' }}

env:
CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PATH: ${{ github.workspace }}/artifacts

steps:
- name: Download submission check failure flag artifacts
uses: actions/download-artifact@v4
with:
path: ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PATH }}
pattern: ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PREFIX }}*

- name: Check for existence of submission check failure flag artifact
id: failure-flag-exists
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: ${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT }}
# actions/download-artifact does not create a folder per its `path` input if no artifacts match `pattern`.
run: |
test -d "${{ env.CHECK_SUBMISSIONS_FAIL_FLAG_ARTIFACT_PATH }}"
check-submissions-fail:
needs:
Expand Down

0 comments on commit 5d935c3

Please sign in to comment.