Skip to content

Commit a0b4762

Browse files
authored
run lint in container (#172)
Now that the required version of atddiff is available in our base ocaml container, we can use that for much faster runs.
1 parent 87316a5 commit a0b4762

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

.github/workflows/lint.yaml

+14-13
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,30 @@ permissions:
1616
jobs:
1717
compatibility:
1818
runs-on: ubuntu-latest
19+
container: returntocorp/ocaml:alpine
1920
steps:
2021
- name: Checkout tree
2122
uses: actions/checkout@v4
2223
with:
2324
fetch-depth: 0
2425
fetch-tags: true
2526

26-
- name: Set-up OCaml
27-
uses: ocaml/setup-ocaml@v2
28-
with:
29-
ocaml-compiler: 5.1
30-
opam-pin: false
31-
opam-depext: false
32-
dune-cache: true
33-
34-
- name: install atddiff
35-
run: opam install atd
36-
3727
- name: atddiff all supported tags
3828
id: diff
3929
shell: bash
4030
run: |
41-
eval $(opam env)
31+
set -x
32+
33+
git config --global --add safe.directory "$(pwd)"
34+
35+
# github actions sets HOME=/home/github where we don't have an opam env
36+
eval $(HOME=/root opam env)
37+
apk add jq
38+
39+
# check / print version of atddiff
40+
atddiff --version
41+
42+
# run the checks
4243
echo -ne 'Backwards compatability summary:\n\n```' > summary-00-header.txt
4344
echo '```' >> summary-20-footer.txt
4445
./scripts/check-backwards-compatability.sh | tee summary-10-body.txt
@@ -59,4 +60,4 @@ jobs:
5960
run: |
6061
pip install mypy
6162
rm __init__.py # because dir has a - in it
62-
mypy semgrep_output_v1.py
63+
mypy semgrep_output_v1.py

scripts/check-backwards-compatability.sh

+20-9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
# - Diff against origin/main to establish a baseline
1111
# - Diff against HEAD
1212
# - Diff the two diffs to see if new issues were introduced
13-
14-
set -u # no "-eo pipefail" because we do our own error handling
13+
set -euo pipefail
1514

1615
minimum="v$(curl -s https://semgrep.dev/api/check-version | jq -r '.versions.minimum')"
1716
tags=$(git log --simplify-by-decoration --pretty=format:%D "${minimum}^!" origin/main | grep -o 'tag: [^,)]\+' | sed 's/^tag: //' | sort -n)
1817

19-
checked=()
18+
checked=("dummy")
2019
errors=0
2120
for tag in $tags; do
2221
commit=$(git rev-list -n 1 "$tag")
@@ -26,19 +25,31 @@ for tag in $tags; do
2625
fi
2726
checked+=("$commit")
2827

28+
set +e # do our own error handling for a bit
2929
echo "Checking backward compatibility of semgrep_output_v1.atd against past version $tag"
30-
git difftool -x 'atddiff --backward' -y "$tag" "origin/main" semgrep_output_v1.atd > before.txt
31-
git difftool -x 'atddiff --backward' -y "$tag" "HEAD" semgrep_output_v1.atd > after.txt
30+
git difftool --trust-exit-code -x 'atddiff --no-locations --backward' -y "$tag" "origin/main" semgrep_output_v1.atd > before.txt
31+
ret=$?
32+
if [ "$ret" -ge 1 ] && [ "$ret" -le 2 ]; then
33+
echo "ERROR: atddiff had an error: $?"
34+
cat before.txt
35+
exit 1
36+
fi
37+
git difftool --trust-exit-code -x 'atddiff --no-locations --backward' -y "$tag" "HEAD" semgrep_output_v1.atd > after.txt
38+
ret=$?
39+
if [ "$ret" -ge 1 ] && [ "$ret" -le 2 ]; then
40+
echo "ERROR: atddiff had an error: $?"
41+
cat after.txt
42+
exit 1
43+
fi
3244

33-
# neccesary because filenames have temp paths and line numbers can change without causing issues
34-
expr='s|File "/.*/\(.*.atd\)", line .*$|File "\1", line <removed for diff>|g'
35-
diff -u <(sed "$expr" before.txt) <(sed "$expr" after.txt)
45+
diff -u <(cat before.txt) <(cat after.txt)
3646
if [ "$?" -ne 0 ]; then
3747
echo "ERROR: semgrep_output_v1.atd is not backward compatible with $tag"
3848
errors=$((errors + 1))
3949
fi
50+
set -e
4051
done
4152

4253
if [ "$errors" -ne 0 ]; then
4354
exit 1
44-
fi
55+
fi

0 commit comments

Comments
 (0)