Files
moby/hack/buildkit-ref
Justin Chadwell f8c0d92a22 ci: extract buildkit version correctly with replace-d modules
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-07-17 14:17:49 +01:00

26 lines
1.1 KiB
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 '{{if .Replace}}{{.Replace.Version}}{{else}}{{.Version}}{{end}}' "github.com/${BUILDKIT_REPO}")
BUILDKIT_REPO=$(./hack/with-go-mod.sh go list -mod=mod -modfile=vendor.mod -u -m -f '{{if .Replace}}{{.Replace.Path}}{{else}}{{.Path}}{{end}}' "github.com/${BUILDKIT_REPO}")
BUILDKIT_REPO=${BUILDKIT_REPO#github.com/}
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_REPO=$BUILDKIT_REPO"
echo "BUILDKIT_REF=$BUILDKIT_REF"