Skip to content

Commit

Permalink
Bump pre-commit/pre-commit-hooks from 4.5.0 to 4.6.0 (#45)
Browse files Browse the repository at this point in the history
### Description

- Bump pre-commit/pre-commit-hooks from 4.5.0 to 4.6.0
- Transform some scripts from bash to sh
  • Loading branch information
fabasoad authored Apr 20, 2024
1 parent 69d2bed commit 9b618ed
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 48 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
name: Functional Tests

on: # yamllint disable-line rule:truthy
pull_request: {}
push:
branches:
- "main"
pull_request:

defaults:
run:
shell: sh

jobs:
package-manager:
Expand All @@ -27,20 +31,19 @@ jobs:
type: scoop
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Setup scoop
if: ${{ runner.os == 'Windows' && matrix.type == 'scoop' }}
if: ${{ matrix.type == 'scoop' }}
uses: MinoruSekine/setup-scoop@main
- name: Configure yarn
if: ${{ runner.os == 'Windows' && matrix.type == 'yarn' }}
run: yarn global bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
shell: pwsh
- name: Install snyk
run: ./hooks/installation/install-${{ matrix.type }}.sh
shell: bash
- name: Print version
run: snyk --version
shell: sh
standalone:
name: Standalone
timeout-minutes: 5
Expand All @@ -50,13 +53,12 @@ jobs:
os: ["macos", "ubuntu", "windows"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Install snyk
run: ./hooks/installation/install-standalone.sh
shell: bash
- name: Print version
run: snyk --version
shell: sh
standalone-alpine:
name: Standalone
timeout-minutes: 5
Expand All @@ -68,13 +70,11 @@ jobs:
container:
image: ${{ matrix.image }}:latest
steps:
- uses: actions/checkout@v4
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Install tools
run: apk add bash curl
shell: sh
run: apk add curl
- name: Install snyk
run: ./hooks/installation/install-standalone.sh
shell: bash
- name: Print version
run: snyk --version
shell: sh
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ repos:
- id: prettier
stages: ["commit"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
Expand Down
10 changes: 5 additions & 5 deletions hooks/installation/install-standalone.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
set -eu

if [[ -f "/etc/alpine-release" ]]; then
if [ -f "/etc/alpine-release" ]; then
binary="snyk-alpine"
path="/usr/local/bin/"
else
Expand All @@ -19,7 +19,7 @@ else
path="C:\Windows\System32"
;;
*)
if [[ "$(uname -m)" == "arm64" ]]; then
if [ "$(uname -m)" = "arm64" ]; then
binary="snyk-linux-arm64"
else
binary="snyk-linux"
Expand All @@ -31,6 +31,6 @@ fi

url="https://static.snyk.io/cli/latest/$binary"
echo "[pre-commit-snyk] GET $url"
curl $url -o snyk
curl "$url" -o snyk
chmod +x ./snyk
mv ./snyk $path
mv ./snyk "$path"
20 changes: 11 additions & 9 deletions hooks/installation/main.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
# shellcheck disable=SC2039,SC3020
set -eu

if ! command -v snyk &> /dev/null
then
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
SCRIPT_PATH=$(realpath "$0")
INSTALLATION_FOLDER_PATH=$(dirname "${SCRIPT_PATH}")

if ! command -v snyk &> /dev/null; then
if command -v brew &> /dev/null; then
bash "${SCRIPT_DIR}"/install-brew.sh
sh "${INSTALLATION_FOLDER_PATH}/install-brew.sh"
elif command -v scoop &> /dev/null; then
bash "${SCRIPT_DIR}"/install-scoop.sh
sh "${INSTALLATION_FOLDER_PATH}/install-scoop.sh"
elif command -v npm &> /dev/null; then
bash "${SCRIPT_DIR}"/install-npm.sh
sh "${INSTALLATION_FOLDER_PATH}/install-npm.sh"
elif command -v yarn &> /dev/null; then
bash "${SCRIPT_DIR}"/install-yarn.sh
sh "${INSTALLATION_FOLDER_PATH}/install-yarn.sh"
else
bash "${SCRIPT_DIR}"/install-standalone.sh
sh "${INSTALLATION_FOLDER_PATH}/install-standalone.sh"
fi
fi
10 changes: 7 additions & 3 deletions hooks/snyk-code.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
set -eu
SCRIPT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
bash "${SCRIPT_DIR}"/installation/main.sh

SCRIPT_PATH=$(realpath "$0")
HOOKS_FOLDER_PATH=$(dirname "${SCRIPT_PATH}")
INSTALLATION_FOLDER_PATH="${HOOKS_FOLDER_PATH}/installation"

sh "${INSTALLATION_FOLDER_PATH}/main.sh"

snyk code test "$@"
44 changes: 36 additions & 8 deletions hooks/snyk-container.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
#!/usr/bin/env bash
set -eu
SCRIPT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
bash "${SCRIPT_DIR}"/installation/main.sh

SCRIPT_PATH=$(realpath "$0")
HOOKS_FOLDER_PATH=$(dirname "${SCRIPT_PATH}")
INSTALLATION_FOLDER_PATH="${HOOKS_FOLDER_PATH}/installation"

sh "${INSTALLATION_FOLDER_PATH}/main.sh"

prefix="[pre-commit-snyk]"

container_build() {
tag="$1"
path="$2"
if command -v docker &> /dev/null; then
docker build -t "$tag" "$path"
elif command -v podman &> /dev/null; then
podman build -t "$tag" "$path"
else
echo "$prefix docker or podman are not found. Please install one of these tools and try again"
exit 1
fi
}

container_rmi() {
image="$1"
if command -v docker &> /dev/null; then
docker rmi "$(docker images "$image" -q)" || printf "\n%s Unable to remove %s" "$prefix" "$image"
elif command -v podman &> /dev/null; then
podman rmi "$(podman images "$image" -q)" || printf "\n%s Unable to remove %s" "$prefix" "$image"
else
echo "$prefix docker or podman are not found. Please install one of these tools and try again"
exit 1
fi
}

snyk_args=()
dockerfiles=()
Expand All @@ -13,22 +44,19 @@ for arg in "$@"; do
fi
done

prefix="[pre-commit-snyk]"

tag=$(date +%s)
i=1

for file_path in "${dockerfiles[@]}"; do
image="pre-commit-snyk:$tag-$i"
if [[ $i -gt 1 ]]
then
if [ $i -gt 1 ]; then
echo ""
fi
printf "%s Building %s from %s\n\n" "$prefix" "$image" "$file_path"
docker build -t "$image" "$(echo "$file_path" | rev | cut -d'/' -f2- | rev)"
container_build "$image" "$(echo "$file_path" | rev | cut -d'/' -f2- | rev)"
printf "\n%s Testing %s\n" "$prefix" "$image"
snyk container test "$image" "--file=$file_path" "${snyk_args[*]}"
printf "\n%s Removing %s" "$prefix" "$image"
docker rmi "$(docker images "$image" -q)" || printf "\n%s Unable to remove %s" "$prefix" "$image"
container_rmi "$image"
i=$((i + 1))
done
10 changes: 7 additions & 3 deletions hooks/snyk-iac.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
set -eu
SCRIPT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
bash "${SCRIPT_DIR}"/installation/main.sh

SCRIPT_PATH=$(realpath "$0")
HOOKS_FOLDER_PATH=$(dirname "${SCRIPT_PATH}")
INSTALLATION_FOLDER_PATH="${HOOKS_FOLDER_PATH}/installation"

sh "${INSTALLATION_FOLDER_PATH}/main.sh"

snyk iac test "$@"
10 changes: 7 additions & 3 deletions hooks/snyk-log4shell.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
set -eu
SCRIPT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
bash "${SCRIPT_DIR}"/installation/main.sh

SCRIPT_PATH=$(realpath "$0")
HOOKS_FOLDER_PATH=$(dirname "${SCRIPT_PATH}")
INSTALLATION_FOLDER_PATH="${HOOKS_FOLDER_PATH}/installation"

sh "${INSTALLATION_FOLDER_PATH}/main.sh"

snyk log4shell "$@"
10 changes: 7 additions & 3 deletions hooks/snyk-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
set -eu
SCRIPT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)"
bash "${SCRIPT_DIR}"/installation/main.sh

SCRIPT_PATH=$(realpath "$0")
HOOKS_FOLDER_PATH=$(dirname "${SCRIPT_PATH}")
INSTALLATION_FOLDER_PATH="${HOOKS_FOLDER_PATH}/installation"

sh "${INSTALLATION_FOLDER_PATH}/main.sh"

snyk test "$@"

2 comments on commit 9b618ed

@JayCork
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frontend developer here, so I don't have the details but one of the projects I work on uses this pre-commit, and I think this commit is causing issues. Sorry I can't be more helpful in recreatring.

Snyk Test................................................................Failed
- hook id: snyk-test
- duration: 0.01s
- exit code: 127

/opt/hostedtoolcache/node/20.12.2/x64/bin/snyk
/home/runner/.cache/pre-commit/repoc_u0qylc/hooks/installation/install-brew.sh: 4: brew: not found

@fabasoad
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically it checks if snyk is installed.. if no then it tries to install it via brew and if brew doesn't exist then it fails.

  1. What OS do you use?
  2. Can you check if snyk is installed on that machine?
  3. If it is macOS - can you check if brew is installed on that machine?

Please sign in to comment.