-
Notifications
You must be signed in to change notification settings - Fork 0
227 lines (210 loc) · 7.75 KB
/
ci-cd.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
# Workflow for checking and releasing all new commits to main and tags
name: CI/CD
on:
push:
branches: # Trigger on commits to main
- main
tags:
- v* # Also version tags
concurrency:
group: cicd-${{ github.ref }}
cancel-in-progress: false
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out main Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Set up Apache Maven Central
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
cache: 'maven'
- name: Run tests
run: mvn clean verify -B
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out main Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
submodules: 'true'
- name: Set up Apache Maven Central
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
cache: 'maven'
- name: Run static checks
run: mvn compile -B -P lint,strict
prepare:
name: Prepare Metadata
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
type: ${{ steps.get-type.outputs.type }}
site: ${{ steps.get-site.outputs.version }}
steps:
- name: Check out GH Pages branch
uses: actions/checkout@v3
with:
ref: gh-pages # Github Pages branch
- name: Get latest site version
id: get-site-version
run: |
git fetch --update-shallow --tags --depth=3
VER="$( git describe --tags --abbrev=0 --match 'v*.*.*-site' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' || echo '0.0.0' )"
echo "version=${VER}" >> $GITHUB_OUTPUT
- name: Check out main Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Set up Apache Maven Central
uses: actions/setup-java@v3
with: # running setup-java again overwrites the settings.xml
distribution: 'zulu'
java-version: 17
cache: 'maven'
- name: Determine version
id: get-version
run: echo "version=$( mvn help:evaluate '-Dexpression=project.version' -q -DforceStdout )" >> $GITHUB_OUTPUT
- name: Determine type
id: get-type
run: |
if [[ "${{ steps.get-version.outputs.version }}" == *-SNAPSHOT ]]; then
echo "type=snapshot" >> $GITHUB_OUTPUT
else
echo "type=release" >> $GITHUB_OUTPUT
fi
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
- name: Determine site tag
id: get-site
run: |
PREV_SITE_VER="${{ steps.get-site-version.outputs.version }}"
NEW_VER="${{ steps.get-version.outputs.version }}"
RELEASE_TYPE="${{ steps.get-type.outputs.type }}"
DIFF="$( python .github/scripts/compare_semver.py $NEW_VER $PREV_SITE_VER )"
if [ "$RELEASE_TYPE" = "release" ] && [ "$DIFF" -gt 0 ]; then
echo "version=v${NEW_VER}-site" >> $GITHUB_OUTPUT
else
echo "version=none" >> $GITHUB_OUTPUT
fi
deploy:
name: Deploy Version
needs: [ test, lint, prepare ]
runs-on: ubuntu-latest
if: github.ref_type == 'tag' || needs.prepare.outputs.type == 'snapshot'
steps:
- name: Check out main Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Set up Apache Maven Central
uses: actions/setup-java@v3
with: # running setup-java again overwrites the settings.xml
distribution: 'zulu'
java-version: 17
cache: 'maven'
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
server-username: NEXUS_USERNAME # env variable for username in deploy
server-password: NEXUS_PASSWORD # env variable for token in deploy
gpg-private-key: ${{ secrets.gpg_private_key }} # Value of the GPG private key to import
gpg-passphrase: GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: Publish to OSSRH
run: mvn deploy -B -P deploy,ossrh -Dmaven.test.skip=true
env:
NEXUS_USERNAME: ${{ secrets.nexus_username }}
NEXUS_PASSWORD: ${{ secrets.nexus_password }}
GPG_PASSPHRASE: ${{ secrets.gpg_passphrase }}
MAVEN_OPTS: "--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED"
# https://issues.sonatype.org/browse/OSSRH-66257
- name: Set up Github Packages
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
gpg-passphrase: GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: Publish to GitHub Packages
run: mvn deploy -B -P deploy,github -Dmaven.test.skip=true
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ github.token }}
GPG_PASSPHRASE: ${{ secrets.gpg_passphrase }}
- name: Upload release artifact
uses: actions/upload-artifact@v3
with:
name: release
path: |
target/*.jar
target/*.jar.asc
site-build:
name: Build Site
needs: [ test, lint ]
runs-on: ubuntu-latest
steps:
- name: Check out main Git repository
uses: actions/checkout@v3
with:
ref: ${{ github.sha }}
- name: Set up Apache Maven Central
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
cache: 'maven'
- name: Run tests # If it got this far, it *should* be guaranteed to pass, but needed for the report
run: mvn clean verify -B
- name: Build project site
run: mvn site -B
- name: Tarball project site
run: tar -czf site.tar.gz -C target/site .
- name: Upload site artifact
uses: actions/upload-artifact@v3
with:
name: site
path: site.tar.gz
site-deploy:
name: Deploy Site
needs: [ prepare, deploy, site-build ]
runs-on: ubuntu-latest
if: needs.prepare.outputs.site != 'none'
concurrency: cd-site-${{ needs.prepare.outputs.version }}
steps:
- name: Check out GH Pages branch
uses: actions/checkout@v3
with:
ref: gh-pages # Github Pages branch
- name: Delete existing site files except CNAME
run: |
find . ! -path './.git/*' ! -path './.git' ! -path . -type d -exec rm -rf {} +
find . ! -path './.git/*' ! -path './CNAME' -type f -exec rm -f {} +
- name: Download site artifact
uses: actions/download-artifact@v3
with:
name: site
- name: Unpack the artifact
run: tar -xzf site.tar.gz
- name: Delete the (local) artifact
run: rm site.tar.gz
- name: Configure git commiter identity
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Commit new files
run: |
git add -A
git commit -m "Updated project site to release version ${{ needs.prepare.outputs.version }}"
git tag -a ${{ needs.prepare.outputs.site }} -m "Site for release version ${{ needs.prepare.outputs.version }}"
- name: Push changes
run: |
git push origin gh-pages
git push origin ${{ needs.prepare.outputs.site }}