-
Notifications
You must be signed in to change notification settings - Fork 17
232 lines (204 loc) · 7.14 KB
/
k8s-dist-tests.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
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
name: (E2E) K8s Distribution Tests
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- "**.md"
pull_request_target:
types:
- labeled
branches:
- main
- 'release/**'
paths-ignore:
- "**.md"
pull_request:
types:
- labeled
branches:
- main
- 'release/**'
paths-ignore:
- "**.md"
permissions:
contents: write
pages: write
id-token: write
actions: write
env:
AWS_REGION: us-east-1
jobs:
decide-run-tests:
name: Decide to run tests
runs-on: ubuntu-22.04
outputs:
RUN_TESTS: ${{ steps.should-run-tests.outputs.RUN_TESTS }}
if: >-
( !cancelled()
&& ((github.event_name == 'pull_request_target'
&& github.event.label.name == 'run-all-test'
&& github.event.pull_request.head.repo.full_name != github.repository)
||
(github.event_name == 'pull_request'
&& github.event.label.name == 'run-all-test'
&& github.event.pull_request.head.repo.full_name == github.repository)
||
github.event_name == 'push'
||
github.event_name == 'workflow_dispatch'
)
)
steps:
- name: Decide to run tests
id: should-run-tests
run: |
if [[ '${{ github.event_name }}' != 'push' ]]; then
echo "RUN_TESTS=true" >> $GITHUB_OUTPUT
exit 0
fi
PR_NUMBER=$(echo "$COMMIT_MESSAGE" | grep -oP '\(#\K[0-9]*(?=\))')
PR_LABELS=$( (gh pr view https://github.com/${{github.repository}}/pull/${PR_NUMBER} --json labels | jq .labels[].name) || echo "Could not get PR labels")
for label in $PR_LABELS; do
# if full suite is ran before
if [[ "$label" == '"run-all-test"' ]]; then
echo "RUN_TESTS=false" >> $GITHUB_OUTPUT
exit 0
fi
done
echo "RUN_TESTS=true" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: ${{ github.event.commits[0].message }}
- name: Print decision
run: echo "Run tests= ${{ steps.should-run-tests.outputs.RUN_TESTS }}"
run-aks:
needs: decide-run-tests
if: needs.decide-run-tests.outputs.RUN_TESTS == 'true'
uses: ./.github/workflows/e2e-aks.yaml
secrets: inherit
run-eks:
needs: decide-run-tests
if: needs.decide-run-tests.outputs.RUN_TESTS == 'true'
uses: ./.github/workflows/e2e-eks.yaml
secrets: inherit
run-gke:
needs: decide-run-tests
if: needs.decide-run-tests.outputs.RUN_TESTS == 'true'
uses: ./.github/workflows/e2e-gke.yaml
secrets: inherit
update-test-run-status-badges:
needs: [run-aks, run-eks, run-gke]
if: always() && needs.decide-run-tests.outputs.RUN_TESTS == 'true'
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Get Secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
TEST_STATUSES_GIST_ID,CN/TEST_STATUSES_GIST_ID
GIST_CREATION_TOKEN,CN/GIST_CREATION_TOKEN
- name: Checkout
uses: actions/checkout@v4
- name: Update Status Badges
run: |
source .github/scripts/utils.sh
update_status_badges ${{ github.run_id }} ${{ env.TEST_STATUSES_GIST_ID }} ${{ env.GIST_CREATION_TOKEN }}
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
- name: Run unit tests
run: make test-unit
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
if: github.event_name == 'push'
strategy:
fail-fast: false
matrix:
edition: ["os", "ee"]
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
- name: Run integration tests
run: |
case ${{ matrix.edition }} in
os) GO_TEST_FLAGS='-ee=false';;
ee) GO_TEST_FLAGS='-ee=true';;
*) echo Unexpected edition: ${{ matrix.edition }} && exit 1;;
esac
make GO_TEST_FLAGS=${GO_TEST_FLAGS} test-it
slack_notify:
name: Slack Notify
timeout-minutes: 15
needs: ["update-test-run-status-badges"]
if: failure() && github.event_name == 'push'
runs-on: ubuntu-latest
env:
ACTION_API_URL: ${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows/k8s-dist-tests.yaml/runs?branch=main
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Get Secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
SLACK_WEBHOOK_URL_CLOUD_NATIVE,CN/SLACK_WEBHOOK_URL_CLOUD_NATIVE
- name: decide to notify
id: decide
run: |
while true
do
curl_result=$(curl -sSL\
-H "Accept: application/vnd.github+json" \
-H "Authorization: $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${ACTION_API_URL})
RESULT=$(echo $curl_result | jq -r 'first(.workflow_runs[] | select(.run_number < ${{ github.run_number }} )) | { conclusion, status, run_number}')
STATUS=$(echo $RESULT | jq -r .status)
if [[ $STATUS == "completed" ]]; then
break
fi
echo "status is $STATUS, sleeping 30 seconds"
sleep 30
done
CONCLUSION=$(echo $RESULT | jq -r .conclusion)
LAST_RUN_NUMBER=$(echo $RESULT | jq -r .run_number)
if [[ $CONCLUSION == "success" ]]; then
echo "SEND_SLACK_MESSAGE=true" >> $GITHUB_OUTPUT
echo "LAST_RUN_NUMBER=$LAST_RUN_NUMBER" >> $GITHUB_OUTPUT
else
echo "SEND_SLACK_MESSAGE=false" >> $GITHUB_OUTPUT
fi
- uses: rtCamp/action-slack-notify@v2
if: steps.decide.outputs.SEND_SLACK_MESSAGE == 'true'
env:
SLACK_CHANNEL: cloud-native-dev
SLACK_COLOR: red # or a specific color like 'green' or '#ff00ff'
SLACK_MESSAGE: '${{ github.actor}} broke the <${{ env.ACTION_RUN_URL }}|main branch> :bomb: previous successful run number was ${{ steps.decide.outputs.LAST_RUN_NUMBER }}'
SLACK_TITLE: Main Branch Broken
SLACK_USERNAME: rtCamp
SLACK_WEBHOOK: ${{ env.SLACK_WEBHOOK_URL_CLOUD_NATIVE }}
MSG_MINIMAL: true