mirror of
https://github.com/anchore/grype
synced 2024-11-10 14:44:12 +00:00
Remove git checkout from tidy check
Signed-off-by: Dan Luhring <dan.luhring@anchore.com>
This commit is contained in:
parent
81f68a1562
commit
ab85f428fa
1 changed files with 7 additions and 13 deletions
20
.github/scripts/go-mod-tidy-check.sh
vendored
20
.github/scripts/go-mod-tidy-check.sh
vendored
|
@ -1,19 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
BACKUPS_DIR=$(mktemp -d "TEMP-backups-XXXXXXXXX")
|
ORIGINAL_STATE_DIR=$(mktemp -d "TEMP-original-state-XXXXXXXXX")
|
||||||
GIT_HEAD_STATE_DIR=$(mktemp -d "TEMP-git-head-state-XXXXXXXXX")
|
|
||||||
TIDY_STATE_DIR=$(mktemp -d "TEMP-tidy-state-XXXXXXXXX")
|
TIDY_STATE_DIR=$(mktemp -d "TEMP-tidy-state-XXXXXXXXX")
|
||||||
|
|
||||||
trap "cp -v ${BACKUPS_DIR}/* ./ && rm -fR ${BACKUPS_DIR} ${GIT_HEAD_STATE_DIR} ${TIDY_STATE_DIR}" EXIT
|
trap "cp -v ${ORIGINAL_STATE_DIR}/* ./ && rm -fR ${ORIGINAL_STATE_DIR} ${TIDY_STATE_DIR}" EXIT
|
||||||
|
|
||||||
echo "Backing up files from working tree..."
|
echo "Capturing original state of files..."
|
||||||
cp -v go.mod go.sum "${BACKUPS_DIR}"
|
cp -v go.mod go.sum "${ORIGINAL_STATE_DIR}"
|
||||||
|
|
||||||
echo "Capturing state of go.mod and go.sum from git HEAD..."
|
|
||||||
git checkout go.mod go.sum
|
|
||||||
cp -v go.mod go.sum "${GIT_HEAD_STATE_DIR}"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo "Capturing state of go.mod and go.sum after running go mod tidy..."
|
echo "Capturing state of go.mod and go.sum after running go mod tidy..."
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
@ -23,8 +17,8 @@ echo ""
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
# Detect difference between the git HEAD state and the go mod tidy state
|
# Detect difference between the git HEAD state and the go mod tidy state
|
||||||
DIFF_MOD=$(diff -u "${GIT_HEAD_STATE_DIR}/go.mod" "${TIDY_STATE_DIR}/go.mod")
|
DIFF_MOD=$(diff -u "${ORIGINAL_STATE_DIR}/go.mod" "${TIDY_STATE_DIR}/go.mod")
|
||||||
DIFF_SUM=$(diff -u "${GIT_HEAD_STATE_DIR}/go.sum" "${TIDY_STATE_DIR}/go.sum")
|
DIFF_SUM=$(diff -u "${ORIGINAL_STATE_DIR}/go.sum" "${TIDY_STATE_DIR}/go.sum")
|
||||||
|
|
||||||
if [[ -n "${DIFF_MOD}" || -n "${DIFF_SUM}" ]]; then
|
if [[ -n "${DIFF_MOD}" || -n "${DIFF_SUM}" ]]; then
|
||||||
echo "go.mod diff:"
|
echo "go.mod diff:"
|
||||||
|
@ -32,6 +26,6 @@ if [[ -n "${DIFF_MOD}" || -n "${DIFF_SUM}" ]]; then
|
||||||
echo "go.sum diff:"
|
echo "go.sum diff:"
|
||||||
echo "${DIFF_SUM}"
|
echo "${DIFF_SUM}"
|
||||||
echo ""
|
echo ""
|
||||||
printf "FAILED! go.mod and/or go.sum are NOT tidy on current git head; please run 'go mod tidy' and commit the change.\n\n"
|
printf "FAILED! go.mod and/or go.sum are NOT tidy; please run 'go mod tidy'.\n\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue