-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
129 lines (106 loc) · 3.85 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
124
125
126
127
128
129
name: Java Unit Test and Analysis with SonarCloud
description: Run Java unit tests, can analyse with SonarCloud
branding:
icon: check-square
color: blue
inputs:
### Required
commands:
description: Commands to run tests, start with '|' for multi-line
required: true
dir:
description: App/package directory
required: true
java-version:
description: Java version, defaults to 17 (LTS)
required: true
### Typical / recommended
java-cache:
description: Java package manager cache, defaults to maven
default: maven
java-distribution:
description: Java distribution, defaults to temurin
default: temurin
sonar_args:
# https://docs.sonarcloud.io/advanced-setup/analysis-parameters/
description: SonarCloud command line arguments
default: |
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=bcgov_${{ github.repository }}
sonar_token:
description: Sonar token, provide unpopulated token for pre-setup (will skip)
triggers:
description: Paths (array) used to trigger a build; e.g. ('./backend/' './frontend/)
### Usually a bad idea / not recommended
diff_branch:
description: Branch to diff against
default: ${{ github.event.repository.default_branch }}
repository:
description: Non-default repository to clone (used for testing this action)
default: ${{ github.repository }}
branch:
description: Non-default branch to clone (used for testing this action)
default: ""
triggers_event:
description: Events (array) to use with triggers; e.g. ("pull_request" "push" "workflow_dispatch")
default: "('pull_request')"
runs:
using: composite
steps:
- name: Warnings for breaking changes
shell: bash
run: |
# Warnings for breaking changes
# sonar_project_token renamed sonar_token
if [ ! -z "${{ inputs.sonar_project_token }}" ]; then
echo -e "\nsonar_project_token renamed. Please correct this and try again."
echo -e "\n\tAction: rename sonar_project_token to sonar_token\n"
exit 1
fi
# Send triggers to diff action
- id: diff
uses: bcgov-nr/[email protected]
with:
triggers: ${{ inputs.triggers }}
diff_branch: ${{ inputs.diff_branch }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
# Setup Java and cache dir
- uses: actions/setup-java@v4
with:
cache: ${{ inputs.java-cache }}
distribution: ${{ inputs.java-distribution }}
java-version: ${{ inputs.java-version }}
server-id: 'github'
# Run tests, hopefully generating coverage for SonarCloud
- name: Run Tests
if: steps.diff.outputs.triggered == 'true'
shell: bash
working-directory: ${{ inputs.dir }}
run: |
# Run tests
${{ inputs.commands }}
### Optional SonarCloud
- if: inputs.sonar_token && steps.diff.outputs.triggered == 'true'
env:
SONAR_TOKEN: ${{ inputs.sonar_token }}
shell: bash
working-directory: ${{ inputs.dir }}
run: |
# Run SonarCloud for ${{ inputs.java-cache }}
if [ "${{ inputs.java-cache }}" == "maven" ]; then
mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.host.url=https://sonarcloud.io ${{ inputs.sonar_args }}
elif [ "${{ inputs.java-cache }}" == "gradle" ]; then
gradlew build sonarqube --info -Dsonar.host.url=https://sonarcloud.io ${{ inputs.sonar_args }}
else
echo "ERROR: inputs.java-cache = ${{ inputs.java-cache }}"
exit 1
fi
### Cleanup
# Fix - Clone for action.yml and other verifications
- name: Checkout Action repo to pass tests
if: always() && inputs.repository != github.repository
uses: actions/checkout@v4