moby/hack/buildkit-ref
Bjorn Neergaard 45fe08c93c
hack: replace go-mod-prepare.sh with wrapper script
To make the local build environment more correct and consistent, we
should never leave an uncommitted go.mod in the tree; however, we need a
go.mod for certain commands to work properly. Use a wrapper script to
create and destroy the go.mod as needed instead of potentially changing
tooling behavior by leaving it.

If a go.mod already exists, this script will warn and call the wrapped
command with GO111MODULE=on.

Signed-off-by: Bjorn Neergaard <bneergaard@mirantis.com>
(cherry picked from commit a449f77774)
Signed-off-by: Bjorn Neergaard <bneergaard@mirantis.com>
2022-12-13 14:42:05 -07:00

21 lines
828 B
Bash
Executable file

#!/usr/bin/env bash
# This script returns the current BuildKit ref being used in moby.
: "${BUILDKIT_REPO=moby/buildkit}"
: "${BUILDKIT_REF=}"
if [ -n "$BUILDKIT_REF" ]; then
echo "$BUILDKIT_REF"
exit 0
fi
# get buildkit version from vendor.mod
BUILDKIT_REF=$(./hack/with-go-mod.sh go list -mod=mod -modfile=vendor.mod -u -m -f '{{.Version}}' "github.com/${BUILDKIT_REPO}")
if [[ "${BUILDKIT_REF}" == *-*-* ]]; then
# if pseudo-version, figure out just the uncommon sha (https://github.com/golang/go/issues/34745)
BUILDKIT_REF=$(echo "${BUILDKIT_REF}" | awk -F"-" '{print $NF}' | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
# use github api to return full sha to be able to use it as ref
BUILDKIT_REF=$(curl -s "https://api.github.com/repos/${BUILDKIT_REPO}/commits/${BUILDKIT_REF}" | jq -r .sha)
fi
echo "$BUILDKIT_REF"