Skip to content

Commit 37653ec

Browse files
authored
feat: branch-out-upload broaden language support (#1320)
1 parent 720f7a0 commit 37653ec

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed

.changeset/funny-hounds-retire.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"branch-out-upload": minor
3+
---
4+
5+
feat: add `test-suite-language` input, and modify behaviour based on the
6+
language

actions/branch-out-upload/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ This action is used to:
88

99
## Inputs
1010

11-
| Input | Description | Required | Default |
12-
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------------- |
13-
| `junit-file-path` | Path to the JUnit XML file to be processed | **Yes** | `./junit.xml` |
14-
| `junit-enhancer-version` | The version of the junit-enhancer to install | No | `latest` |
15-
| `trunk-org-slug` | The organization slug for Trunk.io | **Yes** | - |
16-
| `trunk-token` | The token for Trunk.io | **Yes** | - |
17-
| `trunk-upload-only` | Whether to only upload to Trunk.io, and not let Trunk.io fail the job. Useful when onboarding a repository, and letting Trunk gather data. | No | `false` |
18-
| `trunk-job-url` | The URL to the job run | No | - |
19-
| `trunk-previous-step-outcome` | The outcome of the testing step. Used to determine failure status of this action | **Yes** | - |
20-
| `trunk-variant` | The variant of the test report. Used to differentiate the same test suite across different environments | No | - |
11+
| Input | Description | Required | Default |
12+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------- | -------- | ---------------- |
13+
| `test-suite-language` | The language of the test suite. This determines how the junit file is processed. | **Yes** | `go` |
14+
| `junit-file-path` | Path to the JUnit XML file to be processed | **Yes** | `./junit.xml` |
15+
| `junit-enhancer-version` | The version of the junit-enhancer to install | No | `latest` |
16+
| `trunk-org-slug` | The organization slug for Trunk.io. | **Yes** | - |
17+
| `trunk-token` | The token for Trunk.io. | **Yes** | - |
18+
| `trunk-upload-only` | Upload the result to Trunk.io without using the response to determine the outcome. Common during initial repo onboarding. | No | `false` |
19+
| `trunk-job-url` | The URL to the job run. | **Yes** | See `action.yml` |
20+
| `trunk-previous-step-outcome` | The outcome of the testing step. Used to determine failure status of this action. | **Yes** | - |
21+
| `trunk-variant` | The variant of the test report. Used to differentiate the same test suite across different environments. | No | - |
2122

2223
## Usage
2324

actions/branch-out-upload/action.yml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: branch-out-upload
22
description: "Processes JUnit XML reports and uploads to trunk.io"
33

44
inputs:
5+
test-suite-language:
6+
description: "The programming language of the test suite"
7+
required: true
8+
default: "go"
9+
510
junit-file-path:
611
description: "Path to the JUnit XML file to be processed"
712
required: true
@@ -30,7 +35,10 @@ inputs:
3035

3136
trunk-job-url:
3237
description: "The URL to the job run"
33-
required: false
38+
required: true
39+
default:
40+
${{ format('https://github.com/{0}/actions/runs/{1}/job/{2}/attempts/{3}',
41+
github.repository, github.run_id, job.check_run_id, github.run_attempt) }}
3442

3543
trunk-previous-step-outcome:
3644
description:
@@ -47,24 +55,48 @@ inputs:
4755
runs:
4856
using: composite
4957
steps:
50-
- name: Install JUnit Enhancer
58+
- name: Process inputs
59+
id: inputs-ext
60+
shell: bash
61+
env:
62+
TEST_SUITE_LANGUAGE: ${{ inputs.test-suite-language }}
63+
JUNIT_FILE_PATH: ${{ inputs.junit-file-path }}
64+
run: |
65+
echo "Test suite language: $TEST_SUITE_LANGUAGE"
66+
echo "JUnit file path: $JUNIT_FILE_PATH"
67+
68+
if [[ "$TEST_SUITE_LANGUAGE" == "go" ]]; then
69+
echo "Go test suite detected, will run JUnit Enhancer."
70+
echo "run-enhancer=true" | tee -a "$GITHUB_OUTPUT"
71+
echo "junit-path-to-upload=./junit-enhanced.xml" | tee -a "$GITHUB_OUTPUT"
72+
exit 1
73+
fi
74+
75+
echo "Non-Go test suite detected, skipping JUnit Enhancer."
76+
echo "run-enhancer=false" | tee -a "$GITHUB_OUTPUT"
77+
echo "junit-path-to-upload=$JUNIT_FILE_PATH" | tee -a "$GITHUB_OUTPUT"
78+
79+
- name: Install JUnit Enhancer (go)
80+
if: ${{ steps.inputs-ext.outputs.run-enhancer == 'true' }}
5181
shell: bash
5282
env:
53-
VERSION: ${{ inputs.junit-enhancer-version }}
83+
JUNIT_ENHANCER_VERSION: ${{ inputs.junit-enhancer-version }}
5484
run: |
5585
echo "::group::Install JUnit Enhancer"
56-
go install github.com/smartcontractkit/quarantine/cmd/junit-enhancer@${VERSION}
86+
go install github.com/smartcontractkit/quarantine/cmd/junit-enhancer@${JUNIT_ENHANCER_VERSION}
5787
echo "::endgroup::"
5888
59-
- name: Run JUnit Enhancer
89+
- name: Run JUnit Enhancer (go)
6090
id: run-junit-enhancer
91+
if: ${{ steps.inputs-ext.outputs.run-enhancer == 'true' }}
6192
# continue even if this step fails as it should still have produced an output file that we can upload.
6293
continue-on-error: true
6394
shell: bash
6495
env:
65-
JUNIT_PATH: ${{ inputs.junit-file-path }}
96+
JUNIT_INPUT_PATH: ${{ inputs.junit-file-path }}
97+
JUNIT_OUTPUT_PATH: ${{ steps.inputs-ext.outputs.junit-path-to-upload }}
6698
run: |
67-
junit-enhancer -input ${JUNIT_PATH} -output ./junit-enhanced.xml -verbose
99+
junit-enhancer -input ${JUNIT_INPUT_PATH} -output ${JUNIT_OUTPUT_PATH} -verbose
68100
69101
- name: Upload Test Results to Trunk.io
70102
id: upload-to-trunk
@@ -74,15 +106,15 @@ runs:
74106
TRUNK_TELEMETRY: "off"
75107
JOB_URL: ${{ inputs.job-url }}
76108
with:
77-
junit-paths: "./junit-enhanced.xml"
109+
junit-paths: ${{ steps.inputs-ext.outputs.junit-path-to-upload }}
78110
org-slug: ${{ inputs.trunk-org-slug }}
79111
token: ${{ inputs.trunk-token }}
80112
previous-step-outcome: ${{ inputs.trunk-previous-step-outcome }}
81113
variant: ${{ inputs.trunk-variant }}
82114

83115
- name: Check junit-enhancer outcomes
84116
shell: bash
85-
if: ${{ always() }}
117+
if: ${{ always() && steps.inputs-ext.outputs.run-enhancer == 'true' }}
86118
env:
87119
TRUNK_UPLOAD_ONLY: ${{ inputs.trunk-upload-only }}
88120
STEP_RESULT: ${{ steps.run-junit-enhancer.outcome }}

0 commit comments

Comments
 (0)