2022-03-22 09:58:01 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-07-18 14:12:02 +00:00
|
|
|
# This script returns the current BuildKit ref and source repository being used.
|
|
|
|
# This script will only work with a BuildKit repository hosted on GitHub.
|
|
|
|
#
|
|
|
|
# The output of this script may be valid shell script, but is intended for use with
|
|
|
|
# GitHub Actions' $GITHUB_ENV.
|
2022-03-22 09:58:01 +00:00
|
|
|
|
2023-07-18 14:12:02 +00:00
|
|
|
buildkit_pkg=github.com/moby/buildkit
|
2022-03-22 09:58:01 +00:00
|
|
|
|
|
|
|
# get buildkit version from vendor.mod
|
2023-07-18 14:12:02 +00:00
|
|
|
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/}
|
2023-07-17 13:15:57 +00:00
|
|
|
|
2023-07-18 14:12:02 +00:00
|
|
|
if [[ "${buildkit_ref}" == *-*-* ]]; then
|
2022-03-22 09:58:01 +00:00
|
|
|
# if pseudo-version, figure out just the uncommon sha (https://github.com/golang/go/issues/34745)
|
2023-07-18 14:12:02 +00:00
|
|
|
buildkit_ref=$(awk -F"-" '{print $NF}' <<< "$buildkit_ref" | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
|
2022-03-22 09:58:01 +00:00
|
|
|
# use github api to return full sha to be able to use it as ref
|
2023-07-18 14:12:02 +00:00
|
|
|
buildkit_ref=$(curl -s "https://api.github.com/repos/${buildkit_repo}/commits/${buildkit_ref}" | jq -r .sha)
|
2022-03-22 09:58:01 +00:00
|
|
|
fi
|
|
|
|
|
2023-07-18 14:12:02 +00:00
|
|
|
cat << EOF
|
|
|
|
BUILDKIT_REPO=$buildkit_repo
|
|
|
|
BUILDKIT_REF=$buildkit_ref
|
|
|
|
EOF
|