generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 4
159 lines (146 loc) · 5.14 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
name: Test action
on: pull_request
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-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
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup terraform tools
uses: cds-snc/terraform-tools-setup@v1
- name: Install TF-Summarize
run: |
curl -L -o tf-summarize.zip https://github.com/dineshba/tf-summarize/releases/download/v0.2.3/tf-summarize_linux_amd64.zip \
&& unzip tf-summarize.zip tf-summarize \
&& chmod +x tf-summarize \
&& mv tf-summarize /usr/local/bin
- name: Test ${{ matrix.test }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
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-plan: ${{ matrix.skip-plan || 'false' }}
test-action-comments:
needs: terraform-plan
runs-on: ubuntu-latest
steps:
- name: Test action comments
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.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-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
}
];
// 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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- 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