-
Notifications
You must be signed in to change notification settings - Fork 3
228 lines (200 loc) · 7.42 KB
/
staging-deploy-action.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
name: 'Staging-Deploy'
on:
pull_request:
types:
- closed
branches: [ main ]
jobs:
update-version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.store-version.outputs.version}}
steps:
- name: Checkout project
uses: actions/checkout@v2
with:
token: ${{secrets.VERSION_TOKEN}}
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
server-id: github
settings-path: ${{github.workspace}}
- name: Generate and Set New Version
run: mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false
- name: Extract Maven project version
run: echo "version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_OUTPUT
id: store-version
- name: Set New Snapshot Version
run: mvn build-helper:parse-version versions:set -DnewVersion=${{ steps.store-version.outputs.version}}-SNAPSHOT -DgenerateBackupPoms=false
- name: Commit and Push Changes
shell: bash
env:
COMMITPREFIX: '[VU]'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add . || {
echo "No files were changed, so we did not commit anything"
exit 1
}
git commit -m "$COMMITPREFIX Automated version update" || {
echo "No changes to commit, skipping push"
exit 0
}
git push -f origin main
build-docker-image:
needs: update-version
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
token: ${{secrets.VERSION_TOKEN}}
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
server-id: github
settings-path: ${{github.workspace}}
- name: Set up node 18
uses: actions/setup-node@v3
with:
node-version: 18.17.1
- name: Install Dependencies
run: cd ./frontend && npm ci
- name: Build frontend with Angular
run: cd ./frontend && npm run build:staging
- name: Build backend with Maven
run: mvn -B clean package --file pom.xml -P staging
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build the docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
tags: ${{ vars.NEW_VALUE_URL }}:${{ needs.update-version.outputs.version}}-STAGING
load: true
push: false
outputs: type=docker,dest=/tmp/okr-docker-image.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: okr-image
path: /tmp/okr-docker-image.tar
# e2e-docker:
# runs-on: ubuntu-22.04
# needs: [build-docker-image,update-version]
# strategy:
# matrix:
# browser: [ 'chrome', "firefox" ]
# steps:
# - uses: actions/checkout@v3
# with:
# token: ${{secrets.VERSION_TOKEN}}
#
# - uses: abhi1693/[email protected]
# with:
# browser: ${{ matrix.browser }}
# version: latest
#
# - name: Download artifact
# uses: actions/download-artifact@v3
# with:
# name: okr-image
# path: /tmp
#
# - name: Load image
# run: docker load --input /tmp/okr-docker-image.tar
#
# - name: Run docker image
# run: |
# docker run --network=host \
# -p 8080:8080 \
# -e SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER-URI=https://idp-mock-okr.ocp.cloudscale.puzzle.ch/realms/pitc \
# -e SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK-SET-URI=https://idp-mock-okr.ocp.cloudscale.puzzle.ch/realms/pitc/protocol/openid-connect/certs \
# -e SPRING_SECURITY_OAUTH2_RESOURCESERVER_OPAQUETOKEN_CLIENT-ID=pitc_okr_staging \
# -e SPRING_PROFILES_ACTIVE-ID=integration-test \
# -e SPRING_DATASOURCE_URL="jdbc:h2:mem:db;DB_CLOSE_DELAY=-1" \
# -e SPRING_DATASOURCE_USERNAME=user \
# -e SPRING_DATASOURCE_PASSWORD=sa \
# -e SPRING_FLYWAY_LOCATIONS="classpath:db/h2-db/database-h2-schema,classpath:db/h2-db/data-test-h2" \
# ${{ vars.NEW_VALUE_URL }}:${{ needs.update-version.outputs.version}}-STAGING &
#
# - name: Cypress run e2e tests
# uses: cypress-io/github-action@v6
# with:
# build: npm i -D cypress
# install: false
# wait-on: 'http://localhost:8080/config'
# wait-on-timeout: 120
# browser: ${{ matrix.browser }}
# working-directory: frontend
# config: baseUrl=http://localhost:8080
upload-to-quay:
runs-on: ubuntu-latest
# as soon as e2e gets activated again job also needs e2e-docker
needs: [build-docker-image, update-version]
steps:
- uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: okr-image
path: /tmp
- name: Load image
run: docker load --input /tmp/okr-docker-image.tar
- name: show images
run: docker image ls -a
- name: Log in to Quay registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.QUAY_REGISTRY }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Push
run: docker push ${{ vars.NEW_VALUE_URL }}:${{ needs.update-version.outputs.version}}-STAGING
- name: Build and push the docker image
uses: docker/build-push-action@v3
if: failure()
with:
push: true
tags: ${{ vars.NEW_VALUE_URL }}:${{ needs.update-version.outputs.version}}-STAGING
- name: Trigger Deployment Workflow with latest Version
uses: actions/checkout@v3
with:
repository: ${{ vars.TARGET_REPOSITORY }}
ref: ${{ vars.TARGET_REFERENCE }}
path: ccy-repo
token: ${{secrets.VERSION_TOKEN}}
- name: Change Yaml
shell: bash
env:
FILEPATH: ${{ vars.FILEPATH }}
YAMLPATH: ${{ vars.YAML_PATH }}
NEWVALUE: ${{ vars.NEW_VALUE_URL }}:${{ needs.update-version.outputs.version}}-STAGING
VERSION: v4.25.2
BINARY: yq_linux_amd64
run: |
wget -q https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\
tar xz && mv ${BINARY} /usr/local/bin/yq
yq -i "${YAMLPATH} = \"${NEWVALUE}\"" ccy-repo/${FILEPATH}
- name: Commit and Push Changes
working-directory: ccy-repo
shell: bash
env:
COMMITPREFIX: '[CTS]'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add ${{ vars.FILEPATH }} || {
echo "No files were changed, so we did not commit anything"
exit 1
} && \
git commit -m "$COMMITPREFIX Automated changes to ${{ vars.FILEPATH }}" && \
git push origin ${{ vars.TARGET_REFERENCE }}
- run: rm -rf ccy-repo
shell: bash