@@ -166,28 +166,39 @@ jobs:
166166 key : ${{ runner.os }}-junit-${{ hashFiles('**/pom.xml') }} # key for restoring and saving the cache
167167 restore-keys : ${{ runner.os }}-junit- # key for restoring the cache if no exact match is found
168168 # In this step, we are downloading the latest artifact from the build job and storing it in the container
169- - run : |
170- # Download the latest test results artifact number using GitHub API
171- LATEST_ARTIFACT_NUMBER=$(curl \
172- -H "Accept: application/vnd.github+json" \
173- -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
174- -H "X-GitHub-Api-Version: 2022-11-28" \
175- https://api.github.com/repos/${{ github.repository }}/actions/artifacts | \
176- jq -r '.artifacts | sort_by(.created_at) | .[] | select(.name == "Test Results") | .id' | \
177- sort -n | tail -n 1)
178-
179- # Save the artifact number to the environment file
180- echo "LATEST_ARTIFACT_NUMBER=${LATEST_ARTIFACT_NUMBER}" >> $GITHUB_ENV
181-
182- curl \
169+ - name : Download and unzip all test results artifacts
170+ run : |
171+ # Fetch the last successful workflow run ID
172+ LAST_SUCCESSFUL_RUN_ID=$(curl \
183173 -H "Accept: application/vnd.github+json" \
184174 -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
185175 -H "X-GitHub-Api-Version: 2022-11-28" \
186- -L -o my_artifact.zip \
187- https://api.github.com/repos/${{ github.repository }}/actions/artifacts/"${LATEST_ARTIFACT_NUMBER}"/zip
176+ https://api.github.com/repos/${{ github.repository }}/actions/runs?status=success&per_page=1 | \
177+ jq -r '.workflow_runs[0].id')
178+
179+ ARTIFACT_IDS=$(curl \
180+ -H "Accept: application/vnd.github+json" \
181+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
182+ -H "X-GitHub-Api-Version: 2022-11-28" \
183+ https://api.github.com/repos/${{ github.repository }}/actions/runs/"${LAST_SUCCESSFUL_RUN_ID}"/artifacts | \
184+ jq -r '.artifacts | sort_by(.created_at) | .[] | select(.name | startswith("testresults-")) | .id')
185+
186+ echo "ARTIFACT_IDS=$ARTIFACT_IDS" >> $GITHUB_ENV
187+
188+ mkdir -p test_results
189+
190+ for ARTIFACT_ID in $ARTIFACT_IDS; do
191+ curl \
192+ -H "Accept: application/vnd.github+json" \
193+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
194+ -H "X-GitHub-Api-Version: 2022-11-28" \
195+ -L -o my_artifact.zip \
196+ https://api.github.com/repos/${{ github.repository }}/actions/artifacts/"${ARTIFACT_ID}"/zip
197+
198+ unzip my_artifact.zip -d test_results 2> /dev/null || true
199+ rm my_artifact.zip
200+ done
188201
189- mkdir test_results
190- unzip my_artifact.zip -d test_results 2> /dev/null || true
191202 - name : Ensure junit-path exists and that all xml files are readable in path 'test_results/**/*xml' with this syntax
192203 run : |
193204 if [ ! -d "test_results" ]; then
0 commit comments