-
Notifications
You must be signed in to change notification settings - Fork 289
240 lines (200 loc) · 7.08 KB
/
pr-build.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
232
233
234
235
236
237
238
239
240
name: Pull request Build
on:
pull_request_target:
types: [ opened, synchronize, reopened ]
branches:
- "main"
paths-ignore:
- 'branding/**'
- 'design/**'
- '.codespell-whitelist'
- '.gitignore'
- '.golangci.yml'
- 'botkube-title.png'
- 'botkube_arch.jpg'
- 'CODE_OF_CONDUCT.md'
- 'comm_config.yaml.tpl'
- 'CONTRIBUTING.md'
- 'LICENSE'
- 'README.md'
- 'global_config.yaml.tpl'
env:
HELM_VERSION: v3.9.0
K3D_VERSION: v5.4.6
PR_NUMBER: ${{ github.event.pull_request.number }}
IMAGE_REGISTRY: "ghcr.io"
IMAGE_REPOSITORY: "kubeshop/pr/botkube"
CFG_EXPORTER_IMAGE_REPOSITORY: "kubeshop/pr/botkube-config-exporter"
IMAGE_TAG: ${{ github.event.pull_request.number }}-PR
IMAGE_SAVE_LOAD_DIR: /tmp/botkube-images
jobs:
save-image:
name: Build and save Botkube image
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
install-only: true
version: latest
- name: Save
run: |
make save-images
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: botkube-${{github.sha}}
path: ${{ env.IMAGE_SAVE_LOAD_DIR }}
retention-days: 1
push-image:
name: Push images
runs-on: ubuntu-latest
needs: [ save-image ]
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: botkube-${{github.sha}}
path: ${{ env.IMAGE_SAVE_LOAD_DIR }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push
run: make load-and-push-images
- name: Delete Docker image artifact
uses: geekyeggo/delete-artifact@v1
if: always()
with:
name: botkube-${{github.sha}}
- name: Summary
run: |
cat > $GITHUB_STEP_SUMMARY << ENDOFFILE
### Botkube image published successfully! :rocket:
To test Botkube with PR changes, run:
gh pr checkout ${PR_NUMBER}
helm install botkube -n botkube --create-namespace \\
--set image.repository=${IMAGE_REPOSITORY} \\
--set image.tag=${IMAGE_TAG} \\
./helm/botkube
ENDOFFILE
check-generated-resources:
runs-on: ubuntu-latest
# We want to check all generated resources and notify about all possible problems.
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Run generating gRPC resources
run: make gen-grpc-resources
- name: Detect git changes
run: |
if [[ $(git diff --stat) != '' ]]; then
echo -e '❌ \033[0;31mGenerated gRPC resources are outdated. Run 'make gen-grpc-resources'.\033[0m'
git diff --color
exit 1
fi
- name: Run generating CLI docs
run: make gen-docs-cli
- name: Detect git changes
run: |
if [[ $(git diff --stat) != '' ]]; then
echo -e '❌ \033[0;31mGenerated CLI docs are outdated. Run 'make gen-docs-cli'.\033[0m'
git diff --color
exit 1
else
echo '✔ No issues detected. Have a nice day :-)'
fi
integration-tests:
name: Integration tests
runs-on: ubuntu-latest
needs: [ push-image ]
permissions:
contents: read
packages: read
strategy:
# make the jobs independent
fail-fast: false
matrix:
integration:
- slack
- discord
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: ${{ env.HELM_VERSION }}
- name: Download k3d
run: "wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | TAG=${K3D_VERSION} bash"
- name: Create cluster to test ${{ matrix.integration }}
run: "k3d cluster create ${{ matrix.integration }}-test-cluster --wait --timeout=5m"
- name: Install Botkube to test ${{ matrix.integration }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
DISCORD_BOT_ID: ${{ secrets.DISCORD_BOT_ID }}
run: |
helm install botkube --namespace botkube ./helm/botkube --wait --create-namespace \
-f ./helm/botkube/e2e-test-values.yaml \
--set communications.default-group.slack.token="${SLACK_BOT_TOKEN}" \
--set communications.default-group.discord.token="${DISCORD_BOT_TOKEN}" \
--set communications.default-group.discord.botID="${DISCORD_BOT_ID}" \
--set image.registry="${IMAGE_REGISTRY}" \
--set image.repository="${IMAGE_REPOSITORY}" \
--set image.tag="${IMAGE_TAG}" \
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
install-only: true
version: latest
- name: Build all plugins into dist directory
env:
# we hardcode plugins version, so it's predictable in e2e tests
GORELEASER_CURRENT_TAG: "v0.0.0-latest"
run: |
make build-plugins
- name: Run ${{ matrix.integration }} tests
env:
SLACK_TESTER_APP_TOKEN: ${{ secrets.SLACK_TESTER_APP_TOKEN }}
SLACK_ADDITIONAL_CONTEXT_MESSAGE: "Pull request: ${{ github.event.pull_request.number }} - https://github.com/kubeshop/botkube/pull/${{ github.event.pull_request.number }}"
DISCORD_TESTER_APP_TOKEN: ${{ secrets.DISCORD_TESTER_APP_TOKEN }}
DISCORD_GUILD_ID: ${{ secrets.DISCORD_GUILD_ID }}
DISCORD_ADDITIONAL_CONTEXT_MESSAGE: "Pull request: ${{ github.event.pull_request.number }} - https://github.com/kubeshop/botkube/pull/${{ github.event.pull_request.number }}"
PLUGINS_BINARIES_DIRECTORY: ${{ github.workspace }}/plugin-dist
run: |
KUBECONFIG=$(k3d kubeconfig write ${{ matrix.integration }}-test-cluster) \
make test-integration-${{ matrix.integration }}