-
Notifications
You must be signed in to change notification settings - Fork 28
220 lines (199 loc) · 8.92 KB
/
main.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
name: CI
on:
push:
pull_request:
schedule:
# launch a build every day on develop
- cron: '0 22 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
build:
description: 'Build'
required: false
default: 'true'
karate:
description: 'Karate tests'
required: false
default: 'true'
cypress:
description: 'Cypress Tests'
required: false
default: 'true'
cypressTestFiles:
description: 'Cypress Test files'
required: false
default: '*'
gatling:
description: 'Load tests'
required: false
default: 'false'
doc:
description: 'Build and publish documentation '
required: false
default: 'false'
docLatest:
description: 'Build and publish documentation - Latest'
required: false
default: 'false'
dockerPush:
description: 'Docker push'
required: false
default: 'false'
dockerPushLatest:
description: 'Docker push - Latest'
required: false
default: 'false'
permissions: read-all
jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.dockerPush != 'true' && github.event.inputs.dockerPushLatest != 'true' && github.event.inputs.doc != 'true' && github.event.inputs.docLatest != 'true' && github.event_name != 'schedule' }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Job status
env:
EVENT_NAME: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
HEAD_REF: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
run: |
echo "----------------------------"
echo "Trigger by : $EVENT_NAME"
echo "On branch : $REF_NAME "
echo "PR source branch : $HEAD_REF "
echo "PR target branch : $BASE_REF "
echo "---------------------------"
- name: Cache Gradle packages
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties','**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
# Install all required tools
- name: Install
run: ./CICD/github/install.sh
- name: Build
if: ${{ github.event.inputs.build == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push'}}
# build.sh set variable for sdk, nvm and gradle
# if variable is set in install step it is not accessible in this step
run: ./CICD/github/build.sh
env:
# SonarCloud access token should be generated from https://sonarcloud.io/account/security/
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Karate tests
if: ${{ github.event.inputs.karate == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' }}
run: ./CICD/github/launch_karate_tests.sh
- name: Cypress tests
if: ${{ github.event.inputs.cypress == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' }}
run: ./CICD/github/launch_cypress_tests.sh ${{ github.event.inputs.cypressTestFiles }}
- name: Upload cypress screenshots and logs
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
if: failure()
with:
name: cypress-screenshots
path: |
src/test/cypress/cypress/screenshots
opfab.log
- name: Load tests
if: ${{ github.event.inputs.gatling == 'true' || github.event_name == 'schedule' }}
run: ./CICD/github/launch_load_tests.sh
publish:
runs-on: ubuntu-latest
environment: publishVersion
permissions:
contents: write
if: ${{ github.event.inputs.dockerPush == 'true' || github.event.inputs.dockerPushLatest == 'true' || github.event.inputs.doc == 'true' || github.event.inputs.docLatest == 'true' || github.event_name == 'schedule' }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Job status
env:
EVENT_NAME: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
HEAD_REF: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
run: |
echo "----------------------------"
echo "Trigger by : $EVENT_NAME"
echo "On branch : $REF_NAME "
echo "PR source branch : $HEAD_REF "
echo "PR target branch : $BASE_REF "
echo "---------------------------"
- name: Cache Gradle packages
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties','**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
# Install all required tools
- name: Install
run: ./CICD/github/install.sh
- name: Build
if: ${{ github.event.inputs.build == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push'}}
# set variable in this step (sdk, nvm et gradle)
# if variable is set in install step it is not accessible in this step
run: ./CICD/github/build.sh
env:
# SonarCloud access token should be generated from https://sonarcloud.io/account/security/
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Karate tests
if: ${{ github.event.inputs.karate == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' }}
run: ./CICD/github/launch_karate_tests.sh
- name: Cypress tests
if: ${{ github.event.inputs.cypress == 'true' || github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' }}
run: ./CICD/github/launch_cypress_tests.sh
- name: Upload cypress screenshots
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
if: failure()
with:
name: cypress-screenshots
path: src/test/cypress/cypress/screenshots
- name: Load tests
if: ${{ github.event.inputs.gatling == 'true' || github.event_name == 'schedule' }}
run: ./CICD/github/launch_load_tests.sh
- name : Publish Documentation
if : ${{ github.event.inputs.doc == 'true' || github.event_name == 'schedule'}}
run: |
source $HOME/.sdkman/bin/sdkman-init.sh;
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
source ./bin/load_environment_light.sh;
./gradlew --build-cache generateSwaggerUI asciidoctor;
./CICD/github/upload_doc.sh
env:
GH_DOC_TOKEN: ${{ secrets.GH_DOC_TOKEN}}
- name : Publish Documentation (latest)
if : ${{ github.event.inputs.docLatest == 'true' }}
run: |
source $HOME/.sdkman/bin/sdkman-init.sh;
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
source ./bin/load_environment_light.sh;
./gradlew --build-cache generateSwaggerUI asciidoctor;
./CICD/github/upload_doc.sh --updateLatest true
env:
GH_DOC_TOKEN: ${{ secrets.GH_DOC_TOKEN}}
- name : Push images to dockerhub
if: ${{ github.event.inputs.dockerPush == 'true' || github.event_name == 'schedule' }}
run: |
echo ${{ secrets.DOCKER_TOKEN }} | docker login --username opfabtravis --password-stdin
docker images --format "{{.Repository}}:{{.Tag}}" | grep lfe | while read image; do
echo push ${image}
docker push ${image}
done
- name : Push images latest to dockerhub
if: ${{ github.event.inputs.dockerPushLatest == 'true' }}
run: |
echo ${{ secrets.DOCKER_TOKEN }} | docker login --username opfabtravis --password-stdin
docker images --format "{{.Repository}}:{{.Tag}}" | grep lfe | while read image; do
export repository=$(echo ${image} | cut -d ":" -f 1)
echo "create tag latest for ${repository}"
docker tag ${image} ${repository}:latest
docker push ${repository}:latest
done