Merge pull request #46011 from thaJeztah/23.0_backport_buildkit_ref_replace

[23.0 backport] ci: extract buildkit version correctly with replace-d modules
This commit is contained in:
Bjorn Neergaard 2023-07-18 13:14:01 -06:00 committed by GitHub
commit 41712da47b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 16 deletions

View file

@ -69,7 +69,7 @@ jobs:
-
name: BuildKit ref
run: |
echo "BUILDKIT_REF=$(./hack/buildkit-ref)" >> $GITHUB_ENV
echo "$(./hack/buildkit-ref)" >> $GITHUB_ENV
working-directory: moby
-
name: Checkout BuildKit ${{ env.BUILDKIT_REF }}

View file

@ -1,21 +1,25 @@
#!/usr/bin/env bash
# This script returns the current BuildKit ref being used in moby.
# 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.
: "${BUILDKIT_REPO=moby/buildkit}"
: "${BUILDKIT_REF=}"
if [ -n "$BUILDKIT_REF" ]; then
echo "$BUILDKIT_REF"
exit 0
fi
buildkit_pkg=github.com/moby/buildkit
# get buildkit version from vendor.mod
BUILDKIT_REF=$(./hack/with-go-mod.sh go list -mod=mod -modfile=vendor.mod -u -m -f '{{.Version}}' "github.com/${BUILDKIT_REPO}")
if [[ "${BUILDKIT_REF}" == *-*-* ]]; then
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=$(echo "${BUILDKIT_REF}" | awk -F"-" '{print $NF}' | awk 'BEGIN{FIELDWIDTHS="7"} {print $1}')
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)
buildkit_ref=$(curl -s "https://api.github.com/repos/${buildkit_repo}/commits/${buildkit_ref}" | jq -r .sha)
fi
echo "$BUILDKIT_REF"
cat << EOF
BUILDKIT_REPO=$buildkit_repo
BUILDKIT_REF=$buildkit_ref
EOF

View file

@ -14,8 +14,10 @@ ROOTDIR="$(git -C "$SCRIPTDIR" rev-parse --show-toplevel)"
if test -e "${ROOTDIR}/go.mod"; then
{
scriptname=$(basename "$0")
echo "${scriptname}: WARN: go.mod exists in the repository root!"
echo "${scriptname}: WARN: Using your go.mod instead of our generated version -- this may misbehave!"
cat >&2 <<- EOF
$scriptname: WARN: go.mod exists in the repository root!
$scriptname: WARN: Using your go.mod instead of our generated version -- this may misbehave!
EOF
} >&2
else
set -x