Skip to content

Commit

Permalink
Improve historical version logic
Browse files Browse the repository at this point in the history
It's rare but it's possible that a tagged version exists as a GitHub release
but not as a docker image. Try a few different versions if the tag does not
exist in the docker registry.
  • Loading branch information
philipturnbull committed Aug 14, 2023
1 parent 6bdf176 commit 87478bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/semgrep-rules-test-historical.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ jobs:
- name: grab historical semgrep version
env:
GH_TOKEN: ${{ github.token }}
run: |
SEMGREP_OLD_VERSION=$(gh api --method GET /repos/returntocorp/semgrep/releases | jq -r '.[].tag_name' | sed -n 10p | tr -d v)
echo $SEMGREP_OLD_VERSION
echo "SEMGREP_OLD_VERSION=$SEMGREP_OLD_VERSION" >> $GITHUB_ENV
run: semgrep-rules/scripts/historical-semgrep-version
- name: validate rules on historical semgrep version
run: |
docker run --rm -v ${GITHUB_WORKSPACE}/semgrep-rules:/src returntocorp/semgrep:${SEMGREP_OLD_VERSION} semgrep --validate --config /src
Expand Down
17 changes: 17 additions & 0 deletions scripts/historical-semgrep-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
HISTORICAL_VERSIONS=10
RETRIES=3

versions=$(gh api --method GET /repos/returntocorp/semgrep/releases | jq 'reverse' | jq -r '.[].tag_name' | tail "-n${HISTORICAL_VERSIONS}" | head -n "${RETRIES}" | tr -d v)

for version in $(echo "${versions}"); do
docker pull "returntocorp/semgrep:${version}"
if [[ "$?" == 0 ]]; then
echo "${version}"
echo "SEMGREP_OLD_VERSION=${version}" >> "${GITHUB_ENV}"
exit 0
fi
done

echo "Could not determine historical version, tried: $(echo ${versions})"
exit 1

0 comments on commit 87478bb

Please sign in to comment.