Skip to content

Commit 9f8b36d

Browse files
committed
CI: prevent redundant translation sync runs and enforce 30-minute gap
- Add concurrency control to prevent overlapping runs - Cancel in-progress runs when new one is triggered - Enforce minimum 30-minute gap between syncs (not fixed delay) - Check last commit time on i18n_sync branch - Calculate remaining wait time dynamically - Proceed immediately if >= 30 minutes have passed - Add defensive guard against negative sleep values - Improve log clarity by showing elapsed time in seconds - Update timeout from 20 to 50 minutes - Fix action versions to v4 (checkout and setup-node)
1 parent e552265 commit 9f8b36d

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

.github/workflows/sync_translations.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,64 @@ name: 🌐 Sync Translations
33
on:
44
workflow_dispatch:
55

6+
# Ensure only one sync workflow runs at a time
7+
# Cancel any in-progress runs when a new one is triggered
8+
concurrency:
9+
group: translation-sync
10+
cancel-in-progress: true
11+
612
# We use a machine account PAT from secrets so workflows are triggered
713
# the default token is not needed and should be fully restricted
814
permissions: {}
915

1016
jobs:
1117
sync_translations:
1218
name: 'Sync Translations with Crowdin'
13-
timeout-minutes: 20
19+
timeout-minutes: 50
1420
runs-on: ubuntu-latest
1521
steps:
16-
- uses: actions/checkout@v6
22+
- uses: actions/checkout@v4
1723
with:
1824
token: ${{ secrets.MACHINE_ACCOUNT_PAT }}
1925
ref: 'main'
2026
fetch-depth: 0
2127

28+
- name: Enforce minimum 30-minute gap between syncs
29+
run: |
30+
echo "Checking last sync time to enforce 30-minute minimum gap..."
31+
32+
# Fetch the i18n_sync branch to check last sync time
33+
git fetch origin i18n_sync:i18n_sync 2>/dev/null || true
34+
35+
# Get timestamp of last commit on i18n_sync (if it exists)
36+
if git rev-parse --verify i18n_sync >/dev/null 2>&1; then
37+
LAST_SYNC_TIME=$(git log -1 --format=%ct i18n_sync)
38+
CURRENT_TIME=$(date +%s)
39+
ELAPSED=$((CURRENT_TIME - LAST_SYNC_TIME))
40+
REMAINING=$((1800 - ELAPSED))
41+
42+
# Defensive: ensure REMAINING is never negative
43+
if [ $REMAINING -lt 0 ]; then
44+
REMAINING=0
45+
fi
46+
47+
if [ $REMAINING -gt 0 ]; then
48+
MINUTES=$((REMAINING / 60))
49+
SECONDS=$((REMAINING % 60))
50+
echo "Last sync was $ELAPSED seconds ago."
51+
echo "Waiting $MINUTES minutes and $SECONDS seconds to respect Crowdin rate limiting..."
52+
echo "Sync will start at: $(date -u -d "+${REMAINING} seconds" '+%Y-%m-%d %H:%M:%S UTC')"
53+
sleep $REMAINING
54+
else
55+
echo "Last sync was $ELAPSED seconds ago (≥30 min)."
56+
echo "Proceeding immediately."
57+
fi
58+
else
59+
echo "No previous sync found on i18n_sync branch."
60+
echo "Proceeding immediately."
61+
fi
62+
shell: bash
63+
2264
- name: Credential Prep
2365
run: |
2466
echo "CROWDIN_APIv2_PAT=${{ secrets.CROWDIN_APIv2_PAT }}" >> $GITHUB_ENV
@@ -32,7 +74,7 @@ jobs:
3274
git reset --hard origin/main
3375
shell: bash
3476

35-
- uses: actions/setup-node@v6
77+
- uses: actions/setup-node@v4
3678
with:
3779
node-version: 20
3880

0 commit comments

Comments
 (0)