mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
fix go module tidy checks for release pipeline
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
93b4bf9379
commit
d25d3b1fb3
26
.github/scripts/go-mod-tidy-check.sh
vendored
26
.github/scripts/go-mod-tidy-check.sh
vendored
@ -1,27 +1,31 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -u
|
set -eu
|
||||||
|
|
||||||
TMP_GOMOD=$(mktemp)
|
ORIGINAL_STATE_DIR=$(mktemp -d "TEMP-original-state-XXXXXXXXX")
|
||||||
TMP_GOSUM=$(mktemp)
|
TIDY_STATE_DIR=$(mktemp -d "TEMP-tidy-state-XXXXXXXXX")
|
||||||
|
|
||||||
trap "rm -f ${TMP_GOSUM} ${TMP_GOMOD}" EXIT
|
trap "cp -v ${ORIGINAL_STATE_DIR}/* ./ && rm -fR ${ORIGINAL_STATE_DIR} ${TIDY_STATE_DIR}" EXIT
|
||||||
|
|
||||||
cp go.mod "${TMP_GOMOD}"
|
echo "Capturing original state of files..."
|
||||||
cp go.sum "${TMP_GOSUM}"
|
cp -v go.mod go.sum "${ORIGINAL_STATE_DIR}"
|
||||||
|
|
||||||
|
echo "Capturing state of go.mod and go.sum after running go mod tidy..."
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
cp -v go.mod go.sum "${TIDY_STATE_DIR}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
DIFF_MOD=$(diff -u "${TMP_GOMOD}" go.mod)
|
set +e
|
||||||
DIFF_SUM=$(diff -u "${TMP_GOSUM}" go.sum)
|
|
||||||
|
|
||||||
cp "${TMP_GOMOD}" go.mod
|
# Detect difference between the git HEAD state and the go mod tidy state
|
||||||
cp "${TMP_GOSUM}" go.sum
|
DIFF_MOD=$(diff -u "${ORIGINAL_STATE_DIR}/go.mod" "${TIDY_STATE_DIR}/go.mod")
|
||||||
|
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 and/or go.sum are not tidy; please run go mod tidy"
|
|
||||||
echo "go.mod diff:"
|
echo "go.mod diff:"
|
||||||
echo "${DIFF_MOD}"
|
echo "${DIFF_MOD}"
|
||||||
echo "go.sum diff:"
|
echo "go.sum diff:"
|
||||||
echo "${DIFF_SUM}"
|
echo "${DIFF_SUM}"
|
||||||
|
echo ""
|
||||||
|
printf "FAILED! go.mod and/or go.sum are NOT tidy; please run 'go mod tidy'.\n\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
1
Makefile
1
Makefile
@ -108,7 +108,6 @@ bootstrap-tools: $(TEMPDIR)
|
|||||||
.PHONY: bootstrap-go
|
.PHONY: bootstrap-go
|
||||||
bootstrap-go:
|
bootstrap-go:
|
||||||
go mod download
|
go mod download
|
||||||
go mod tidy # note: it is important that the go.sum is kept in a consistent state at all times (especially during release)
|
|
||||||
|
|
||||||
.PHONY: bootstrap
|
.PHONY: bootstrap
|
||||||
bootstrap: $(RESULTSDIR) bootstrap-go bootstrap-tools ## Download and install all go dependencies (+ prep tooling in the ./tmp dir)
|
bootstrap: $(RESULTSDIR) bootstrap-go bootstrap-tools ## Download and install all go dependencies (+ prep tooling in the ./tmp dir)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user