Skip to content

Commit

Permalink
Merge pull request #3040 from returntocorp/lockfile-comment-fix
Browse files Browse the repository at this point in the history
update use-frozen-lockfile rule
  • Loading branch information
philipturnbull authored Aug 14, 2023
2 parents d5bec93 + 87478bb commit d39961c
Show file tree
Hide file tree
Showing 5 changed files with 25 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
3 changes: 3 additions & 0 deletions generic/ci/security/use-frozen-lockfile.fixed.generic
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ RUN yarn install --prod --frozen-lockfile --prefer-offline --ignore-optional --n
# ok: use-frozen-lockfile-yarn
RUN yarn install --production --frozen-lockfile

# ok: use-frozen-lockfile-npm
# i am a comment, just to explain.. npm install

RUN yarn install --frozen-lockfile
RUN yarn install --immutable
# ruleid: use-frozen-lockfile-yarn
Expand Down
3 changes: 3 additions & 0 deletions generic/ci/security/use-frozen-lockfile.generic
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ RUN yarn install --prod --frozen-lockfile --prefer-offline --ignore-optional --n
# ok: use-frozen-lockfile-yarn
RUN yarn install --production --frozen-lockfile

# ok: use-frozen-lockfile-npm
# i am a comment, just to explain.. npm install

RUN yarn install --frozen-lockfile
RUN yarn install --immutable
# ruleid: use-frozen-lockfile-yarn
Expand Down
1 change: 1 addition & 0 deletions generic/ci/security/use-frozen-lockfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ rules:
- pattern-not-regex: npm install -g
- pattern-not-regex: npm install --global
- pattern-not-regex: npm install [\w]+
- pattern-not-regex: \#(.*)
fix: npm ci
message: >-
To ensure reproducible and deterministic builds, use `npm ci` rather than `npm install` in scripts.
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 d39961c

Please sign in to comment.