-
-
Notifications
You must be signed in to change notification settings - Fork 57
327 lines (295 loc) · 12 KB
/
ci.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
name: ci
on:
push:
branches:
- master
pull_request:
jobs:
linting:
name: "pre-commit hooks" # (includes Python formatting + linting)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
name: Checkout code
- name: Internal github app token
id: token
uses: getsentry/action-github-app-token@97c9e23528286821f97fba885c1b1123284b29cc # v2.0.0
continue-on-error: true
with:
app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }}
private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }}
- uses: actions/setup-python@v4
with:
python-version: 3.8
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Setup pre-commit
run: make setup-git
- name: Install dependencies
run: |
python -m pip install --upgrade pip
make install-python-dependencies
- uses: getsentry/paths-filter@v2
id: files
with:
# Enable listing of files matching each filter.
# Paths to files will be available in `${FILTER_NAME}_files` output variable.
# Paths will be escaped and space-delimited.
# Output is usable as command line argument list in linux shell
list-files: shell
# It doesn't make sense to lint deleted files.
# Therefore we specify we are only interested in added or modified files.
filters: |
all:
- added|modified: '**/*'
- name: Run pre-commit checks
# Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
# XXX: there is a very small chance that it'll expand to exceed Linux's limits
# `getconf ARG_MAX` - max # bytes of args + environ for exec()
# we skip the `no-commit-to-branch` because in CI we are in fact on master already
# and we have merged to it
run: |
SKIP=no-commit-to-branch pre-commit run --files ${{ steps.files.outputs.all_files }}
# If working tree is dirty, commit and update if we have a token
- name: Apply any pre-commit fixed files
if: steps.token.outcome == 'success' && github.ref != 'refs/heads/master' && always()
uses: getsentry/action-github-commit@v1.0.0
with:
github-token: ${{ steps.token.outputs.token }}
typing:
name: "mypy typing"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
name: Checkout code
- uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
make install-python-dependencies
- name: Run mypy
run: |
make backend-typing
config-validation:
name: "Dataset Config Validation"
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: actions/checkout@v3
name: Checkout code
- uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
make install-python-dependencies
- name: Validate configs
run: |
make validate-configs
snuba-image:
name: Build snuba CI image
runs-on: ubuntu-latest
timeout-minutes: 20
outputs:
branch: ${{ steps.branch.outputs.branch }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get branch name
id: branch
# strip `refs/heads/` from $GITHUB_REF and replace `/` with `-` so that
# it can be used as a docker tag
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> "$GITHUB_OUTPUT"
# We are only using ghcr here for CI as `setup-gcloud` is a bit slow
# Should revisit this when we move off of google cloud build (we may want to move these to GCR)
- name: Registry login
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
# These are pulled in order to be able to use docker layer caching
- name: Pull snuba CI images
if: github.repository_owner == 'getsentry'
run: |
docker pull ghcr.io/getsentry/snuba-ci:${{ github.sha }} || \
docker pull ghcr.io/getsentry/snuba-ci:${{ steps.branch.outputs.branch }} || \
docker pull ghcr.io/getsentry/snuba-ci:latest || true
- name: Build snuba docker image for CI
if: github.repository_owner == 'getsentry'
run: |
docker build . \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg SHOULD_BUILD_RUST=false \
-t ghcr.io/getsentry/snuba-ci:latest \
-t ghcr.io/getsentry/snuba-ci:${{ github.sha }} \
-t ghcr.io/getsentry/snuba-ci:${{ steps.branch.outputs.branch }} \
--cache-from ghcr.io/getsentry/snuba-ci:latest \
--cache-from ghcr.io/getsentry/snuba-ci:${{ steps.branch.outputs.branch }} \
--cache-from ghcr.io/getsentry/snuba-ci:${{ github.sha }} \
--target testing
- name: Publish images for cache
if: steps.branch.outputs.branch == 'master' || github.event.pull_request.head.repo.full_name == github.repository
# outside contributors won't be able to push to the docker registry
# ignore the failures in this step
continue-on-error: ${{ github.event_name == 'pull_request' }}
run: |
# Useful to speed up CI
docker push ghcr.io/getsentry/snuba-ci:${{ steps.branch.outputs.branch }}
docker push ghcr.io/getsentry/snuba-ci:${{ github.sha }}
if [ "${{ steps.branch.outputs.branch }}" == 'master' ]; then
# The latest tag should only be published on `master`
docker push ghcr.io/getsentry/snuba-ci:latest
fi
tests:
needs: [linting, snuba-image]
name: Tests and code coverage
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
snuba_settings:
["test", "test_distributed", "test_distributed_migrations"]
steps:
- uses: actions/checkout@v2
name: Checkout code
- name: Pull snuba CI images
run: |
docker pull ghcr.io/getsentry/snuba-ci:${{ github.sha }} || \
docker pull ghcr.io/getsentry/snuba-ci:${{ needs.snuba-image.outputs.branch }} || \
docker pull ghcr.io/getsentry/snuba-ci:latest || true
- name: Build snuba docker image for CI
run: |
docker build . \
-t snuba-test \
--build-arg SHOULD_BUILD_RUST=false \
--cache-from ghcr.io/getsentry/snuba-ci:${{ github.sha }} \
--cache-from ghcr.io/getsentry/snuba-ci:${{ needs.snuba-image.outputs.branch }} \
--cache-from ghcr.io/getsentry/snuba-ci:latest \
--target testing
- name: Docker set up
run: |
docker network create --attachable cloudbuild
- name: Docker Snuba tests
run: |
SNUBA_IMAGE=snuba-test SNUBA_SETTINGS=${{ matrix.snuba_settings }} docker-compose -f docker-compose.gcb.yml run --rm snuba-test
if: ${{ matrix.snuba_settings != 'test_distributed_migrations' }}
- name: Docker Snuba Multi-Node Tests
run: |
SNUBA_SETTINGS=test_distributed_migrations docker-compose --profile multi_node -f docker-compose.gcb.yml up -d
SNUBA_IMAGE=snuba-test SNUBA_SETTINGS=test_distributed_migrations TEST_LOCATION=test_distributed_migrations docker-compose --profile multi_node -f docker-compose.gcb.yml run --rm snuba-test
if: ${{ matrix.snuba_settings == 'test_distributed_migrations' }}
- name: Docker Snuba Init Tests
run: |
SNUBA_IMAGE=snuba-test SNUBA_SETTINGS=test_initialization TEST_LOCATION=test_initialization docker-compose -f docker-compose.gcb.yml run --rm snuba-test
if: ${{ matrix.snuba_settings == 'test' }}
- name: Upload to codecov
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov && chmod +x codecov && ./codecov -t ${CODECOV_TOKEN}
admin-tests:
needs: [linting]
name: Front end tests for snuba admin
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout code
- uses: volta-cli/action@v4
- name: Set up and run tests through yarn
run: cd snuba/admin && yarn install && yarn run test --coverage
- name: Upload to codecov
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov && chmod +x codecov && ./codecov -t ${CODECOV_TOKEN}
sentry:
needs: [snuba-image]
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
matrix:
instance: [0, 1]
env:
# XXX: MATRIX_INSTANCE_TOTAL must be hardcoded to the length of strategy.matrix.instance.
MATRIX_INSTANCE_TOTAL: 2
MIGRATIONS_TEST_MIGRATE: 1
steps:
# Checkout codebase
- name: Checkout snuba
uses: actions/checkout@v2
- name: Pull snuba CI images
run: |
docker pull ghcr.io/getsentry/snuba-ci:${{ github.sha }} || \
docker pull ghcr.io/getsentry/snuba-ci:${{ needs.snuba-image.outputs.branch }} || \
docker pull ghcr.io/getsentry/snuba-ci:latest || true
- name: Build snuba docker image for CI
run: |
docker build . \
-t snuba-test \
--build-arg SHOULD_BUILD_RUST=false \
--cache-from ghcr.io/getsentry/snuba-ci:latest \
--cache-from ghcr.io/getsentry/snuba-ci:${{ needs.snuba-image.outputs.branch }} \
--cache-from ghcr.io/getsentry/snuba-ci:${{ github.sha }} \
--target testing
# Checkout Sentry and run integration tests against latest snuba
# Make sure this is after `docker build`, otherwise we'll break docker cache
- name: Checkout sentry
uses: actions/checkout@v2
with:
repository: getsentry/sentry
path: sentry
- name: Setup steps
id: setup
run: |
pip install --upgrade pip wheel
# We cannot execute actions that are not placed under .github of the main repo
mkdir -p .github/actions
cp -r sentry/.github/actions/* .github/actions
- name: Setup Sentry
id: setup-sentry
uses: ./.github/actions/setup-sentry
with:
workdir: sentry
cache-files-hash: ${{ hashFiles('sentry/requirements**.txt') }}
python-version: 3.8
snuba: false
kafka: true
clickhouse: true
- name: Start snuba
run: |
docker run -d --rm \
-p 127.0.0.1:1218:1218 \
-e PYTHONUNBUFFERED=1 \
-e SNUBA_SETTINGS=docker \
-e DEBUG=1 \
-e DEFAULT_BROKERS=sentry_kafka:9092 \
-e CLICKHOUSE_HOST=sentry_clickhouse \
-e CLICKHOUSE_PORT=9000 \
-e CLICKHOUSE_HTTP_PORT=8123 \
-e REDIS_HOST=sentry_redis \
-e REDIS_PORT=6379 \
-e REDIS_DB=1 \
--name sentry_snuba \
--network sentry \
snuba-test
docker exec sentry_snuba snuba migrations migrate --force
- name: Run snuba tests
working-directory: sentry
run: |
make test-snuba
self-hosted-end-to-end:
needs: [snuba-image]
runs-on: ubuntu-latest
# temporary, remove once we are confident the action is working
continue-on-error: true
steps:
- name: Checkout Snuba
uses: actions/checkout@v3
- name: Run Sentry self-hosted e2e CI
uses: getsentry/action-self-hosted-e2e-tests@f45ef07793b2cc805a9a9401819f486da449a90a
with:
project_name: snuba
docker_repo: getsentry/snuba
image_url: us.gcr.io/sentryio/snuba:${{ github.event.pull_request.head.sha || github.sha }}
docker_password: ${{ secrets.DOCKER_HUB_RW_TOKEN }}