Skip to content

Commit 99a6e02

Browse files
LUwUcifermikehardy
authored andcommitted
Automate sync_translations workflow for 30 minute delays
1 parent d529ff1 commit 99a6e02

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

.github/workflows/sync_translations.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ name: 🌐 Sync Translations
33
on:
44
workflow_dispatch:
55

6+
concurrency:
7+
group: sync-translations
8+
cancel-in-progress: true
9+
610
# We use a machine account PAT from secrets so workflows are triggered
711
# the default token is not needed and should be fully restricted
812
permissions: {}
913

1014
jobs:
1115
sync_translations:
1216
name: 'Sync Translations with Crowdin'
13-
timeout-minutes: 20
17+
timeout-minutes: 50
1418
runs-on: ubuntu-latest
1519
steps:
1620
- uses: actions/checkout@v6
@@ -32,6 +36,28 @@ jobs:
3236
git reset --hard origin/main
3337
shell: bash
3438

39+
- name: Get second to latest run time
40+
env:
41+
GH_TOKEN: ${{ secrets.MACHINE_ACCOUNT_PAT }}
42+
run: |
43+
OUTPUT=$(gh run list --workflow sync_translations.yml --json updatedAt | jq -r '.[1].updatedAt')
44+
echo "LATEST_RUN=$OUTPUT" >> $GITHUB_ENV
45+
46+
- name: Calculate seconds passed
47+
id: calc_time
48+
uses: actions/github-script@v8
49+
with:
50+
script: |
51+
const lastRun = new Date(process.env.LATEST_RUN);
52+
const secondsPassed = Math.floor((Date.now() - lastRun.getTime()) / 1000);
53+
const timeLeft = 1800 - secondsPassed > 0 ? 1800 - secondsPassed: 0;
54+
console.log('Seconds to sleep for: ' + timeLeft);
55+
core.setOutput('time_left', timeLeft);
56+
57+
- name: Await CrowdIn API Cooldown If Needed
58+
if: steps.calc_time.outputs.time_left > 0
59+
run: sleep ${{ steps.calc_time.outputs.time_left }}
60+
3561
- uses: actions/setup-node@v6
3662
with:
3763
node-version: 20

0 commit comments

Comments
 (0)