forked from semgrep/semgrep
-
Notifications
You must be signed in to change notification settings - Fork 0
380 lines (358 loc) · 13.6 KB
/
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
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# The goals of this workflow are to check that:
# - we can build semgrep-core and semgrep
# - we can build a Docker image as well as Linux and MacOS binaries
# - all our tests (the one in semgrep-core and the one in semgrep-cli) are passing
# - we don't have any perf regressions in our benchmarks
name: tests
on:
workflow_dispatch:
pull_request:
paths-ignore:
- "**.md"
push:
branches:
- develop
paths-ignore:
- "**.md"
jobs:
test-core:
# TODO: why not use the artifact of build-semgrep-core in this job instead?
name: test semgrep-core
runs-on: ubuntu-22.04
container: returntocorp/ocaml:alpine-2023-04-03
env:
HOME: /root
steps:
- uses: actions/checkout@v3
with:
submodules: true
persist-credentials: false
- name: Build semgrep-core
run: ./scripts/install-alpine-semgrep-core
- name: Test semgrep-core
run: |
eval $(opam env)
START=`date +%s`
make core-test
make core-e2etest
END=`date +%s`
TEST_RUN_TIME=$((END-START))
curl --fail -L -X POST "https://dashboard.semgrep.dev/api/metric/semgrep.core.test-run-time-seconds.num" -d "$TEST_RUN_TIME"
- name: Report Number of Tests Stats
if: github.ref == 'refs/heads/develop'
run: ./tests/report_test_metrics.sh
# TODO: move this to a stable host for more reliable results.
#
# It's not clear how to push the stats only when "on the main
# branch". The GitHub Actions documentation is unhelpful. So we
# keep things simple and publish the results every time.
#
- name: Publish match performance
run: |
# This runs a short test suite to track the match performance
# of semgrep-core over time. The results are pushed to the
# dashboard at https://dashboard.semgrep.dev/
#
opam exec -- make report-perf-matching
test-osemgrep:
name: test osemgrep
runs-on: ubuntu-22.04
container: returntocorp/ocaml:alpine-2023-04-03
env:
HOME: /root
steps:
- uses: actions/checkout@v3
with:
submodules: true
persist-credentials: false
- name: Build semgrep-core
run: ./scripts/install-alpine-semgrep-core
- name: Install osemgrep
run: |
eval $(opam env)
make core-install
cp bin/semgrep-core /usr/bin/ # needed for pipenv install to work below
- name: Install Python dependencies
working-directory: cli
run: pipenv install --dev
- name: Run pytest for osemgrep known passing tests
working-directory: cli
run: |
make osempass
test-cli:
name: test semgrep-cli
runs-on: ubuntu-22.04
needs: [build-test-core-x86]
permissions:
contents: write
pull-requests: write
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Fetch semgrep-cli submodules
run: git submodule update --init --recursive --recommend-shallow cli/src/semgrep/lang cli/src/semgrep/semgrep_interfaces
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: pipenv
- run: pip install pipenv==2022.6.7
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: ocaml-build-artifacts-release
- name: Install artifacts
run: |
tar xf ocaml-build-artifacts.tgz
sudo cp ocaml-build-artifacts/bin/* /usr/bin
- name: Install Python dependencies
working-directory: cli
run: pipenv install --dev
- name: Run pytest
working-directory: cli
run: |
# tests should simulate CI environment iff they need one
unset CI
unset "${!GITHUB_@}"
pipenv run pytest -n auto -vv --snapshot-update --allow-snapshot-deletion
# because of the fail-fast setting, we expect only the fastest failing job to get to the steps below
- name: Prepare repo for snapshot commit
if: failure()
run: |
# the commit step that follows will fail to fetch the pfff submodule
# (perhaps because of the github token's permissions)
# so we disable recursive fetching
git config fetch.recurseSubmodules false
# Because we are not persisting creds in the checkout step, we must create the creds file
# when it's needed to push up snapshot changes.
# Note that this is only done after tests are run, so that tests do not have access to the token
- name: Configure git creds for push
id: configure-creds
if: failure() && github.event_name == 'pull_request' && (github.actor != 'dependabot[bot]' && !(github.event.pull_request.head.repo.full_name != github.repository))
run: |
echo "machine github.com" >> ~/.netrc
echo "login ${{ github.repository }}" >> ~/.netrc
echo "password ${{ secrets.GITHUB_TOKEN }}" >> ~/.netrc
- name: Commit snapshot updates
id: snapshot-commit
if: failure() && github.event_name == 'pull_request' && (github.actor != 'dependabot[bot]' && !(github.event.pull_request.head.repo.full_name != github.repository))
uses: EndBug/add-and-commit@v9
with:
add: cli/tests/e2e/snapshots
default_author: github_actions
message: "Update pytest snapshots"
new_branch: snapshot-updates-${{ github.run_id }}-${{ github.run_attempt }}
- name: Remove Credentials
id: remove-creds
if: failure() && github.event_name == 'pull_request' && (github.actor != 'dependabot[bot]' && !(github.event.pull_request.head.repo.full_name != github.repository))
run: rm ~/.netrc
- name: Comment about any snapshot updates
if: failure() && steps.snapshot-commit.outputs.pushed == 'true'
run: |
echo ":camera_flash: The pytest shapshots changed in your PR." >> /tmp/message.txt
echo "Please carefully review these changes and make sure they are intended:" >> /tmp/message.txt
echo >> /tmp/message.txt
echo "1. Review the changes at https://github.com/returntocorp/semgrep/commit/${{ steps.snapshot-commit.outputs.commit_long_sha }}" >> /tmp/message.txt
echo "2. Accept the new snapshots with" >> /tmp/message.txt
echo >> /tmp/message.txt
echo " git fetch origin && git cherry-pick ${{ steps.snapshot-commit.outputs.commit_sha }} && git push" >> /tmp/message.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file /tmp/message.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# These tests aren't run by default by pytest.
# To reproduce errors locally, use:
# $ cd cli/tests
# $ make qa
#
# TODO: if you know this, please explain what the code below is meant
# to achieve and how to make sure it works.
#
test-qa:
name: quality assurance on semgrep
runs-on: ubuntu-22.04
needs: [build-test-core-x86]
strategy:
fail-fast: false
matrix:
split: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Fetch semgrep-cli submodules
run: git submodule update --init --recursive --recommend-shallow cli/src/semgrep/lang cli/src/semgrep/semgrep_interfaces tests/semgrep-rules
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: pipenv
- run: pip install pipenv==2022.6.7
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: ocaml-build-artifacts-release
- name: Install artifacts
run: |
tar xf ocaml-build-artifacts.tgz
sudo cp ocaml-build-artifacts/bin/* /usr/bin
- name: Install semgrep
working-directory: cli
run: |
export PATH=/github/home/.local/bin:$PATH
pipenv install --dev
- uses: actions/cache@v3
with:
path: ~/.cache/qa-public-repos
key: qa-public-repos-${{ hashFiles('semgrep/tests/qa/*public_repos*') }}-${{ matrix.split }}
- run: |
mkdir -p ~/.cache/qa-public-repos
touch ~/.cache/qa-public-repos/ok
- name: Test semgrep
working-directory: cli
run: |
export PATH=/github/home/.local/bin:$PATH
pipenv run pytest -n auto -vv --tb=short --splits 4 --group ${{ matrix.split }} tests/qa
env:
QA_TESTS_CACHE_PATH: ~/.cache/qa-public-repos
# Run abbreviated version of benchmarks to check that they work
benchmarks-lite:
runs-on: ubuntu-22.04
needs: [build-test-core-x86]
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Fetch semgrep-cli submodules
run: git submodule update --init --recursive --recommend-shallow cli/src/semgrep/lang cli/src/semgrep/semgrep_interfaces
- uses: actions/setup-python@v4
with:
python-version: "3.7"
cache: pipenv
- run: pip install pipenv==2022.6.7
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: ocaml-build-artifacts-release
- name: Install artifacts
run: |
tar xf ocaml-build-artifacts.tgz
sudo cp ocaml-build-artifacts/bin/* /usr/bin
- name: Install cli dependencies
working-directory: cli
run: pipenv install --dev
- name: Test dummy benchmarks on latest
working-directory: cli
run: |
pipenv run semgrep --version
pipenv run python -m semgrep --version
pipenv run semgrep-core -version
pipenv run python3 ../perf/run-benchmarks --dummy
# Run each benchmark twice to decrease effect of natural variance
benchmarks-full:
runs-on: ubuntu-22.04
needs: [build-test-core-x86]
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Fetch semgrep-cli submodules
run: git submodule update --init --recursive --recommend-shallow cli/src/semgrep/lang cli/src/semgrep/semgrep_interfaces
- uses: actions/setup-python@v4
with:
python-version: "3.7"
cache: pipenv
- run: pip install pipenv==2022.6.7
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: ocaml-build-artifacts-release
- name: Install artifacts
run: |
tar xf ocaml-build-artifacts.tgz
sudo cp ocaml-build-artifacts/bin/* /usr/bin
- name: Install cli dependencies
working-directory: cli
run: pipenv install --dev
- name: Run perf benchmark
run: scripts/run-benchmarks.sh ${{ secrets.GITHUB_TOKEN }} ${{ github.event.number }}
- name: Run python performance tests
working-directory: cli
run: pipenv run pytest tests/performance
build-test-docker:
uses: ./.github/workflows/build-test-docker.yaml
secrets: inherit
with:
docker-tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=pr
type=ref,event=branch
type=sha,event=branch
type=edge
artifact-name: image-test
repository-name: ${{ github.repository }}
file: Dockerfile
enable-tests: true
push-docker:
needs: [build-test-docker]
uses: ./.github/workflows/push-docker.yaml
if: github.ref == 'refs/heads/develop' || (github.actor != 'dependabot[bot]' && !(github.event.pull_request.head.repo.full_name != github.repository))
secrets: inherit
with:
artifact-name: image-test
repository-name: ${{ github.repository }}
dry-run: false
build-test-dev-docker:
uses: ./.github/workflows/build-test-docker.yaml
secrets: inherit
with:
docker-tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=pr
type=ref,event=branch
type=sha,event=branch
type=edge
repository-name: ${{ github.repository }}-dev
artifact-name: image-dev
file: dockerfiles/semgrep-dev.Dockerfile
enable-tests: false
push-dev-docker:
needs: [build-test-dev-docker]
uses: ./.github/workflows/push-docker.yaml
if: github.ref == 'refs/heads/develop'
secrets: inherit
with:
artifact-name: image-dev
repository-name: ${{ github.repository }}-dev
dry-run: false
test-semgrep-pro:
needs: [build-test-docker, push-docker]
uses: ./.github/workflows/test-semgrep-pro.yaml
if: github.ref == 'refs/heads/develop' || github.event.pull_request.head.repo.full_name == github.repository # only returntocorp has the necessary credentials to access semgrep pro
secrets: inherit
with:
artifact-name: image-test
repository-name: ${{ github.repository }}
build-test-core-x86:
uses: ./.github/workflows/build-test-core-x86.yaml
secrets: inherit
build-test-manylinux-x86:
needs: [build-test-core-x86]
uses: ./.github/workflows/build-test-manylinux-x86.yaml
secrets: inherit
build-test-osx-x86:
uses: ./.github/workflows/build-test-osx-x86.yaml
secrets: inherit
build-test-osx-m1:
uses: ./.github/workflows/build-test-osx-m1.yaml
secrets: inherit
build-test-ubuntu-16-04:
needs: [build-test-core-x86]
uses: ./.github/workflows/build-test-ubuntu-x86.yaml
secrets: inherit
build-test-javascript:
uses: ./.github/workflows/build-test-javascript.yaml
secrets: inherit