Skip to content

Commit d10e2dc

Browse files
committed
Use retry logic when pushing to a joint branch
1 parent 5463a97 commit d10e2dc

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

.github/workflows/check-new-library-versions-in-batch.yml

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,53 @@ jobs:
144144
FAILED_VERSION=$(grep "^FAILED:" test_results.txt | sed 's/FAILED://g')
145145
echo "failed_version=$FAILED_VERSION" >> $GITHUB_OUTPUT
146146
147-
- name: "✔️ New library versions are supported"
147+
- name: "✔️ New library versions are supported (with locks, waiting and retries)"
148148
if: steps.runtests.outputs.successful_versions != ''
149+
env:
150+
BRANCH: ${{ needs.get-all-libraries.outputs.branch }}
149151
run: |
152+
set -euo pipefail
150153
git config --local user.email "[email protected]"
151154
git config --local user.name "Github Actions"
152-
git fetch origin ${{ needs.get-all-libraries.outputs.branch }}
153-
git checkout ${{ needs.get-all-libraries.outputs.branch }}
154155
155-
while read version; do
156-
if [ -n "$version" ]; then
157-
./gradlew addTestedVersion --coordinates="${{ matrix.item.name }}:$version" --lastSupportedVersion="${{ env.LATEST_VERSION }}"
156+
update_new_versions() {
157+
while read version; do
158+
if [ -n "$version" ]; then
159+
./gradlew addTestedVersion --coordinates="${{ matrix.item.name }}:$version" --lastSupportedVersion="${{ env.LATEST_VERSION }}"
160+
fi
161+
done < successful_versions.txt
162+
}
163+
164+
# Small jitter to reduce contention start
165+
sleep $((RANDOM % 5 + 1))
166+
167+
for i in {1..10}; do
168+
# Always start from the latest remote state
169+
git fetch origin "$BRANCH"
170+
git checkout -B "$BRANCH" "origin/$BRANCH"
171+
172+
update_new_versions
173+
174+
# If nothing changed, exit early
175+
if git status --porcelain | grep -q .; then
176+
git add -u
177+
git commit -m "Update tested versions for ${{ matrix.item.name }}"
178+
else
179+
echo "No changes to commit for ${{ matrix.item.name }}."
180+
exit 0
158181
fi
159-
done < successful_versions.txt
160182
161-
git add -u
162-
git commit -m "Update tested versions for ${{ matrix.item.name }}"
163-
git push origin ${{ needs.get-all-libraries.outputs.branch }}
183+
if git push origin "$BRANCH"; then
184+
echo "Pushed successfully."
185+
exit 0
186+
fi
187+
188+
echo "Push failed (likely concurrent update). Waiting and retrying..."
189+
sleep 5
190+
done
191+
192+
echo "Timed out waiting to push updates after concurrent jobs."
193+
exit 1
164194
165195
- name: "❗ New library version is not supported"
166196
if: steps.runtests.outputs.failed_version != ''

0 commit comments

Comments
 (0)