-
Notifications
You must be signed in to change notification settings - Fork 94
220 lines (187 loc) · 7.82 KB
/
settings_checks.yml
File metadata and controls
220 lines (187 loc) · 7.82 KB
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
name: Settings Checks
on:
pull_request:
types: [opened, reopened, synchronize]
paths:
- 'config/settings.yml'
- 'config/settings/*.yml'
permissions:
id-token: write
contents: read
checks: write
jobs:
validate-config-files:
env:
COVERBAND_DISABLE_AUTO_START: true
BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
permissions: write-all
runs-on: ubuntu-32-cores-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: ruby/setup-ruby@3ff19f5e2baf30647122352b96108b1fbe250c64 # v1
with:
bundler-cache: true
- name: Install pdftk
run: sudo apt-get update && sudo apt-get install -y pdftk-java
- name: Run Settings Validation Rake task
run: bundle exec rake settings:validate
- name: Add Settings Failure label
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['settings-failure'],
})
- name: Remove Settings Failure label
if: success() && github.event_name == 'pull_request'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: 'settings-failure',
})
} catch (e) {
if (e.status !== 404) throw e
}
check-parameters:
runs-on: ubuntu-32-cores-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7 # v6
with:
role-to-assume: ${{ vars.AWS_ASSUME_ROLE }}
aws-region: us-gov-west-1
- name: Obtain GitHub Token
uses: department-of-veterans-affairs/action-inject-ssm-secrets@d8e6de3bde4dd728c9d732baef58b3c854b8c4bb # latest
with:
ssm_parameter: /devops/VA_VSP_BOT_GITHUB_TOKEN
env_variable_name: VA_VSP_BOT_GITHUB_TOKEN
- name: Install jq
run: |
sudo apt update
sudo apt install jq -y
- name: Fetch the remote master branch
run: git fetch origin master
- name: Check ENV diff for aws_ssm_custom lookups
run: |
diff_output=$(git diff origin/master config/settings.yml)
if [[ -z "$diff_output" ]]; then
echo "No changes detected in config/settings.yml."
exit 0
fi
new_env_keys=$(git diff --unified=0 origin/master config/settings.yml | \
grep '^+' | grep -o 'ENV\[[^]]*\]' | sed 's/ENV\[\([^]]*\)\]/\1/' | sort -u)
if [[ -z "$new_env_keys" ]]; then
echo "No ENV variables found in changes."
exit 0
fi
keys=()
for line in $new_env_keys; do
# Remove any quotes that might be present
line=$(echo "$line" | tr -d "'")
keys+=("$line")
done
echo "Found the following ENV keys:"
for key in "${keys[@]}"; do
echo " - $key"
done
echo "PARAM_STORE_VARS=true" >> $GITHUB_ENV
invalid_parameters=()
for key in "${keys[@]}"; do
param_names=()
# replace double underscores with slashes
formatted_key=$(echo "$key" | sed 's/__/\//g')
echo "Processing key: $key (formatted as: $formatted_key)"
dev_ssm_param="/dsva-vagov/vets-api/dev/env_vars/$formatted_key"
staging_ssm_param="/dsva-vagov/vets-api/staging/env_vars/$formatted_key"
sandbox_ssm_param="/dsva-vagov/vets-api/sandbox/env_vars/$formatted_key"
prod_ssm_param="/dsva-vagov/vets-api/prod/env_vars/$formatted_key"
param_names+=("$dev_ssm_param")
param_names+=("$staging_ssm_param")
param_names+=("$sandbox_ssm_param")
param_names+=("$prod_ssm_param")
# Use a more resilient approach for the AWS command
set +e # Don't exit on error
ssm_output=$(aws ssm get-parameters \
--names "${param_names[@]}" \
--query "InvalidParameters" \
--output json 2>&1)
aws_exit_code=$?
set -e # Restore exit on error
if [ $aws_exit_code -ne 0 ]; then
echo "AWS SSM command failed with output: $ssm_output"
continue # Skip to next key
fi
# Process invalid parameters
if [[ -n "$ssm_output" && "$ssm_output" != "[]" && "$ssm_output" != "null" ]]; then
# Parse the JSON output to extract invalid parameters
while read -r param; do
if [[ -n "$param" ]]; then
invalid_parameters+=("$param")
fi
done < <(echo "$ssm_output" | jq -r '.[]' 2>/dev/null || echo "")
fi
done
# Display invalid parameters
echo "Invalid parameters found: ${#invalid_parameters[@]}"
if [[ ${#invalid_parameters[@]} -gt 0 ]]; then
for param in "${invalid_parameters[@]}"; do
echo " - $param"
done
invalid_params_string=$(printf -- '- %s\n' "${invalid_parameters[@]}")
{
echo "INVALID_PARAMETERS<<EOF"
echo "$invalid_params_string"
echo "EOF"
} >> "$GITHUB_ENV"
else
echo "No invalid parameters found"
echo "INVALID_PARAMETERS=" >> $GITHUB_ENV
fi
- name: Respond to PR if invalid parameters are found
if: env.INVALID_PARAMETERS != ''
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
github-token: ${{ env.VA_VSP_BOT_GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number
const invalidParameters = process.env.INVALID_PARAMETERS || ''
const body = `:warning: The following Parameter Store values are invalid. Please make sure the values are correct and exist in AWS Parameter Store before merging:\n\n${invalidParameters}`
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
})
- name: Fail if invalid parameters are found
if: env.INVALID_PARAMETERS != ''
run: exit 1
- name: Respond to PR if no invalid parameters are found
if: env.INVALID_PARAMETERS == '' && env.PARAM_STORE_VARS == 'true'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
github-token: ${{ env.VA_VSP_BOT_GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: ':+1: All Parameter Store values in this PR are valid',
})