CICD: Fix the Version Number Generation

Fix the script used to generate version numbers for CICD builds. If
there is a race condition and we are not the first to create the branch
named after the lates changeset id, go and do a `git pull` before
attempting to read the branch that was created by another process.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2025-01-01 17:48:07 +13:00
parent 4528c56eaf
commit 5c22db022f

View file

@ -18,7 +18,7 @@ cd nightly-builds
latest=$(<latest-subsurface-buildnumber) latest=$(<latest-subsurface-buildnumber)
# now let's see if a branch for the current SHA exists # now let's see if a branch for the current SHA exists
if git checkout "$SHA_BRANCH" if git switch "$SHA_BRANCH"
then then
# one of the other workflows created a release number already # one of the other workflows created a release number already
latest=$(<latest-subsurface-buildnumber) latest=$(<latest-subsurface-buildnumber)
@ -27,7 +27,9 @@ else
# the main branch should have held the previous release number # the main branch should have held the previous release number
# increment by one and write as new build number into the named branch # increment by one and write as new build number into the named branch
latest=$((latest+1)) latest=$((latest+1))
git checkout -b "$SHA_BRANCH" echo "new build number is $latest"
git switch -c "$SHA_BRANCH"
echo $latest > latest-subsurface-buildnumber echo $latest > latest-subsurface-buildnumber
git commit -a -m "record build number for this SHA" git commit -a -m "record build number for this SHA"
@ -36,7 +38,7 @@ else
if git push origin "$SHA_BRANCH" if git push origin "$SHA_BRANCH"
then then
# yay - we win! now let's make sure that we remember this number for next time # yay - we win! now let's make sure that we remember this number for next time
git checkout main git switch main
echo $latest > latest-subsurface-buildnumber echo $latest > latest-subsurface-buildnumber
git commit -a -m "record latest build number in main branch" git commit -a -m "record latest build number in main branch"
if ! git push origin main if ! git push origin main
@ -46,9 +48,10 @@ else
fi fi
else else
# someone else was faster - get the number they wrote # someone else was faster - get the number they wrote
git checkout main &> /dev/null git switch main
git branch -D "$SHA_BRANCH" &> /dev/null git branch -D "$SHA_BRANCH"
if ! git checkout "$SHA_BRANCH" git pull
if ! git switch "$SHA_BRANCH"
then then
echo "push to $SHA_BRANCH failed, but switching to it failed as well" echo "push to $SHA_BRANCH failed, but switching to it failed as well"
exit 2 exit 2