Skip to content

Commit

Permalink
Merge pull request #12753 from simondeziel/static-analysis-improvements
Browse files Browse the repository at this point in the history
Improve `test/lint/golangci` script
  • Loading branch information
tomponline authored Jan 22, 2024
2 parents 91efd07 + 5fb0e64 commit d3c1928
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ endif
flake8 test/deps/import-busybox
shellcheck --shell sh test/*.sh test/includes/*.sh test/suites/*.sh test/backends/*.sh test/lint/*.sh
shellcheck test/extras/*.sh
run-parts --exit-on-error --regex '.sh' test/lint
run-parts --verbose --exit-on-error --regex '.sh' test/lint

.PHONY: staticcheck
staticcheck:
Expand Down
29 changes: 9 additions & 20 deletions test/lint/golangci.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh -eu

target_branch=""
# Default target branch.
target_branch="main"
if [ -n "${GITHUB_BASE_REF:-}" ]; then
# Target branch when scanning a Github pull request
target_branch="${GITHUB_BASE_REF}"
Expand All @@ -10,29 +11,17 @@ elif [ -n "${GITHUB_BEFORE:-}" ]; then
elif [ -n "${1:-}" ]; then
# Allow a target branch parameter.
target_branch="${1}"
else
# Default target branch.
for branch in main origin; do
if git show-ref --quiet "refs/heads/${branch}" >/dev/null 2>&1; then
target_branch="${branch}"
break
fi
done
fi

# Check if we found a target branch.
if [ -z "${target_branch}" ]; then
echo "The target branch for golangci couldn't be found, aborting."
false
fi

# Fetch the reference if it doesn't exist (Github uses a shallow clone).
if ! git show-ref --quiet "refs/heads/${target_branch}" --quiet >/dev/null 2>&1; then
git fetch origin "${target_branch}"
# Gets the most recent commit hash from the target branch.
rev="$(git log --max-count=1 --format=%H "origin/${target_branch}" || true)"
if [ -z "${rev}" ]; then
# actions/checkout creates shallow clones by default
echo "Convert shallow clone into treeless clone"
git fetch --filter=tree:0 origin "${target_branch}"
rev="$(git log --max-count=1 --format=%H "origin/${target_branch}")"
fi

# Gets the most recent commit hash from the target branch.
rev="$(git log "origin/${target_branch}" --oneline --no-abbrev-commit -n1 | cut -d' ' -f1)"
if [ -z "${rev}" ]; then
echo "No revision found for the tip of the target branch, aborting."
false
Expand Down

0 comments on commit d3c1928

Please sign in to comment.