-
-
Notifications
You must be signed in to change notification settings - Fork 16
172 lines (154 loc) Β· 5.81 KB
/
build.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Build CI
on:
push:
tags: [ '[0-9]+.[0-9]+.[0-9]+' ]
branches: [ main ]
pull_request:
branches: [ main ]
types: [ opened, reopened, synchronize ]
paths:
- .github/workflows/**
- gradle/**
- kata/**
- build.gradle.kts
- settings.gradle.kts
- gradle.properties
workflow_dispatch:
inputs:
ref_name:
description: Branch, tag or SHA to checkout
job_count:
description: Max concurrent jobs to execute
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
fork:
runs-on: ubuntu-22.04
timeout-minutes: 1
outputs:
job_count: ${{ steps.job.outputs.count }}
job_sid: ${{ steps.job.outputs.sid }}
steps:
- name: Assign job IDs
id: job
run: |
# set default as inputs resolve only at manual executions
JOB_COUNT=${{ github.event.inputs.job_count || 40 }}
echo "count=$JOB_COUNT" >> $GITHUB_OUTPUT
echo "sid=[`seq -s , 1 $JOB_COUNT`]" >> $GITHUB_OUTPUT
# ------------------------
test:
needs: fork
runs-on: ubuntu-22.04
timeout-minutes: 8
strategy:
matrix:
job_sid: ${{ fromJson(needs.fork.outputs.job_sid) }}
steps:
- name: Checkout repository (default ref)
if: ${{ github.event.inputs.ref_name == '' }}
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Checkout repository (custom ref)
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
if: ${{ github.event.inputs.ref_name != '' }}
with:
ref: ${{ github.event.inputs.ref_name }}
- name: Switch to Gradle Binary Distribution
run: sed -i 's/-all.zip/-bin.zip/' gradle/wrapper/gradle-wrapper.properties
- name: Setup Java
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0
with:
distribution: temurin
java-version: 17
cache: gradle
- name: Test project
uses: gradle/gradle-build-action@8cbcb9948b5892387aed077daf6f90e1f0ba5b27 # v2.11.0
with:
gradle-home-cache-cleanup: true
arguments: |
test jacocoTestReport -x processResources -x processTestResources
--parallel
--build-cache
--no-daemon
--scan
-DforkCount=${{ needs.fork.outputs.job_count }}
-DforkSid=${{ matrix.job_sid }}
-Dsonar.gradle.skipCompile=true
- name: Pack fork artifacts
run: |
find . -path "*/main/*.class" -o -path "*/test/*.class" -o -path "*/jacocoTestReport.xml" > artifacts
tar czfT artifacts.tar.gz artifacts
- name: Upload fork artifacts
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0
with:
name: fork-${{ matrix.job_sid }}
retention-days: 1
path: artifacts.tar.gz
# ------------------------
scan:
needs: test
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
contents: write
env:
VERSION: 1.21.0
steps:
- name: Checkout repository (default ref)
if: ${{ github.event.inputs.ref_name == '' }}
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Checkout repository (custom ref)
if: ${{ github.event.inputs.ref_name != '' }}
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.inputs.ref_name }}
- name: Download fork artifacts
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
- name: Unpack fork artifacts
run: for f in fork-*/artifacts.tar.gz; do tar xf $f && rm $f; done
- name: Switch to Gradle Binary Distribution
run: sed -i 's/-all.zip/-bin.zip/' gradle/wrapper/gradle-wrapper.properties
- name: Setup Java
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0
with:
distribution: temurin
java-version: 17
cache: gradle
- name: Analyze code quality (main)
if: startsWith(github.event_name, 'pull_request') == false
uses: gradle/gradle-build-action@8cbcb9948b5892387aed077daf6f90e1f0ba5b27 # v2.11.0
with:
gradle-home-cache-cleanup: true
dependency-graph: generate-and-submit
arguments: |
sonar -x compileJava -x compileTestJava
--no-daemon
--scan
-Pversion=${{ format('{0}+{1}', env.VERSION, github.RUN_NUMBER) }}
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
-Dsonar.organization=${{ secrets.SONAR_KEY }}
-Dsonar.branch.name=${{ github.event.inputs.ref_name || github.REF_NAME}}
-Dsonar.qualitygate.wait=true
-Dsonar.gradle.skipCompile=true
- name: Analyze code quality (PR)
if: startsWith(github.event_name, 'pull_request')
uses: gradle/gradle-build-action@8cbcb9948b5892387aed077daf6f90e1f0ba5b27 # v2.11.0
with:
arguments: |
sonar -x compileJava -x compileTestJava
--no-daemon
--scan
-Pversion=${{ format('{0}+{1}', env.VERSION, github.RUN_NUMBER) }}
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
-Dsonar.organization=${{ secrets.SONAR_KEY }}
-Dsonar.pullrequest.provider=github
-Dsonar.pullrequest.branch=${{ github.HEAD_REF }}
-Dsonar.pullrequest.base=${{ github.BASE_REF }}
-Dsonar.pullrequest.key=${{ github.event.number }}
-Dsonar.qualitygate.wait=true
-Dsonar.gradle.skipCompile=true