-
Notifications
You must be signed in to change notification settings - Fork 28
279 lines (271 loc) · 10.4 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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: build
on:
push:
branches: [ main ]
tags:
- 'v*.*.*'
paths-ignore:
- '.talismanrc'
- '*.md'
env:
SERVICE_NAME: gitactionboard
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout local repository
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/${{ env.SERVICE_NAME }}
- name: Install nvm at specific version
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- name: Install prettier using npm
run: sudo npm install --global prettier
- name: Install jenv
run: |
git clone https://github.com/gcuisinier/jenv.git ~/.jenv
echo "$HOME/.jenv/bin" >> $GITHUB_PATH
- name: Configure jenv
run: |
jenv init -
jenv add ${JAVA_HOME_21_X64}
- name: Install Hadolint and add to PATH
run: |
sh bin/install-hadolint.sh
echo "$GITHUB_WORKSPACE/$SERVICE_NAME" >> $GITHUB_PATH
working-directory: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: Cache gradle wrapper and jars
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-${{ steps.get-date.outputs.date }}-
${{ runner.os }}-gradle-
- name: Cache node modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.get-date.outputs.date }}-
${{ runner.os }}-node-
${{ runner.os }}-
- name: Cache pitest history
uses: pat-s/[email protected]
with:
path: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/backend/pitestHistory/pitestHistory
key: pitestHistory-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
pitestHistory-${{ steps.get-date.outputs.date }}-
pitestHistory-
- name: Run all tests
run: ./run.sh test
working-directory: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/
- name: Run Mutation test for backend
run: ./run.sh pitest
working-directory: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/
- name: Upload build report to artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ env.SERVICE_NAME }}-build-reports
path: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/backend/build/reports/
determaine_should_publish_new_version:
runs-on: ubuntu-22.04
outputs:
PUBLISH_NEW_VERSION: ${{ steps.determaine_should_publish_new_version.outputs.PUBLISH_NEW_VERSION }}
steps:
- name: Checkout local repository
uses: actions/checkout@v4
- name: Determine should publish docker image
id: determaine_should_publish_new_version
run: |
PUBLISH_NEW_VERSION=false
if [[ $(git tag --points-at HEAD) != '' ]]; then
PUBLISH_NEW_VERSION=true
fi
echo "PUBLISH_NEW_VERSION=${PUBLISH_NEW_VERSION}" >> $GITHUB_OUTPUT
determaine_current_tag_name:
runs-on: ubuntu-22.04
needs: [ build, determaine_should_publish_new_version ]
if: ${{ needs.determaine_should_publish_new_version.outputs.PUBLISH_NEW_VERSION == 'true' }}
outputs:
CURRENT_TAG: ${{ steps.find_current_tag_name.outputs.CURRENT_TAG }}
steps:
- name: Checkout local repository
uses: actions/checkout@v4
- name: Determine current tag
id: find_current_tag_name
run: |
CURRENT_TAG=$(git describe --tags --abbrev=0)
echo "CURRENT_TAG=${CURRENT_TAG}" >> $GITHUB_OUTPUT
update_changelog:
runs-on: ubuntu-22.04
needs: [ build, determaine_should_publish_new_version, determaine_current_tag_name ]
if: ${{ needs.determaine_should_publish_new_version.outputs.PUBLISH_NEW_VERSION == 'true' }}
outputs:
CHANGE_LOG_URL: ${{ steps.create_change_log_url.outputs.CHANGE_LOG_URL }}
permissions:
contents: write
steps:
- name: Checkout local repository
uses: actions/checkout@v4
with:
ref: 'main'
fetch-depth: 0
path: ${{ github.workspace }}/${{ env.SERVICE_NAME }}
- name: Install nvm at specific version
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- name: Install git-cliff and prettier using npm
run: sudo npm install --global git-cliff prettier
- name: Generate changelog
run: ./run.sh generate-changelog
working-directory: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/
- name: Commit and push updated changelog
run: |
git add .
if ! (git diff --staged --quiet --exit-code); then
git config user.name "GitHub Actions"
git commit -m 'docs: Update changelog'
git push origin main
fi
working-directory: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/
- name: Create change log url
id: create_change_log_url
run: |
echo "CHANGE_LOG_URL=$(./run.sh generate-changelog-url ${{ needs.determaine_current_tag_name.outputs.CURRENT_TAG }})" >> $GITHUB_OUTPUT
working-directory: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/
docker:
runs-on: ubuntu-22.04
needs: [ build, determaine_current_tag_name, update_changelog ]
steps:
- name: Checkout local repository
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/${{ env.SERVICE_NAME }}
- name: Install jenv
run: |
git clone https://github.com/gcuisinier/jenv.git ~/.jenv
echo "$HOME/.jenv/bin" >> $GITHUB_PATH
- name: Configure jenv
run: |
jenv init -
jenv add ${JAVA_HOME_21_X64}
- name: Install nvm at specific version
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: Cache gradle wrapper and jars
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-${{ steps.get-date.outputs.date }}-
${{ runner.os }}-gradle-
- name: Build boot jar
id: build_jar
run: ./run.sh build-jar
working-directory: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.SERVICE_NAME }}
tags: |
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: create github release
uses: ncipollo/release-action@v1
with:
artifacts: "${{ github.workspace }}/${{ env.SERVICE_NAME }}/backend/build/libs/gitactionboard.jar"
token: ${{ secrets.GITHUB_TOKEN }}
tag: "${{ needs.determaine_current_tag_name.outputs.CURRENT_TAG }}"
body: "Changelog can be found [here](${{ needs.update_changelog.outputs.CHANGE_LOG_URL }})."
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: ${{ github.workspace }}/${{ env.SERVICE_NAME }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
push: true
platforms: linux/amd64,linux/arm64
- name: Update docker hub description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.SERVICE_NAME }}
readme-filepath: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/README.md
deploy_to_github_pages:
runs-on: ubuntu-22.04
needs: [ docker ]
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout local repository
uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/${{ env.SERVICE_NAME }}
- name: Setup Pages
uses: actions/configure-pages@v5
with:
enablement: true
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: Install nvm at specific version
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
- name: Cache node modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.get-date.outputs.date }}-
${{ runner.os }}-node-
${{ runner.os }}-
- name: Build frontend
run: ./run.sh frontend-build-for-github-pages
working-directory: ${{ github.workspace }}/${{ env.SERVICE_NAME }}/
- name: Upload site artifact
uses: actions/upload-pages-artifact@v3
with:
path: "${{ github.workspace }}/${{ env.SERVICE_NAME }}/frontend/dist"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4