generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 4
201 lines (185 loc) · 6.35 KB
/
pr-test.yaml
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
name: Test action
on: pull_request
env:
AWS_REGION: ca-central-1
TERRAFORM_VERSION: 1.9.8
TERRAGRUNT_VERSION: 0.68.6
TF_SUMMARIZE_VERSION: 0.3.5
permissions:
id-token: write
pull-requests: write
contents: read
jobs:
terraform-plan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- test: changes
allow-failure: false
- test: no-changes
allow-failure: false
- test: format-error
allow-failure: true
- test: invalid
allow-failure: true
- test: conftest-deny
allow-failure: true
- test: skip-conftest
allow-failure: false
skip-conftest: true
- test: skip-fmt
allow-failure: false
skip-fmt: true
- test: skip-plan
allow-failure: false
skip-plan: true
- test: truncate-plan
allow-failure: false
- test: init-fail
allow-failure: true
- test: validate-fail
allow-failure: true
- test: import
allow-failure: true
- test: terragrunt
allow-failure: false
terragrunt: true
- test: init-run-all
allow-failure: false
terragrunt: true
init-run-all: true
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup terraform tools
uses: cds-snc/terraform-tools-setup@v1
- name: Configure AWS credentials using OIDC
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: arn:aws:iam::124044056575:role/terraform-plan-plan
role-session-name: TFPlan
aws-region: ${{ env.AWS_REGION }}
- name: Test ${{ matrix.test }}
uses: ./
with:
directory: test/${{ matrix.test }}
allow-failure: ${{ matrix.allow-failure }}
comment-title: Test ${{ matrix.test }}
comment-delete: true
github-token: ${{ secrets.GITHUB_TOKEN }}
skip-conftest: ${{ matrix.skip-conftest || 'false' }}
skip-fmt: ${{ matrix.skip-fmt || 'false' }}
skip-plan: ${{ matrix.skip-plan || 'false' }}
terragrunt: ${{ matrix.terragrunt || 'false' }}
init-run-all: ${{ matrix.init-run-all || 'false'}}
test-action-comments:
needs: terraform-plan
runs-on: ubuntu-latest
steps:
- name: Test action comments
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let isFailed = false;
const testComments = [
{
exist: true,
title: /Test changes/g,
state: /`success`[^`]+`success`/g
},{
exist: true,
title: /Test format-error/g,
state: /`failed`[^`]+`success`/g
},{
exist: true,
title: /Test invalid/g,
state: /`failed`[^`]+`failed`/g
},{
exist: false,
title: /Test no-changes/g,
state: /./g
},{
exist: true,
title: /Test conftest-deny/g,
state: /FAIL/g
},{
exist: false,
title: /Test skip-conftest/g,
state: /Conftest:\*\*/gm
},{
exist: true,
title: /Test skip-fmt/g,
state: /Terraform Validate:\*\* `success`\n\*\*✅ Terraform Plan/gm
},{
exist: true,
title: /Test skip-plan/g,
state: /Terraform Format:\*\* `success`\n/gm
},{
exist: true,
title: /Test truncate-plan/g,
state: /plan has been truncated/gm
},{
exist: true,
title: /Test init-fail/g,
state: /Terraform Init:\*\* `failed`\n/gm
},{
exist: true,
title: /Test validate-fail/g,
state: /Terraform Validate:\*\* `failed`\n/gm
},{
exist: true,
title: /Test import/g,
state: /`success`[^`]+`success`/g
},
{
exist: true,
title: /Test terragrunt/g,
state: /`success`[^`]+`success`/g
},
{
exist: true,
title: /Test init-run-all/g,
state: /`success`[^`]+`success`/g
}
];
// Get the existing comments.
const {data: comments} = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
});
// Run through the tests
let botComment;
for(let test of testComments){
botComment = comments.find(comment => comment.body.match(test.title) && comment.body.match(test.state));
if((botComment && !test.exist) || (!botComment && test.exist)){
console.log(`Failed '${test.title}'`);
isFailed = true;
}
}
if(isFailed){
core.setFailed('PR comments did not match');
}
test-directory-failure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup terraform tools
uses: cds-snc/terraform-tools-setup@v1
- name: Test directory failure
id: directory-failure
continue-on-error: true
uses: ./
with:
directory: invalid
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check directory failure
if: steps.directory-failure.outcome == 'failure'
run: |
echo "Directory failure test passed"
- name: Test failed
if: steps.directory-failure.outcome == 'success' && steps.directory-failure.conclusion == 'success'
run: |
exit 1