-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (175 loc) · 7.44 KB
/
pr-checks.yml
File metadata and controls
208 lines (175 loc) · 7.44 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
name: Pull Request Checks
on:
pull_request:
branches: [main, live]
env:
VITE_API_URL: https://test-api.example.com
VITE_PORTAL_URL: https://test-portal.example.com
VITE_PORTAL_CASE_URL: https://test-portal.example.com/cases
jobs:
backend-tests:
name: Backend Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./serverless
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: './serverless/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Run backend tests
run: npm test -- --testPathIgnorePatterns=__integration_tests__
frontend-tests:
name: Frontend Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: './frontend/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Run frontend tests
run: npm test
- name: Lint frontend
run: npm run lint
- name: Check TypeScript build
run: npx tsc -b
- name: Test production build
run: npm run build
terraform-plan-dev:
name: Terraform Plan (Dev)
if: github.base_ref == 'main'
runs-on: ubuntu-latest
environment: dev
defaults:
run:
working-directory: ./infra/terraform
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: '1.11.4'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Terraform Init
working-directory: ./infra/terraform/dev
run: terraform init
- name: Set Terraform environment variables
run: |
echo "TF_VAR_alert_email=${{ vars.ALERT_EMAIL }}" >> $GITHUB_ENV
- name: Terraform Plan
working-directory: ./infra/terraform/dev
run: |
terraform plan -no-color > plan_full.txt || { exit_code=$?; cat plan_full.txt; echo "plan<<EOF" >> $GITHUB_OUTPUT; cat plan_full.txt >> $GITHUB_OUTPUT; echo "EOF" >> $GITHUB_OUTPUT; echo "has_changes=true" >> $GITHUB_OUTPUT; exit $exit_code; }
cat plan_full.txt
# Check if there are any changes planned
if grep -q "No changes" plan_full.txt; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
# Extract only the meaningful plan output (skipping "Refreshing state..." lines)
grep -v "Refreshing state" plan_full.txt > plan_changes.txt
echo "plan<<EOF" >> $GITHUB_OUTPUT
cat plan_changes.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
id: plan-dev
- name: Add Dev Plan Comment
if: steps.plan-dev.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Dev Plan 🧪
\`\`\`terraform
${{ steps.plan-dev.outputs.plan || 'No output available' }}
\`\`\`
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
terraform-plan-prod:
name: Terraform Plan (Prod)
if: github.base_ref == 'live'
runs-on: ubuntu-latest
environment: prod
defaults:
run:
working-directory: ./infra/terraform
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: '1.11.4'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Terraform Init
working-directory: ./infra/terraform/prod
run: terraform init
- name: Set Terraform environment variables
run: |
echo "TF_VAR_alert_email=${{ vars.ALERT_EMAIL }}" >> $GITHUB_ENV
- name: Terraform Plan
working-directory: ./infra/terraform/prod
run: |
terraform plan -no-color > plan_full.txt || { exit_code=$?; cat plan_full.txt; echo "plan<<EOF" >> $GITHUB_OUTPUT; cat plan_full.txt >> $GITHUB_OUTPUT; echo "EOF" >> $GITHUB_OUTPUT; echo "has_changes=true" >> $GITHUB_OUTPUT; exit $exit_code; }
cat plan_full.txt
# Check if there are any changes planned
if grep -q "No changes" plan_full.txt; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
# Extract only the meaningful plan output (skipping "Refreshing state..." lines)
grep -v "Refreshing state" plan_full.txt > plan_changes.txt
echo "plan<<EOF" >> $GITHUB_OUTPUT
cat plan_changes.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
id: plan-prod
- name: Add Prod Plan Comment
if: steps.plan-prod.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Prod Plan 🧪
\`\`\`terraform
${{ steps.plan-prod.outputs.plan || 'No output available' }}
\`\`\`
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})