4ecc01f3ad
Post-f8c0d92a22bad004cb9cbb4db704495527521c42, BUILDKIT_REPO doesn't really do what it claims to. Instead, don't allow overloading since the import path for BuildKit is always the same, and make clear the provenance of values when generating the final variable definitions. We also better document the script, and follow some best practices for both POSIX sh and Bash. Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
31 lines
1.3 KiB
Bash
Executable file
31 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# This script returns the current BuildKit ref and source repository being used.
|
|
# This script will only work with a BuildKit repository hosted on GitHub.
|
|
# If BUILDKIT_REF is already set in the environment, it will be returned as-is.
|
|
#
|
|
# The output of this script may be valid shell script, but is intended for use with
|
|
# GitHub Actions' $GITHUB_ENV.
|
|
|
|
buildkit_pkg=github.com/moby/buildkit
|
|
|
|
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}}' "$buildkit_pkg")
|
|
buildkit_repo=$(./hack/with-go-mod.sh go list -mod=mod -modfile=vendor.mod -u -m -f '{{if .Replace}}{{.Replace.Path}}{{else}}{{.Path}}{{end}}' "$buildkit_pkg")
|
|
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=$(awk -F"-" '{print $NF}' <<< "$buildkit_ref" | 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
|
|
|
|
cat << EOF
|
|
BUILDKIT_REPO=$buildkit_repo
|
|
BUILDKIT_REF=$buildkit_ref
|
|
EOF
|