-
Notifications
You must be signed in to change notification settings - Fork 70
236 lines (210 loc) · 9.18 KB
/
maven-build-test.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: CI/CD
on:
workflow_dispatch:
push:
# https://github.community/t/action-does-not-run-on-master-with-tags-ignore-v/128354/4
branches:
- '**'
paths-ignore:
- 'documentation/**'
- 'solicitor/**'
- '**.asciidoc'
tags-ignore:
- '**'
pull_request:
paths-ignore:
- 'documentation/**'
- 'solicitor/**'
- '**.asciidoc'
env:
# if continuously builds exiting randomly, possibly add again -Djansi.force=true -Djansi.passthrough=true
MVN_BATCH_MODE: '-B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn'
# fixing random connection reset of maven downloads as proposed here: https://github.com/actions/virtual-environments/issues/2715#issuecomment-797388909
MVN_HTTP_OPTIMIZATION: '-Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120'
REPOSITORY_PATH: repo
jobs:
cache-dependencies:
runs-on: ubuntu-latest
steps:
- name: Enable git support for long paths on Windows
if: ${{ runner.os == 'Windows' }}
shell: cmd
run: git config --system core.longpaths true
- name: Clone Repository
uses: actions/checkout@v3
with:
path: ${{ env.REPOSITORY_PATH }}
- name: Checkout & Prepare
uses: devonfw-actions/java-maven-setup@main
with:
maven-cache-path: ./.m2/repository
maven-cache-key: cobigen-dep-${{ hashFiles(format('{0}/**/pom.xml', env.REPOSITORY_PATH)) }}
clone: false # checkout in a separate / earlier step to allow eager evaluation of parameter expression like workspace or hashFiles
- name: Overwrite maven settings
shell: bash
run: |
mkdir -p ~/.m2
cp -rf ${{ env.REPOSITORY_PATH }}/.mvn/ci-settings.xml ~/.m2/settings.xml
- name: Resolve non-cobigen dependencies
shell: bash
run: |
cd ${{ env.REPOSITORY_PATH }}
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:resolve -pl !com.devonfw.cobigen:com.devonfw.cobigen.eclipse.test -DexcludeGroupIds=com.devonfw.cobigen -T1C -Pp2-build ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} || true # never fail
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:resolve-plugins -pl !com.devonfw.cobigen:com.devonfw.cobigen.eclipse.test -DexcludeGroupIds=com.devonfw.cobigen -T1C -Pp2-build ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} || true # never fail
build:
needs: cache-dependencies
runs-on: ubuntu-latest
steps:
- name: Enable git support for long paths on Windows
if: ${{ runner.os == 'Windows' }}
shell: cmd
run: git config --system core.longpaths true
- name: Clone Repository
uses: actions/checkout@v3
with:
path: ${{ env.REPOSITORY_PATH }}
- name: Checkout & Prepare
uses: devonfw-actions/java-maven-setup@main
with:
maven-cache-path: ./.m2/repository
maven-cache-key: maven-${{ github.sha }}-${{ github.run_number }} # new key will cache
maven-cache-restore-key: cobigen-dep-${{ hashFiles(format('{0}/**/pom.xml', env.REPOSITORY_PATH)) }}
java-version: 11
clone: false # checkout in a separate / earlier step to allow eager evaluation of parameter expression like workspace or hashFiles
- name: Cache built P2 repositories
uses: actions/cache@v3
with:
path: ./${{ env.REPOSITORY_PATH }}/**/target/repository/
key: p2-${{ github.sha }}-${{ github.run_number }} # new key will cache
enableCrossOsArchive: true
- name: Build all artifacts
shell: bash
run: |
cd ${{ env.REPOSITORY_PATH }}
./build.sh -spb
test:
needs: build
strategy:
fail-fast: false
matrix:
component: [core, plugins, templates, maven, eclipse, cli]
javaVersion: [11]
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Enable git support for long paths on Windows
if: ${{ runner.os == 'Windows' }}
shell: cmd
run: git config --system core.longpaths true
- name: Clone Repository
uses: actions/checkout@v3
with:
path: ${{ env.REPOSITORY_PATH }}
- uses: devonfw-actions/java-maven-setup@main
with:
maven-cache-path: ./.m2/repository
maven-cache-key: maven-${{ github.sha }}-${{ github.run_number }} # match, restore only
java-version: ${{ matrix.javaVersion }}
jacoco-cache-key: jacoco-${{ github.sha }}-${{ matrix.component }} # new key will cache
clone: false # checkout in a separate / earlier step to allow eager evaluation of parameter expression like workspace or hashFiles
- name: Restore built P2 repositories
uses: actions/cache@v3
with:
path: ./${{ env.REPOSITORY_PATH }}/**/target/repository/
key: p2-${{ github.sha }}-${{ github.run_number }} # match, restore only
enableCrossOsArchive: true
# need to overwrite global settings file to cath all mvn executions properly in tests
- name: Overwrite maven settings
shell: bash
run: |
mkdir -p ~/.m2
cp -rf ${{ env.REPOSITORY_PATH }}/.mvn/ci-settings.xml ~/.m2/settings.xml
- name: Test
shell: bash
env:
M2_REPO: ${{ github.workspace }}/.m2/repository # fix for https://github.com/m-m-m/code/issues/43
run: |
cd ${{ env.REPOSITORY_PATH }}
if [[ "${{ matrix.component }}" == "eclipse" && "${{ matrix.os }}" == "ubuntu-latest" ]]
then
xvfb-run -a ./build.sh -sdtcb --components ${{ matrix.component }}
else
./build.sh -sdtcb --components ${{ matrix.component }}
fi
# Sonar Analysis is done in separate workflow (https://github.com/devonfw/cobigen/blob/master/.github/workflows/sonar-analysis.yml)
# as of a workaround of potential secret leaking on PRs (https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)
sonar-analysis-preparation:
needs: [test]
runs-on: ubuntu-latest
steps:
- name: 'Prepare workflow context for transfer'
env:
# As a precaution, reference this value by an interpolated ENV var;
# instead of interpolating user controllable input directly in the shell script.
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
# Save ENV for transfer
{
echo "PR_HEADSHA=${{ github.event.pull_request.head.sha }}"
echo "PR_NUMBER=${{ github.event.pull_request.number }}"
echo "PR_TITLE=${PR_TITLE}"
} >> workflow.env
tar --zstd -cf workflow.tar.zst workflow.env
- name: 'Upload workflow context artifact'
uses: actions/upload-artifact@v3
with:
name: maven-build-test-workflow-context
path: workflow.tar.zst
retention-days: 1
release:
needs: [test]
runs-on: ubuntu-latest
if: ${{ startsWith(github.repository, 'devonfw/') && github.ref == 'refs/heads/master' }}
continue-on-error: true
environment:
name: maven-central
outputs:
release_tag: ${{ steps.get_tag.outputs.tag }}
steps:
- name: Clone Repository
uses: actions/checkout@v3
with:
path: ${{ env.REPOSITORY_PATH }}
- uses: devonfw-actions/java-maven-setup@main
with:
maven-cache-path: ./.m2/repository
maven-cache-key: cobigen-dep-${{ hashFiles(format('{0}/**/pom.xml', env.REPOSITORY_PATH)) }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
BUILD_USER: ${{ secrets.BUILD_USER }}
BUILD_USER_PASSWD: ${{ secrets.BUILD_USER_PASSWD }}
BUILD_USER_EMAIL: ${{ secrets.BUILD_USER_EMAIL }}
clone: false # checkout in a separate / earlier step to allow eager evaluation of parameter expression like workspace or hashFiles
- name: Release
id: release
shell: bash
env:
GPG_KEY: ${{ secrets.GPG_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
BUILD_USER: ${{ secrets.BUILD_USER }}
BUILD_USER_PASSWD: ${{ secrets.BUILD_USER_PASSWD }}
BUILD_USER_EMAIL: ${{ secrets.BUILD_USER_EMAIL }}
run: |
cd ${{ env.REPOSITORY_PATH }}
./release.sh -syb skip-qa
- name: 'Get release tag'
id: get_tag
uses: "WyriHaximus/github-action-get-previous-tag@v1.1.0"
env:
GITHUB_TOKEN: "${{ secrets.GHA_TOKEN }}"
github-release:
needs: release
runs-on: ubuntu-latest
if: ${{ startsWith(github.repository, 'devonfw/') && github.ref == 'refs/heads/master' && needs.release.outputs.release_tag != '' }}
steps:
- uses: devonfw-actions/create-github-release@v1
with:
release_version: ${{ needs.release.outputs.release_tag }}
GHA_TOKEN: ${{ secrets.GHA_TOKEN }}