-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (141 loc) · 5.07 KB
/
settings-1-update.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
name: Config Settings Update
on:
push:
# Below condition is enforced by the `if` condition in
# the `setup-settings-update` job:
# branches:
# - $default_branch
paths:
- config/settings.*
pull_request:
paths:
- config/settings.*
env:
CONFIG_SETTINGS_PATH: ./config/settings.json
CONFIG_SETTINGS_SCHEMA_PATH: ./config/settings.schema.json
jobs:
setup-settings-validation:
name: Setup Validate Deployment Settings
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.target.outputs.matrix }}
steps:
- name: Get deployment settings.json
uses: actions/checkout@v4
with:
repository: access-nri/build-cd
- name: Generate Deployment Target Matrix
id: target
run: |
targets=$(jq --compact-output '.deployment | keys' config/settings.json)
echo "$targets"
echo "targets=$targets" >> $GITHUB_OUTPUT
settings-validation:
name: Validate Deployment Settings
needs:
- setup-settings-validation
strategy:
matrix:
target: ${{ fromJson(needs.setup-settings-validation.outputs.targets) }}
runs-on: ubuntu-latest
steps:
- name: Checkout settings.json
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ vars.PYTHON_VERSION }}
- name: Validate settings.json against Schema
run: jsonschema --instance ${{ env.CONFIG_SETTINGS_PATH }} ${{ env.CONFIG_SETTINGS_SCHEMA_PATH }}
- name: Validate Deployment Settings
id: validate
uses: access-nri/build-cd/.github/actions/validate-deployment-settings@v4
with:
settings-path: ${{ env.CONFIG_SETTINGS_PATH }}
target: ${{ matrix.target }}
- name: Comment Validation Issues
if: steps.validate.outputs.failures != '' && github.event_name == 'pull_request'
uses: access-nri/actions/.github/actions/pr-comment@main
with:
comment: |
:warning: `${{ env.CONFIG_SETTINGS_PATH }}`: Inconsistencies detected with the `${{ matrix.target }}` configuration. See below. :warning:
${{ steps.validate.outputs.failures }}
setup-settings-update:
name: Setup Update of Deployment Settings
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
needs:
- settings-validation
runs-on: ubuntu-latest
outputs:
updates: ${{ steps.info.outputs.updates }}
steps:
- uses: actions/checkout@v4
- name: Collect Deployment Information
id: info
# Essentially, we are getting the config/settings.json into a form
# that can be understood by the later matrix job.
# A matrix job will need something of the form (but in yaml):
# {
# "deployment-environment": "Gadi",
# "type": "Release"
# }
# TODO: Add back in the ...spack json object as an input to the next job
run: |
update=$(jq --raw-output --compact-output \
'[.deployment | to_entries[] | .key as $d | .value | keys[] | {
"deployment-environment": $d,
"type": .
}]' ${{ env.CONFIG_SETTINGS_PATH }}
)
echo "updates=$update" >> $GITHUB_OUTPUT
settings-link-run:
name: Link Workflow Run To PR
if: github.event_name == 'push'
needs:
- setup-settings-update
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4
- name: Get merged PR number
id: pr
# Get the most-recently merged PR and comment the workflow run link
run: |
last_merged_pr_number=$(gh pr list \
--state merged \
--json 'number,mergedAt' \
--jq 'sort_by(.mergedAt) | last | .number'
)
gh pr view $last_merged_pr_number
echo "number=$last_merged_pr_number" >> $GITHUB_OUTPUT
- name: Comment on PR ${{ steps.pr.outputs.number }}
env:
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
uses: access-nri/actions/.github/actions/pr-comment@main
with:
pr: ${{ steps.pr.outputs.number }}
comment: |-
:information_source: The deployment of the merged settings update can be found here: ${{ env.RUN_URL }} :information_source:
settings-update:
name: Update
if: github.event_name == 'push'
needs:
- setup-settings-update
strategy:
fail-fast: false
matrix:
update: ${{ fromJson(needs.setup-settings-update.outputs.updates) }}
# Example of this matrix:
# update:
# - deployment-environment: Gadi
# type: Release
# - deployment-environment: Gadi
# type: Prerelease
# etc ...
uses: access-nri/build-cd/.github/workflows/settings-2-deploy.yml@v4
with:
deployment-environment: ${{ matrix.update.deployment-environment }}
spack-type: ${{ matrix.update.type }}
secrets: inherit