Skip to content

Commit fbe5ec7

Browse files
authored
[copy of] Tentative fixes for the atddiff check #207 (#211)
This is the same set of changes as #207 but I pushed this branch to the original repo owned by semgrep instead of my personal fork. The CI checks should now all pass.
1 parent 6dffeaa commit fbe5ec7

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

.github/workflows/lint.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
set -x
3232
3333
git config --global --add safe.directory "$(pwd)"
34-
34+
3535
# github actions sets HOME=/home/github where we don't have an opam env
3636
eval $(HOME=/root opam env)
3737
apk add jq
@@ -40,9 +40,12 @@ jobs:
4040
atddiff --version
4141
4242
# run the checks
43-
echo -ne 'Backwards compatability summary:\n\n```' > summary-00-header.txt
43+
echo -ne 'Backwards compatibility summary:\n\n```' > summary-00-header.txt
4444
echo '```' >> summary-20-footer.txt
45-
./scripts/check-backwards-compatability.sh | tee summary-10-body.txt
45+
46+
# fail if check command fails
47+
set -o pipefail
48+
./scripts/check-backwards-compatibility | tee summary-10-body.txt
4649
4750
- uses: marocchino/sticky-pull-request-comment@v2
4851
if: ${{ !cancelled() }}

scripts/check-backwards-compatability.sh renamed to scripts/check-backwards-compatibility

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
# - Diff the two diffs to see if new issues were introduced
1313
set -euo pipefail
1414

15-
minimum="v$(curl -s https://semgrep.dev/api/check-version | jq -r '.versions.minimum')"
15+
version_url="https://semgrep.dev/api/check-version"
16+
min_version=$(curl -s "$version_url" | jq -r '.versions.minimum')
17+
if [[ -z "$min_version" ]]; then
18+
echo "Failed to obtain minimum supported version from $version_url" >&2
19+
exit 1
20+
fi
21+
22+
minimum="v${min_version}"
1623
tags=$(git log --simplify-by-decoration --pretty=format:%D "${minimum}^!" origin/main | grep -o 'tag: [^,)]\+' | sed 's/^tag: //' | sort -n)
1724

1825
checked=("dummy")
@@ -27,22 +34,27 @@ for tag in $tags; do
2734

2835
set +e # do our own error handling for a bit
2936
echo "Checking backward compatibility of semgrep_output_v1.atd against past version $tag"
30-
git difftool --trust-exit-code -x 'atddiff --no-locations --backward' -y "$tag" "origin/main" semgrep_output_v1.atd > before.txt
37+
# I'm getting an exit code 128 when atddiff returns 3 (as of git 2.43.0),
38+
# contrary to what 'git difftool --help' promises for '--trust-exit-code'.
39+
# I'd report the bug if it was easier. -- Martin
40+
git difftool --trust-exit-code -x 'atddiff --no-locations --backward' -y \
41+
"$tag" "origin/main" -- semgrep_output_v1.atd > before.txt
3142
ret=$?
3243
if [ "$ret" -ge 1 ] && [ "$ret" -le 2 ]; then
33-
echo "ERROR: atddiff had an error: $?"
44+
echo "ERROR: atddiff had an error: $ret"
3445
cat before.txt
3546
exit 1
3647
fi
37-
git difftool --trust-exit-code -x 'atddiff --no-locations --backward' -y "$tag" "HEAD" semgrep_output_v1.atd > after.txt
48+
git difftool --trust-exit-code -x 'atddiff --no-locations --backward' -y \
49+
"$tag" "HEAD" -- semgrep_output_v1.atd > after.txt
3850
ret=$?
3951
if [ "$ret" -ge 1 ] && [ "$ret" -le 2 ]; then
40-
echo "ERROR: atddiff had an error: $?"
52+
echo "ERROR: atddiff had an error: $ret"
4153
cat after.txt
4254
exit 1
4355
fi
4456

45-
diff -u <(cat before.txt) <(cat after.txt)
57+
diff -u before.txt after.txt
4658
if [ "$?" -ne 0 ]; then
4759
echo "ERROR: semgrep_output_v1.atd is not backward compatible with $tag"
4860
errors=$((errors + 1))

0 commit comments

Comments
 (0)