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>
| ... | ... |
@@ -1,8 +1,12 @@ |
| 1 | 1 |
#!/usr/bin/env bash |
| 2 |
-# This script returns the current BuildKit ref being used in moby. |
|
| 2 |
+# This script returns the current BuildKit ref and source repository being used. |
|
| 3 |
+# This script will only work with a BuildKit repository hosted on GitHub. |
|
| 4 |
+# If BUILDKIT_REF is already set in the environment, it will be returned as-is. |
|
| 5 |
+# |
|
| 6 |
+# The output of this script may be valid shell script, but is intended for use with |
|
| 7 |
+# GitHub Actions' $GITHUB_ENV. |
|
| 3 | 8 |
|
| 4 |
-: "${BUILDKIT_REPO=moby/buildkit}"
|
|
| 5 |
-: "${BUILDKIT_REF=}"
|
|
| 9 |
+buildkit_pkg=github.com/moby/buildkit |
|
| 6 | 10 |
|
| 7 | 11 |
if [ -n "$BUILDKIT_REF" ]; then |
| 8 | 12 |
echo "$BUILDKIT_REF" |
| ... | ... |
@@ -10,16 +14,18 @@ if [ -n "$BUILDKIT_REF" ]; then |
| 10 | 10 |
fi |
| 11 | 11 |
|
| 12 | 12 |
# get buildkit version from vendor.mod |
| 13 |
-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}")
|
|
| 14 |
-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}")
|
|
| 15 |
-BUILDKIT_REPO=${BUILDKIT_REPO#github.com/}
|
|
| 13 |
+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")
|
|
| 14 |
+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")
|
|
| 15 |
+buildkit_repo=${buildkit_repo#github.com/}
|
|
| 16 | 16 |
|
| 17 |
-if [[ "${BUILDKIT_REF}" == *-*-* ]]; then
|
|
| 17 |
+if [[ "${buildkit_ref}" == *-*-* ]]; then
|
|
| 18 | 18 |
# if pseudo-version, figure out just the uncommon sha (https://github.com/golang/go/issues/34745) |
| 19 |
- BUILDKIT_REF=$(echo "${BUILDKIT_REF}" | awk -F"-" '{print $NF}' | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
|
|
| 19 |
+ buildkit_ref=$(awk -F"-" '{print $NF}' <<< "$buildkit_ref" | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
|
|
| 20 | 20 |
# use github api to return full sha to be able to use it as ref |
| 21 |
- BUILDKIT_REF=$(curl -s "https://api.github.com/repos/${BUILDKIT_REPO}/commits/${BUILDKIT_REF}" | jq -r .sha)
|
|
| 21 |
+ buildkit_ref=$(curl -s "https://api.github.com/repos/${buildkit_repo}/commits/${buildkit_ref}" | jq -r .sha)
|
|
| 22 | 22 |
fi |
| 23 | 23 |
|
| 24 |
-echo "BUILDKIT_REPO=$BUILDKIT_REPO" |
|
| 25 |
-echo "BUILDKIT_REF=$BUILDKIT_REF" |
|
| 24 |
+cat << EOF |
|
| 25 |
+BUILDKIT_REPO=$buildkit_repo |
|
| 26 |
+BUILDKIT_REF=$buildkit_ref |
|
| 27 |
+EOF |