forked from linode/terraform-provider-linode
-
Notifications
You must be signed in to change notification settings - Fork 0
243 lines (213 loc) · 9.03 KB
/
integration_tests.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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: Integration Tests
on:
workflow_dispatch: null
push:
branches:
- main
- dev
jobs:
integration_tests:
name: Run integration tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
user: ["USER_1", "USER_2", "USER_3", "USER_4"]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.x'
- name: Install Dependencies
run: |
make deps
sudo apt-get update -y
sudo apt-get install -y build-essential
- name: Install go-junit-report
run: go install github.com/jstemmer/go-junit-report/v2@latest
# Note: test tags are not in alphabetical order, it was divided to optimize test execution time
- name: Set Test Scope for each Account
run: |
case "${{ matrix.user }}" in
"USER_1")
echo "TEST_TAGS=acceptance,backup,domain,domainrecord,domains,domainzonefile,helper,instance,provider" >> $GITHUB_ENV
echo "LINODE_TOKEN=${{ secrets.LINODE_TOKEN_USER_1 }}" >> $GITHUB_ENV
;;
"USER_2")
echo "TEST_TAGS=firewall,firewalldevice,firewalls,image,images,instancenetworking,instancesharedips,instancetype,instancetypes,ipv6range,ipv6ranges,kernel,kernels,nb,nbconfig,nbconfigs,nbnode,nbs,sshkey,sshkeys,vlan,volume,volumes,vpc,vpcs,vpcsubnets" >> $GITHUB_ENV
echo "LINODE_TOKEN=${{ secrets.LINODE_TOKEN_USER_2 }}" >> $GITHUB_ENV
;;
"USER_3")
echo "TEST_TAGS=instanceconfig,instancedisk,instanceip,networkingip,objcluster,objkey,profile,rdns,region,regions,stackscript,stackscripts" >> $GITHUB_ENV
echo "LINODE_TOKEN=${{ secrets.LINODE_TOKEN_USER_3 }}" >> $GITHUB_ENV
;;
"USER_4")
echo "TEST_TAGS=lke,lkeclusters,lkenodepool,lkeversions,obj,objbucket,placementgroup,placementgroups,placementgorupassignment,token,user,users" >> $GITHUB_ENV
echo "LINODE_TOKEN=${{ secrets.LINODE_TOKEN_USER_4 }}" >> $GITHUB_ENV
;;
esac
- name: Set report filename
run: echo "REPORT_FILENAME=$(date +'%Y%m%d%H%M')_terraform_test_report_${{ matrix.user }}.xml" >> $GITHUB_ENV
- name: Run Integration Tests
run: |
make TEST_TAGS="${{ env.TEST_TAGS }}" int-test | go-junit-report -set-exit-code -iocopy -out $REPORT_FILENAME
env:
LINODE_TOKEN: ${{ env.LINODE_TOKEN }}
- name: Upload Test Report as Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: test-report-${{ matrix.user }}
if-no-files-found: ignore
path: '*.xml'
retention-days: 1
apply-calico-rules:
runs-on: ubuntu-latest
needs: [integration_tests]
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
- name: Download kubectl and calicoctl for LKE clusters
run: |
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
chmod +x calicoctl-linux-amd64 kubectl
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
mv kubectl /usr/local/bin/kubectl
- name: Apply Calico Rules to LKE # Only Running against Matrix USER 4 which includes LKE test suite
run: |
cd e2e_scripts/cloud_security_scripts/lke_calico_rules/ && ./lke_calico_rules_e2e.sh
env:
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN_USER_4 }}
add-fw-lke-nodes:
runs-on: ubuntu-latest
needs: [integration_tests]
if: always()
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Linode CLI
run: |
pip install linode-cli
- name: Create Firewall and Attach to Instances
run: |
FIREWALL_ID=$(linode-cli firewalls create --label "e2e-fw-$(date +%s)" --rules.inbound_policy "DROP" --rules.outbound_policy "ACCEPT" --text --format=id --no-headers)
echo "Created Firewall with ID: $FIREWALL_ID"
for instance_id in $(linode-cli linodes list --format "id" --text --no-header); do
echo "Attaching firewall to instance: $instance_id"
if linode-cli firewalls device-create "$FIREWALL_ID" --id "$instance_id" --type linode; then
echo "Firewall attached to instance $instance_id successfully."
else
echo "An error occurred while attaching firewall to instance $instance_id. Skipping..."
fi
done
env:
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN_USER_4 }} # only Matrix test user 4 runs LKE tests
process-upload-report:
runs-on: ubuntu-latest
needs: [integration_tests]
if: always() && github.repository == 'linode/terraform-provider-linode' # Run even if integration tests fail and only on main repository
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Python dependencies
run: pip3 install requests wheel boto3
- name: Download test report
uses: actions/download-artifact@v4
- name: Get .xml reports from separate Artifacts into root folder
run: rsync -av test-report-USER_*/* .
- name: Merge Test Reports
run: python e2e_scripts/tod_scripts/xml_to_obj_storage/terraform_tests/merge_terraform_results.py
- name: Add Information to XML Report
run: |
filename=$(ls | grep -E '^[0-9]{12}_terraform_merged_report.xml$')
python e2e_scripts/tod_scripts/xml_to_obj_storage/scripts/add_gha_info_to_xml.py --branch_name "${GITHUB_REF#refs/*/}" --gha_run_id "${GITHUB_RUN_ID}" --gha_run_number "${GITHUB_RUN_NUMBER}" --xmlfile "${filename}"
- name: Upload Test Results
run: |
filename=$(ls | grep -E '^[0-9]{12}_terraform_merged_report.xml$')
python e2e_scripts/tod_scripts/xml_to_obj_storage/scripts/xml_to_obj.py "${filename}"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
notify-slack:
runs-on: ubuntu-latest
needs: [integration_tests]
if: always() && github.repository == 'linode/terraform-provider-linode' # Run even if integration tests fail and only on main repository
steps:
- name: Notify Slack
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":rocket: *${{ github.workflow }} Completed in: ${{ github.repository }}* :white_check_mark:"
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Build Result:*\n${{ needs.integration_tests.result == 'success' && ':large_green_circle: Build Passed' || ':red_circle: Build Failed' }}"
},
{
"type": "mrkdwn",
"text": "*Branch:*\n`${{ github.ref_name }}`"
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Commit Hash:*\n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ github.sha }}>"
},
{
"type": "mrkdwn",
"text": "*Run URL:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Run Details>"
}
]
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Triggered by: :bust_in_silhouette: `${{ github.actor }}`"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}