Skip to content

Commit

Permalink
Merge pull request #222 from Nordix/tuomo/fix-gomod-1.1
Browse files Browse the repository at this point in the history
🐛 cherry-pick gomod.sh fixes from main
  • Loading branch information
metal3-io-bot authored Mar 27, 2023
2 parents df27b3a + a22b5c9 commit 9c0d48e
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions hack/gomod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,40 @@
#
# NOTE: This won't work unless the build environment has internet access

set -ux
set -eux

IS_CONTAINER=${IS_CONTAINER:-false}
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"

if [ "${IS_CONTAINER}" != "false" ]; then
export XDG_CACHE_HOME="/tmp/.cache"
export XDG_CACHE_HOME=/tmp/.cache

STATUS=$(git status --porcelain)
if [ -n "$STATUS" ]; then
echo "Dirty tree: refusing to continue out of caution"
exit 1
fi
mkdir /tmp/gomod
cp -r . /tmp/gomod
cd /tmp/gomod

go mod tidy
rc=$?
STATUS="$(git status --porcelain)"
if [ -n "${STATUS}" ]; then
echo "Dirty tree: refusing to continue out of caution"
exit 1
fi

if [ $rc -ne 0 ]; then
echo "'go mod tidy' failed"
exit 1;
fi
make modules

STATUS=$(git status --porcelain go.mod go.sum)
if [ -n "$STATUS" ]; then
echo "go.mod and go.sum changed"
echo "Please run 'go mod tidy' and commit the changes to go.mod & go.sum."
echo "Abort"
exit 1
fi

exit 0;
STATUS="$(git status --porcelain)"
if [ -n "${STATUS}" ]; then
echo "one of the go.mod and/or go.sum files changed"
echo "${STATUS}"
echo "Please run 'go mod tidy' and commit the changes"
exit 1
fi

else
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/metal3-ipam:ro,z" \
--entrypoint sh \
--workdir /metal3-ipam \
registry.hub.docker.com/library/golang:1.17 \
/metal3-ipam/hack/gomod.sh "${@}"
fi;
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/workdir:ro,z" \
--entrypoint sh \
--workdir /workdir \
docker.io/golang:1.17 \
/workdir/hack/gomod.sh "$@"
fi

0 comments on commit 9c0d48e

Please sign in to comment.