-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
123 lines (109 loc) · 4.37 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Run a gradle/junit task and upload test reports
description: |
Run a gradle task expecting JUnit reports to be produced. The exported reports will follow naming conventions detailed
by our ADRs (https://confluence.equisoft.com/display/HRMI/ADR).
This actions will also annotate the PR or commit with the failed tests.
inputs:
gradle-properties:
description: Content of a gradle.properties file that will be passed to the gradle runner.
required: false
gradle-project-path:
description: |
Gradle project path. For example: bff.
Defaults to the root project.
required: true
default: "."
read-only-cache:
description: If set to true, the action will only read from the cache and will not write to it.
required: true
default: "true"
report-retention-days:
description: Duration in days to preserve reports.
required: true
default: "5"
task-name:
description: |
The JUnit task name. The action expects a Gradle task named "ci-<task-name>".
This task name will be used to read multiple outputs under the build directory:
- <project>/build/jacoco/<task-name>.exec
- <project>/build/reports/tests/<task-name>/
- <project>/build/test-results/<task-name>/
Defaults to "test".
required: true
default: test
working-directory:
description: Relative path under $GITHUB_WORKSPACE where the root project is located.
required: false
default: "."
runs:
using: composite
steps:
- name: metadata
id: metadata
shell: bash
run: |
WORKING_DIRECTORY=${{ inputs.working-directory }}
GRADLE_PROJECT_PATH=${{ inputs.gradle-project-path }}
if [[ "$GRADLE_PROJECT_PATH" == "." ]]; then
ARTIFACT_PATH="$WORKING_DIRECTORY/**"
else
ARTIFACT_PATH="$WORKING_DIRECTORY/$GRADLE_PROJECT_PATH"
fi
echo "artifact-path=$ARTIFACT_PATH" >> $GITHUB_OUTPUT
- name: Process gradle properties
id: gradle-properties
shell: python
env:
GRADLE_PROPERTIES: ${{ inputs.gradle-properties }}
run: |
import os
properties_list: list[str] = [line for line in (line.strip() for line in os.environ.get('GRADLE_PROPERTIES').splitlines()) if line]
properties = list(map(lambda x: f'-P{x}' if not x.startswith('-P') else x, properties_list))
with open(os.environ.get('GITHUB_OUTPUT'), 'a') as output_file:
output_file.write('gradle-properties=')
output_file.write(' '.join(properties))
output_file.write('\n')
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
build-root-directory: ${{ inputs.working-directory }}
cache-read-only: ${{ inputs.read-only-cache }}
- name: Run tests
shell: bash
working-directory: ${{ inputs.working-directory }}
run: ./gradlew -p ${{ inputs.gradle-project-path }} ci-${{ inputs.task-name }} ${{ steps.gradle-properties.outputs.gradle-properties }}
- name: Upload report
uses: actions/upload-artifact@v4
if: "!cancelled()"
with:
name: ${{ inputs.task-name }}-report
retention-days: ${{ inputs.report-retention-days }}
path: |
${{ steps.metadata.outputs.artifact-path }}/build/reports/tests/${{ inputs.task-name }}/
- name: Upload results
uses: actions/upload-artifact@v4
if: "!cancelled()"
with:
name: ${{ inputs.task-name }}-results
retention-days: 1
if-no-files-found: error
path: |
${{ steps.metadata.outputs.artifact-path }}/build/test-results/${{ inputs.task-name }}/
!${{ steps.metadata.outputs.artifact-path }}/build/test-results/${{ inputs.task-name }}/binary
- name: Upload coverage results
uses: actions/upload-artifact@v4
if: "!cancelled()"
with:
name: ${{ inputs.task-name }}-jacoco-build
retention-days: 1
if-no-files-found: error
path: |
${{ steps.metadata.outputs.artifact-path }}/build/jacoco/${{ inputs.task-name }}.exec
- name: Create annotations
uses: mikepenz/action-junit-report@v4
if: "!cancelled() && github.actor != 'dependabot[bot]'"
with:
check_name: ${{ inputs.task-name }} report
report_paths: |
${{ steps.metadata.outputs.artifact-path }}/build/test-results/${{ inputs.task-name }}/TEST-*.xml