Skip to content

Commit d625a03

Browse files
committed
improving sync when no pr is necessary
1 parent 0e01cac commit d625a03

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

.github/workflows/sync_translations.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v6
2121
with:
22-
token: ${{ secrets.MACHINE_ACCOUNT_PAT }}
22+
token: ${{ secrets.GITHUB_TOKEN }}
2323
ref: 'main'
2424
fetch-depth: 0
2525

@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: Get second to latest run time
4040
env:
41-
GH_TOKEN: ${{ secrets.MACHINE_ACCOUNT_PAT }}
41+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4242
run: |
4343
OUTPUT=$(gh run list --workflow sync_translations.yml --json updatedAt | jq -r '.[1].updatedAt')
4444
echo "LATEST_RUN=$OUTPUT" >> $GITHUB_ENV
@@ -50,7 +50,7 @@ jobs:
5050
script: |
5151
const lastRun = new Date(process.env.LATEST_RUN);
5252
const secondsPassed = Math.floor((Date.now() - lastRun.getTime()) / 1000);
53-
const timeLeft = 1800 - secondsPassed > 0 ? 1800 - secondsPassed: 0;
53+
const timeLeft = 10 - secondsPassed > 0 ? 10 - secondsPassed: 0;
5454
console.log('Seconds to sleep for: ' + timeLeft);
5555
core.setOutput('time_left', timeLeft);
5656
@@ -69,49 +69,51 @@ jobs:
6969
yarn build
7070
7171
- name: Push translation sources to crowdin
72+
continue-on-error: true
7273
run: |
7374
cd ./tools/localization
7475
yarn start upload
7576
7677
- name: Pull translation updates from crowdin
78+
continue-on-error: true
7779
run: |
7880
cd ./tools/localization
7981
yarn start download
8082
8183
- name: Extract downloaded ankidroid.zip file
84+
continue-on-error: true
8285
run: |
8386
cd ./tools/localization
8487
yarn start extract
8588
8689
- name: Update translation to AnkiDroid res
90+
continue-on-error: true
8791
run: |
8892
cd ./tools/localization
8993
yarn start update
9094
91-
- name: Commit changes
92-
run: |
93-
git add docs/marketing/localized_description AnkiDroid/src/main/res
94-
git commit -am 'Updated strings from Crowdin'
95-
git push --set-upstream origin +i18n_sync
96-
echo "The results of the sync are on the i18n_sync branch, PR them from there for merge."
97-
echo "https://github.com/ankidroid/Anki-Android/compare/i18n_sync?expand=1"
98-
99-
- name: Check if there are strings changes
95+
- name: Check for changes and handle results
10096
id: tr_check
10197
run: |
102-
git checkout i18n_sync
103-
COMMITS_COUNT=`git rev-list --count HEAD ^main`
104-
if [ "$COMMITS_COUNT" -gt 0 ]; then
105-
echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT
106-
else
98+
git add docs/marketing/localized_description AnkiDroid/src/main/res
99+
if git diff --cached --quiet; then
107100
echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT
101+
echo "### 🌐 Translation Sync Result" >> $GITHUB_STEP_SUMMARY
102+
echo ":heavy_check_mark: No new translation found on Crowdin. No Pull Request necessary" >> $GITHUB_STEP_SUMMARY
103+
else
104+
echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT
105+
git commit -m 'Updated strings from Crowdin'
106+
git push --set-upstream origin +i18n_sync
107+
echo "### 🌐 Translation Sync Result" >> $GITHUB_STEP_SUMMARY
108+
echo ":rocket: New translations found and pushed to branch \`i18n_sync\`" >> $GITHUB_STEP_SUMMARY
108109
fi
110+
shell: bash
109111

110112
- name: Create PR for strings changes if needed
111-
if: ${{ steps.tr_check.outputs.HAS_CHANGES }}
113+
if: steps.tr_check.outputs.HAS_CHANGES == 'true'
112114
uses: actions/github-script@v9
113115
with:
114-
github-token: ${{ secrets.MACHINE_ACCOUNT_PAT }}
116+
github-token: ${{ secrets.GITHUB_TOKEN }}
115117
script: |
116118
const now = new Date();
117119
// Date format used: YYYY/MM/DD HH:MM , UTC time(ex: 2023/01/13 08:38)

0 commit comments

Comments
 (0)