Skip to content

Commit 6b0a752

Browse files
authored
Fix conditionals that trigger Artifact upload (#38236)
#### Description After the revert done in #38230 and #38231, I'm looking yet again on what went wrong there. I'm solving this in small parts, and this PR focuses on ensuring JUnit Artifacts are uploaded correctly. #### Link to tracking issue Still related to #36761 #### Testing I plan to test this by looking at the artifacts produced in this PR. The JUnit files need to be there. See https://github.com/actions/upload-artifact?tab=readme-ov-file#where-does-the-upload-go --------- Signed-off-by: Arthur Silva Sens <[email protected]>
1 parent 7ec4927 commit 6b0a752

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

.github/workflows/build-and-test.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -286,22 +286,31 @@ jobs:
286286
path: ~/.cache/go-build
287287
key: go-test-build-${{ runner.os }}-${{ matrix.go-version }}-${{ matrix.runner }}-${{ hashFiles('**/go.sum') }}
288288
- name: Run Unit Tests
289-
if: startsWith( matrix.go-version, '1.23' ) != true
289+
id: tests
290+
if: github.ref != 'refs/heads/main' # Runs on every PR and both go versions
290291
run: make gotest GROUP=${{ matrix.group }}
291292
- name: Run Unit Tests With JUnit and Coverage
292-
if: startsWith( matrix.go-version, '1.23' ) # only run junit/coverage on one version
293+
id: tests-with-junit
294+
if: startsWith( matrix.go-version, '~1.23' ) && github.ref == 'refs/heads/main' && github.event_name == 'push' # only run junit/coverage on one version and only on main
295+
continue-on-error: true # Allow uploading artifacts even if the test fails
293296
run: make gotest-with-junit-and-cover GROUP=${{ matrix.group }}
294297
- uses: actions/upload-artifact@v4
295-
if: startsWith( matrix.go-version, '1.23' ) # only upload artifact for one version
298+
if: startsWith( matrix.go-version, '~1.23' ) && github.ref == 'refs/heads/main' && github.event_name == 'push' # only upload artifact for one version and only on main
296299
with:
297300
name: coverage-artifacts-${{ matrix.go-version }}-${{ matrix.runner }}-${{ matrix.group }}
298301
path: ${{ matrix.group }}-coverage.txt
299302
- uses: actions/upload-artifact@v4
300-
if: startsWith( matrix.go-version, '1.23' ) # only upload artifact for one version
303+
if: startsWith( matrix.go-version, '~1.23' ) && github.ref == 'refs/heads/main' && github.event_name == 'push' # only upload artifact for one version and only on main
301304
with:
302305
name: test-results-${{ matrix.go-version }}-${{ matrix.runner }}-${{ matrix.group }}
303306
path: internal/tools/testresults/
304307
retention-days: 4
308+
- name: Fail workflow if tests fails
309+
if: steps.tests-with-junit.outcome == 'failure' || steps.tests.outcome == 'failure'
310+
run: |
311+
echo "Tests failed. Failing workflow."
312+
exit 1
313+
305314
unittest:
306315
if: ${{ github.actor != 'dependabot[bot]' && always() }}
307316
runs-on: ubuntu-24.04

0 commit comments

Comments
 (0)