-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (135 loc) · 5.46 KB
/
Copy pathcode-maven_java-PR_verify.yml
File metadata and controls
152 lines (135 loc) · 5.46 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
name: code-maven-PR-verify
concurrency:
group: code-PR-verify-${{ github.event.pull_request.number }}
cancel-in-progress: true
on:
pull_request:
paths:
- 'code/**'
- '.github/workflows/code*'
env:
MAVEN_OPTS: "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
SONAR_MAVEN_PLUGIN_VERSION: 5.5.0.6356
SONAR_JAVA_VERSION: temurin-21.0.4+7.0.LTS
jobs:
unit-tests:
name: Code / Verify
runs-on: ubuntu-24.04
permissions:
contents: write
checks: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Maven Cache
uses: actions/cache@v4
continue-on-error: true
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Setup asdf Cache
uses: actions/cache@v4
continue-on-error: true
with:
path: ~/.asdf/data
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
restore-keys: |
${{ runner.os }}-asdf-
- name: Validate tool-versions content
run: |
if grep -Evq '^[a-zA-Z0-9_-]+ [a-zA-Z0-9._+-]+$' code/.tool-versions; then
echo "::error::Invalid .tool-versions content detected"
exit 1
fi
- name: Save tool-versions content
run: |
{
echo "TOOL_VERSIONS<<EOF"
cat code/.tool-versions
echo "EOF"
} >> "$GITHUB_ENV"
- name: Maven / Setup asdf environment
uses: asdf-vm/actions/install@b7bcd026f18772e44fe1026d729e1611cc435d47 # v4
with:
tool_versions: ${{ env.TOOL_VERSIONS }}
- name: Setup Java environment vars
working-directory: code
run: |
JAVA_HOME="$(asdf where java)"
echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: Store project information
if: ${{ vars.IS_INDITEXTECH_REPO == 'true' }}
id: version
run: |
echo "app-version=$(yq -oy '.project.version' code/pom.xml)" >> "$GITHUB_OUTPUT"
echo "app-name=$(yq -oy '.project.artifactId' code/pom.xml)" >> "$GITHUB_OUTPUT"
echo "github-repository=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)" >> "$GITHUB_OUTPUT"
- name: Maven / Verify artifact with coverage
if: ${{ !(contains(github.event.pull_request.labels.*.name, 'autopublish/snapshot-binaries')) }}
working-directory: code
run: |
mvn -B clean verify -Djacoco.skip=false -DskipITs -DfailIfNoTests=false -Dmaven.test.failure.ignore=false -DskipEnforceSnapshots=true
- name: Maven / Process Surefire report and annotate PR
if: ${{ always() && !cancelled() }}
uses: scacap/action-surefire-report@a2911bd1a4412ec18dde2d93b1758b3e56d2a880 # v1
with:
fail_if_no_tests: false
create_check: false
check_name: "Code / Verify"
- name: SonarCloud / Setup asdf tools
if: ${{ vars.IS_INDITEXTECH_REPO == 'true' }}
uses: asdf-vm/actions/install@b7bcd026f18772e44fe1026d729e1611cc435d47 # v4
with:
tool_versions: |
java ${{ env.SONAR_JAVA_VERSION }}
nodejs 20.10.0
maven 3.9.4
- name: SonarCloud / Set asdf versions
if: ${{ vars.IS_INDITEXTECH_REPO == 'true' }}
working-directory: code
run: |
cat > .tool-versions <<VERSIONS
java ${{ env.SONAR_JAVA_VERSION }}
nodejs 20.10.0
maven 3.9.4
VERSIONS
asdf reshim
- name: Setup Java environment vars
if: ${{ vars.IS_INDITEXTECH_REPO == 'true' }}
working-directory: code
run: |
JAVA_HOME="$(asdf where java)"
echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: SonarCloud / Run Maven Sonar goal
if: ${{ vars.IS_INDITEXTECH_REPO == 'true' }}
env:
PR_HEAD_REF: ${{ github.head_ref }}
LOGIN: ${{ secrets.SONAR_TOKEN }}
SONAR_SCANNER_OPTS: ''
working-directory: code
run: |
JACOCO_REPORT_PATH="$GITHUB_WORKSPACE/code/jacoco-report-aggregate/target/site/jacoco-aggregate/jacoco.xml"
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:${{ env.SONAR_MAVEN_PLUGIN_VERSION }}:sonar \
-Dsonar.projectKey="InditexTech_${{ steps.version.outputs.github-repository }}" \
-Dsonar.projectName="${{ steps.version.outputs.app-name }}" \
-Dsonar.projectVersion="${{ steps.version.outputs.app-version }}" \
-Dsonar.host.url="https://sonarcloud.io/" \
-Dsonar.organization=inditextech \
-Dsonar.token="${LOGIN}" \
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
-Dsonar.pullrequest.branch="$PR_HEAD_REF" \
-Dsonar.pullrequest.base=${{ github.base_ref }} \
-Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \
-Dsonar.qualitygate.wait=true \
-Dsonar.qualitygate.timeout=300 \
-Dsonar.pullrequest.provider=GitHub \
-Dsonar.pullrequest.github.repository="${{ github.repository }}" \
-Dsonar.pullrequest.github.summary_comment=true \
-Dsonar.coverage.jacoco.xmlReportPaths="$JACOCO_REPORT_PATH"