buildkit-ref 1.2 KB

12345678910111213141516171819202122232425
  1. #!/usr/bin/env bash
  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. #
  5. # The output of this script may be valid shell script, but is intended for use with
  6. # GitHub Actions' $GITHUB_ENV.
  7. buildkit_pkg=github.com/moby/buildkit
  8. # get buildkit version from vendor.mod
  9. 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")
  10. 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")
  11. buildkit_repo=${buildkit_repo#github.com/}
  12. if [[ "${buildkit_ref}" == *-*-* ]]; then
  13. # if pseudo-version, figure out just the uncommon sha (https://github.com/golang/go/issues/34745)
  14. buildkit_ref=$(awk -F"-" '{print $NF}' <<< "$buildkit_ref" | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
  15. # use github api to return full sha to be able to use it as ref
  16. buildkit_ref=$(curl -s "https://api.github.com/repos/${buildkit_repo}/commits/${buildkit_ref}" | jq -r .sha)
  17. fi
  18. cat << EOF
  19. BUILDKIT_REPO=$buildkit_repo
  20. BUILDKIT_REF=$buildkit_ref
  21. EOF