-
Notifications
You must be signed in to change notification settings - Fork 9
294 lines (262 loc) · 8.97 KB
/
on_pr_master.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
name: CI-CD
on:
pull_request:
branches: [ master ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]
schedule:
- cron: '30 5 * * *' #Daily at 05:30
#- cron: '*/15 * * * *' #At every 15th minute.
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
docker-auth:
runs-on: ubuntu-latest
steps:
- uses: actions/upload-artifact@v2
with:
name: docker-auth
path: ~/.docker/config.json
changes:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
# Set job outputs to values from filter step
outputs:
doc: ${{ steps.filter.outputs.doc }}
not-doc: ${{ steps.filter.outputs.not-doc }}
steps:
- uses: dorny/paths-filter@v2.2.1
id: filter
with:
filters: |
doc:
- '**/*.md'
not-doc:
- '**/!(*.md)'
linter:
runs-on: ubuntu-latest
if: github.event.action != 'closed'
steps:
- uses: actions/checkout@v2
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
- name: Super-Linter
uses: github/super-linter@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_TERRAGRUNT: false
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'pull_request' && 'false' || 'true' }}
enforce-changelog:
runs-on: ubuntu-latest
if: github.event.action != 'closed' && github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v2
- uses: dangoslen/changelog-enforcer@v2.3.1
with:
changeLogPath: 'CHANGELOG.md'
skipLabels: 'ci/skip-changelog'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
needs: changes
runs-on: macos-latest # Macos includes virtualbox and vagrant.
if: |
always() &&
(
( github.event.action == 'closed' &&
github.event.pull_request.merged == true
)
&& (
contains( github.event.pull_request.labels.*.name, 'change/major') ||
contains( github.event.pull_request.labels.*.name, 'change/minor') ||
contains( github.event.pull_request.labels.*.name, 'change/patch')
)
|| (
github.event.action != 'closed' &&
needs.changes.outputs.not-doc == 'true'
)
|| (
github.event_name == 'schedule'
)
)
steps:
- uses: actions/checkout@v2
- name: Versions on runner
run: make -C install versions
- name: Run make build
run: make build
- name: Make box available as artifact
uses: actions/upload-artifact@v2
with:
name: vagrantbox
path: packer/output-hashistack/package.box
test:
if: >-
(
github.event.action != 'closed'
&& github.event.pull_request.merged != true
) || (
github.event_name == 'schedule'
)
needs:
- build
- docker-auth
runs-on: macos-latest
strategy:
matrix:
consul_acl: ["consul_acl_enabled", "consul_acl_disabled"]
consul_acl_default_policy: ["consul_acl_deny"]
nomad_acl: ["nomad_acl_enabled", "nomad_acl_disabled"]
hashicorp_binary: ["hashicorp_oss", "hashicorp_enterprise"]
master_token: ["master_token_random"]
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: set consul acl (enabled/disabled)
id: consul_acl
run: |
declare test_consul_acl
if [ "$test_consul_acl" == 'consul_acl_enabled' ]
then
echo "ENVKEY_consul_acl=true" >> "$GITHUB_ENV"
else
echo "ENVKEY_consul_acl=false" >> "$GITHUB_ENV"
fi
env:
test_consul_acl: ${{ matrix.consul_acl }}
- name: set consul acl default policy (allow/deny)
id: consul_acl_default_policy
run: |
declare test_consul_acl_default_policy
if [ "$test_consul_acl_default_policy" == 'consul_acl_allow' ]
then
echo "ENVKEY_consul_acl_default_policy=allow" >> "$GITHUB_ENV"
else
echo "ENVKEY_consul_acl_default_policy=deny" >> "$GITHUB_ENV"
fi
env:
test_consul_acl_default_policy: ${{ matrix.consul_acl_default_policy }}
- name: set nomad acl (enabled/disabled)
id: nomad_acl
run: |
declare test_nomad_acl
if [ "$test_nomad_acl" == 'nomad_acl_enabled' ]
then
echo "ENVKEY_nomad_acl=true" >> "$GITHUB_ENV"
else
echo "ENVKEY_nomad_acl=false" >> "$GITHUB_ENV"
fi
env:
test_nomad_acl: ${{ matrix.nomad_acl }}
- name: set hashicorp binary (oss/enterprise)
id: hashicorp_binary
run: |
declare test_hashicorp_binary
if [ "$test_hashicorp_binary" == 'hashicorp_oss' ]
then
printf "ENVKEY_consul_enterprise=false\nENVKEY_nomad_enterprise=false\nENVKEY_vault_enterprise=false\n" >> "$GITHUB_ENV"
else
printf "ENVKEY_consul_enterprise=true\nENVKEY_nomad_enterprise=true\nENVKEY_vault_enterprise=true\n" >> "$GITHUB_ENV"
fi
env:
test_hashicorp_binary: ${{ matrix.hashicorp_binary }}
- name: set master token (random)
id: master_token
run: |
printf "ENVKEY_nomad_master_token=random\nENVKEY_consul_master_token=random\nENVKEY_vault_master_token=random\n" >> "$GITHUB_ENV"
env:
test_master_token: ${{ matrix.master_token }}
- name: Make .env_override in order to matrix test
run: python .github/action/create-env.py
env:
ENVKEY_env_override: true
FILE_NAME: template/template_example/.env_override
- uses: actions/download-artifact@v2
with:
name: vagrantbox
path: packer/output-hashistack
- uses: actions/download-artifact@v2
with:
name: docker-auth
path: template/template_example/docker/conf/config.json
- name: Run make test
run: make test
release-prerequisites:
if: always() && github.event_name == 'pull_request'
needs:
- enforce-changelog
- linter
runs-on: ubuntu-latest
outputs:
bump: ${{ steps.bump.outputs.match }}
next_version: ${{ steps.next_version.outputs.version }}
log_entry: ${{ steps.changelog_reader.outputs.changes }}
steps:
- uses: actions/checkout@v2
- name: Require PR label (major/minor/patch)
id: bump
uses: zwaldowski/match-label-action@v2
with:
allowed: change/major,change/minor,change/patch
- uses: rishabhgupta/split-by@v1
id: split
with:
string: ${{ steps.bump.outputs.match }}
split-by: '/'
- id: next_version
uses: zwaldowski/semver-release-action@v2
with:
dry_run: true
bump: ${{ steps.split.outputs._1 }}
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Find and replace
run: python .github/action/find-replace.py
env:
FIND: "'"
REPLACE: "'\\''"
FILE_TO_MODIFY: CHANGELOG.md
- name: Get Changelog Entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v2.0.0
with:
version: ${{ steps.next_version.outputs.version }}
path: ./CHANGELOG.md
release:
if: >-
always()
&& github.event.action == 'closed'
&& github.event.pull_request.merged == true
&& contains( github.event.pull_request.labels.*.name , 'ci/release')
needs:
- release-prerequisites
- build
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Get vagrantbox artifact
uses: actions/download-artifact@v2
with:
name: vagrantbox
path: packer/output-hashistack
- name: Authenticate to vagrant cloud
run: vagrant cloud auth login --token ${{ secrets.VAGRANT_CLOUD_TOKEN }}
- name: Upload and release vagrantbox on vagrant cloud
uses: nick-invision/retry@v1
with:
timeout_minutes: 10
max_attempts: 3
command: vagrant cloud publish --release --force Skatteetaten/hashistack ${{ needs.release-prerequisites.outputs.next_version }} virtualbox packer/output-hashistack/package.box --version-description ' ${{ needs.release-prerequisites.outputs.log_entry }}'
- name: Create Release on github
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.release-prerequisites.outputs.next_version }}
release_name: Release v${{ needs.release-prerequisites.outputs.next_version }}
body: |
${{ needs.release-prerequisites.outputs.log_entry }}
draft: false
prerelease: false