Skip to content

Commit 4a0c506

Browse files
committed
ceph-source-dist: derive canonical BRANCH from SHA1
When SHA1 is provided, the checkout prefers it over BRANCH, but dist/branch echoed the BRANCH parameter verbatim. If the two disagreed, downstream consumers of dist/branch (ceph-dev-pipeline and, through it, chacra/shaman) would record the build under the wrong ref. Ask the remote which branch tips the built commit and reset BRANCH accordingly. The given BRANCH is kept when it already tips the commit (including when several branches share the tip) and, with a warning, when the commit is not the tip of any branch, since older commits are contained by many branches and there is no unambiguous answer. Fixes: https://tracker.ceph.com/issues/73658 Signed-off-by: David Galloway <david.galloway@ibm.com>
1 parent b2d1263 commit 4a0c506

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

ceph-source-dist/build/Jenkinsfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ pipeline {
107107
bzip2 -dc ceph-$ceph_version_tarball.$extension | gzip > ceph-$ceph_version_tarball.tar.gz
108108
popd
109109
else
110+
if [ -n "${SHA1:-}" ]; then
111+
# The checkout preferred SHA1 over BRANCH, so the BRANCH
112+
# parameter may not match the code actually built
113+
# (https://tracker.ceph.com/issues/73658). Keep BRANCH only
114+
# if its remote tip is the built commit; otherwise use the
115+
# branch whose tip is.
116+
sha=$(git rev-parse HEAD)
117+
git ls-remote --heads "${CEPH_REPO}" > remote_heads
118+
# Build an array of every branch whose tip is the built commit:
119+
# match ls-remote lines ("<sha> refs/heads/<branch>") on the sha
120+
# and strip the ref prefix, leaving just the branch names.
121+
mapfile -t tip_branches < <(awk -v sha="${sha}" '$1 == sha {sub("refs/heads/", "", $2); print $2}' remote_heads)
122+
rm -f remote_heads
123+
if [ "${#tip_branches[@]}" -eq 0 ]; then
124+
echo "WARNING: ${sha} is not the tip of any branch on ${CEPH_REPO}; keeping BRANCH=${BRANCH}"
125+
elif ! printf '%s\n' "${tip_branches[@]}" | grep -qxF "${BRANCH}"; then
126+
echo "BRANCH=${BRANCH} does not contain SHA1=${sha}; using ${tip_branches[0]}"
127+
BRANCH="${tip_branches[0]}"
128+
fi
129+
fi
110130
echo "BRANCH=${BRANCH}" > dist/branch
111131
fi
112132

0 commit comments

Comments
 (0)