-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
138 lines (115 loc) · 4.25 KB
/
action.yml
File metadata and controls
138 lines (115 loc) · 4.25 KB
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
130
131
132
133
134
135
136
137
138
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
pattern: "^[a-zA-Z0-9._/-]+$"
java-version:
description: Java version, defaults to 17 (LTS)
required: true
pattern: '^[0-9]+(\.[0-9]+)*$'
### Typical / recommended
java-cache:
description: Java package manager cache, defaults to maven
default: maven
pattern: "^(maven|gradle)$"
java-distribution:
description: Java distribution, defaults to temurin
default: temurin
pattern: "^(temurin|corretto|openjdk|zulu)$"
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)
pattern: "^[a-zA-Z0-9]{20,}$"
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 }}
pattern: "^[a-zA-Z0-9._/-]+$"
repository:
description: Non-default repository to clone (used for testing this action)
default: ${{ github.repository }}
pattern: "^[a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+$"
branch:
description: Non-default branch to clone (used for testing this action)
default: ""
pattern: "^[a-zA-Z0-9._/-]*$"
outputs:
triggered:
description: Whether the action was triggered based on path changes
value: ${{ steps.diff.outputs.triggered }}
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, but only for pull requests
- id: diff
uses: bcgov/action-diff-triggers@4abfcb211f5816d654d1c5a417e5431a2c4a5379 # v1.1.1
with:
triggers: ${{ (github.event_name == 'pull_request' && inputs.triggers) || '' }}
diff_branch: ${{ inputs.diff_branch }}
- uses: actions/checkout@v6
with:
fetch-depth: 0
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
# Setup Java and cache dir
- uses: actions/setup-java@v5
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@v6