-
Notifications
You must be signed in to change notification settings - Fork 0
559 lines (456 loc) · 18.7 KB
/
push.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
---
name: mac_maker-push
# Workflow Secrets:
# SLACK_WEBHOOK (Required, for slack notifications...)
on:
push:
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
env:
PROJECT_NAME: "mac_maker"
USERNAME: "osx-provisioner"
VERBOSE_NOTIFICATIONS: 0
jobs:
_start_notification:
runs-on: ubuntu-latest
steps:
- name: Start -- Checkout Repository
uses: actions/checkout@v3
- name: Start -- Setup Environment
run: |
source ./.github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Start -- Report Job Status on Success
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: workflow has started!"
- name: Start -- Report Job Status on Failure
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: error reporting job status!"
_success_notification:
needs: [attach_release_binaries]
runs-on: ubuntu-latest
steps:
- name: Success -- Checkout Repository
uses: actions/checkout@v3
- name: Success -- Setup Environment
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Success -- Report Job Status on Success
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: all checks were successful!"
- name: Success -- Report Job Status on Failure
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: error reporting job status!"
apply:
needs: [container_build, osx_build]
# Only on tags, main and production branches.
runs-on: macos-${{ matrix.os }}
strategy:
max-parallel: 4
matrix:
os: [12, 13]
platform: [x86_64]
python-version: [3.11.8]
steps:
- name: Apply Test -- Branch Filter
id: branch_filter
run: |
MATCH="FALSE"
[[ "${{ github.event.ref }}" =~ /tags/v\.* ]] && MATCH="TRUE"
[[ "${{ github.event.ref }}" == "refs/heads/main" ]] && MATCH="TRUE"
[[ "${{ github.event.ref }}" == "refs/heads/production" ]] && MATCH="TRUE"
echo "MATCH=${MATCH}" >> $GITHUB_OUTPUT
- name: Apply Test -- Checkout
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/checkout@v3
- name: Apply Test -- Setup Environment
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
PYTHON_VERSION: ${{ matrix.python-version }}
- name: Apply Test -- Download Built Binary
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/download-artifact@v3
with:
name: built_binary_${{ matrix.os }}_${{ matrix.platform }}_${{ env.BRANCH_OR_TAG }}
- name: Apply Test -- Clear Quarantine Attribute
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
tar xvzf mac_maker_${{ matrix.os }}_${{ matrix.platform }}_${BRANCH_OR_TAG}.tar.gz
xattr -d -r com.apple.quarantine mac_maker_${{ matrix.os }}_${{ matrix.platform }}_${BRANCH_OR_TAG}
- name: Apply Test -- Apply a Profile
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
cd mac_maker_${{ matrix.os }}_${{ matrix.platform }}_${BRANCH_OR_TAG}
export ANSIBLE_BECOME_PASSWORD="skip the prompt"
./mac_maker apply github https://github.com/osx-provisioner/profile-example.git
- name: Apply Test -- Report Job Status (Success)
if: steps.branch_filter.outputs.match == 'TRUE' && env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: ${{ matrix.os }} profile application using built binary (${{ matrix.os }} ${{ matrix.platform }}) was successful"
- name: Apply Test -- Report Job Status (Failure)
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: ${{ matrix.os }} profile application using built binary (${{ matrix.os }} ${{ matrix.platform }}) failed!"
attach_release_binaries:
needs: [create_release]
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
os: [12, 13]
platform: [x86_64]
python-version: [3.11.8]
steps:
- name: Attach Release Binaries -- Branch Filter
id: branch_filter
run: |
MATCH="FALSE"
[[ "${{ github.event.ref }}" =~ /tags/v\.* ]] && MATCH="TRUE"
echo "MATCH=${MATCH}" >> $GITHUB_OUTPUT
- name: Attach Release Binaries -- Checkout
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Attach Release Binaries -- Setup Environment
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
PYTHON_VERSION: ${{ matrix.python-version }}
- name: Attach Release Binaries -- Download Built Binary
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/download-artifact@v3
with:
name: built_binary_${{ matrix.os }}_${{ matrix.platform }}_${{ env.BRANCH_OR_TAG }}
- name: Attach Release Binaries -- Identify Binary
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
ls -la
BINARY_NAME=$(ls *.tar.gz)
echo "BINARY_NAME=${BINARY_NAME}" >> $GITHUB_ENV
- name: Attach Release Binaries -- Upload Release Asset
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source ./.github/scripts/upload_asset.sh
env:
FILE_PATH: ${{ env.BINARY_NAME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ needs.create_release.outputs.upload_url }}
- name: Attach Release Binaries -- Report Success
if: steps.branch_filter.outputs.match == 'TRUE' && env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: compiled binary has been attached to release: ${BINARY_NAME}"
- name: Attach Release Binaries -- Report Failure
if: failure() && contains(github.ref, '/tags/v')
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: compiled binaries could not be attached to release!"
container_build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
include:
- python-version: 3.11
steps:
- name: Container Build -- Checkout
uses: actions/checkout@v3
- name: Container Build -- Setup Environment
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
PYTHON_VERSION: ${{ matrix.python-version }}
- name: Container Build -- Create Docker Mounted Content
run: |
echo | ssh-keygen
touch ${HOME}/.gitconfig
touch ${HOME}/.gitconfig_global
- name: Container Build -- Build Container
run: |
source .github/scripts/build_container.sh
- name: Container Build -- Ensure GIT is working
run: |
docker compose exec -T "${PROJECT_NAME}" git status
- name: Container Build -- Run TOML Linter
run: |
docker compose exec -T "${PROJECT_NAME}" tomll /app/pyproject.toml
- name: Container Build -- Run Documentation Build
run: |
docker compose exec -T "${PROJECT_NAME}" dev build-docs
- name: Container Build -- Run Linter
run: |
docker compose exec -T "${PROJECT_NAME}" dev lint
- name: Container Build -- Run Sec Test
run: |
docker compose exec -T "${PROJECT_NAME}" dev sectest
- name: Container Build -- Run Unit Tests
run: |
docker compose exec -T "${PROJECT_NAME}" dev coverage
- name: Container Build -- Run MyPy
run: |
docker compose exec -T "${PROJECT_NAME}" dev types
- name: Container Build -- Run Release Validation
run: |
docker compose exec -T "${PROJECT_NAME}" ./scripts/release.sh
- name: Container Build -- Report Job Status (Success)
if: env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: container build for Python ${PYTHON_VERSION} was successful"
- name: Container Build -- Report Job Status (Failure)
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: container build for Python ${PYTHON_VERSION} failed!"
create_release:
needs: [_start_notification, apply, container_build, documentation_test, security_test, shellcheck_test, workflow_lint_test]
runs-on: ubuntu-latest
outputs:
upload_url: ${{ fromJSON(steps.create_release.outputs.result).data.upload_url }}
steps:
- name: Create Release -- Branch Filter
id: branch_filter
run: |
MATCH="FALSE"
[[ "${{ github.event.ref }}" =~ /tags/v\.* ]] && MATCH="TRUE"
echo "MATCH=${MATCH}" >> $GITHUB_OUTPUT
- name: Create Release -- Checkout
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create Release -- Setup Environment
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Create Release -- Prepare Content
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
echo "{}" > package.json
- name: Create Release -- Generate Changelog
if: steps.branch_filter.outputs.match == 'TRUE'
run:
source ./.github/scripts/changelog.sh
- name: Create Release -- Generate Github Release Draft
id: create_release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
if (process.env.RELEASE_BRANCH !== 'TRUE') {
return { data: { upload_url: null }}
}
const result = await github.rest.repos.createRelease({
body: process.env.CHANGE_LOG_CONTENT,
draft: true,
name: "Release " + process.env.BRANCH_OR_TAG,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.BRANCH_OR_TAG,
});
return result
} catch (error) {
core.setFailed(error.message);
}
env:
RELEASE_BRANCH: ${{ steps.branch_filter.outputs.match }}
- name: Create Release -- Report Success
if: steps.branch_filter.outputs.match == 'TRUE' && env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: automated release has been created:\nhttps://github.com/${USERNAME}/${PROJECT_NAME}/releases"
- name: Create Release -- Report Failure
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: automated release generation failed!"
documentation_test:
runs-on: ubuntu-latest
steps:
- name: Documentation Test -- Checkout Repository
uses: actions/checkout@v3
- name: Documentation Test -- Setup Environment
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Documentation Test -- Documentation Validation
uses: gaurav-nelson/[email protected]
with:
config-file: '.github/config/actions/gaurav-nelson-github-action-markdown-link-check.json'
use-quiet-mode: 'no'
use-verbose-mode: 'yes'
- name: Documentation Test -- Report Success
if: env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: documentation checks were successful!"
- name: Documentation Test -- Report Failure
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: documentation checks failed!"
security_test:
runs-on: ubuntu-latest
steps:
- name: Security Test -- Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Security Test -- Setup Environment
run: |
source .github/scripts/setup.sh
source .github/scripts/pushed_commit_range.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Security Test -- Run Trufflehog
uses: trufflesecurity/[email protected]
with:
path: .
base: ${{ env.PUSHED_COMMIT_RANGE }}
head: ${{ env.BRANCH_OR_TAG }}
extra_args: --only-verified
- name: Security Test -- Report Success
if: env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: security checks were successful!"
- name: Security Test -- Report Failure
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: security checks failed!"
shellcheck_test:
runs-on: ubuntu-latest
steps:
- name: Shellcheck -- Checkout Repository
uses: actions/checkout@v3
- name: Shellcheck -- Setup Environment
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Shellcheck -- Check Scripts
run: |
source .github/scripts/shellcheck.sh
- name: Shellcheck -- Report Job Status on Success
if: env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: shellcheck checks were successful!"
- name: Shellcheck -- Report Job Status on Failure
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: shellcheck checks failed!"
workflow_lint_test:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.11]
steps:
- name: Workflow Lint -- Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Workflow Lint -- Checkout Repository
uses: actions/checkout@v3
- name: Workflow Lint -- Setup Environment
run: |
source ./.github/scripts/setup.sh
pip install yamllint
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Workflow Lint -- Run Linter
run: |
yamllint ./.github/workflows -c .yamllint.yml -f standard
- name: Workflow Lint -- Report Job Status on Success
if: env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: workflow linting was successful!"
- name: Workflow Lint -- Report Job Status on Failure
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: workflow linting has failed!"
osx_build:
# Only on tags, main and production branches.
runs-on: macos-${{ matrix.os }}
strategy:
max-parallel: 4
matrix:
os: [12, 13]
platform: [x86_64]
python-version: [3.11.8]
steps:
- name: OSX Build -- Branch Filter
id: branch_filter
run: |
MATCH="FALSE"
[[ "${{ github.event.ref }}" =~ /tags/v\.* ]] && MATCH="TRUE"
[[ "${{ github.event.ref }}" == "refs/heads/main" ]] && MATCH="TRUE"
[[ "${{ github.event.ref }}" == "refs/heads/production" ]] && MATCH="TRUE"
echo "MATCH=${MATCH}" >> $GITHUB_OUTPUT
- name: OSX Build -- Checkout
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/checkout@v3
- name: OSX Build -- Setup Environment
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
source .github/scripts/setup.sh
env:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
PYTHON_VERSION: ${{ matrix.python-version }}
- name: OSX Build -- Setup Python ${{ matrix.python-version }}
if: steps.branch_filter.outputs.match == 'TRUE'
run: |
./scripts/build.sh pyenv "${PYTHON_VERSION}"
env:
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
- name: OSX Build -- Setup Build Environment
if: steps.branch_filter.outputs.match == 'TRUE'
shell: bash -l {0}
run: |
eval $(~/.pyenv/bin/pyenv init --path)
pip install poetry wheel
env:
PYENV_VERSION: ${{ matrix.python-version }}
- name: OSX Build -- Build Mac Maker Binary
if: steps.branch_filter.outputs.match == 'TRUE'
shell: bash -l {0}
run: |
eval $(~/.pyenv/bin/pyenv init --path)
./scripts/build.sh binary "${OS_VERSION}" "${BRANCH_OR_TAG}"
env:
PYENV_VERSION: ${{ matrix.python-version }}
OS_VERSION: ${{ matrix.os }}
PLATFORM: ${{ matrix.platform }}
- name: OSX Build -- Test the version command
if: steps.branch_filter.outputs.match == 'TRUE'
shell: bash -l {0}
run: |
./dist/mac_maker version
env:
PYENV_VERSION: ${{ matrix.python-version }}
- name: OSX Build -- Upload Build Artifact
if: steps.branch_filter.outputs.match == 'TRUE'
uses: actions/upload-artifact@v3
with:
name: built_binary_${{ matrix.os }}_${{ matrix.platform }}_${{ env.BRANCH_OR_TAG }}
path: ./dist/mac_maker_${{ matrix.os }}_${{ matrix.platform }}_${{ env.BRANCH_OR_TAG }}.tar.gz
retention-days: 1
if-no-files-found: error
- name: OSX Build -- Report Job Status (Success)
if: steps.branch_filter.outputs.match == 'TRUE' && env.VERBOSE_NOTIFICATIONS == '1'
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":white_check_mark: ${{ matrix.os }} binary build for Python ${PYTHON_VERSION} was successful"
- name: OSX Build -- Report Job Status (Failure)
if: failure()
run: |
./.github/scripts/notifications.sh "${NOTIFICATION}" ":x: ${{ matrix.os }} binary build for Python ${PYTHON_VERSION} failed!"