@@ -9,7 +9,10 @@ concurrency:
99
1010# We use a machine account PAT from secrets so workflows are triggered
1111# the default token is not needed and should be fully restricted
12- permissions : {}
12+ permissions :
13+ contents : write
14+ pull-requests : write
15+ checks : write
1316
1417jobs :
1518 sync_translations :
1922 steps :
2023 - uses : actions/checkout@v6
2124 with :
22- token : ${{ secrets.MACHINE_ACCOUNT_PAT }}
25+ token : ${{ secrets.GITHUB_TOKEN }}
2326 ref : ' main'
2427 fetch-depth : 0
2528
3841
3942 - name : Get second to latest run time
4043 env :
41- GH_TOKEN : ${{ secrets.MACHINE_ACCOUNT_PAT }}
44+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4245 run : |
4346 OUTPUT=$(gh run list --workflow sync_translations.yml --json updatedAt | jq -r '.[1].updatedAt')
4447 echo "LATEST_RUN=$OUTPUT" >> $GITHUB_ENV
5053 script : |
5154 const lastRun = new Date(process.env.LATEST_RUN);
5255 const secondsPassed = Math.floor((Date.now() - lastRun.getTime()) / 1000);
53- const timeLeft = 1800 - secondsPassed > 0 ? 1800 - secondsPassed: 0;
56+ const timeLeft = 10 - secondsPassed > 0 ? 10 - secondsPassed: 0;
5457 console.log('Seconds to sleep for: ' + timeLeft);
5558 core.setOutput('time_left', timeLeft);
5659
@@ -69,49 +72,74 @@ jobs:
6972 yarn build
7073
7174 - name : Push translation sources to crowdin
72- run : |
73- cd ./tools/localization
74- yarn start upload
75+ # run: |
76+ # cd ./tools/localization
77+ # yarn start upload
78+ run : echo "Skipping update for testing"
7579
7680 - name : Pull translation updates from crowdin
77- run : |
78- cd ./tools/localization
79- yarn start download
81+ # run: |
82+ # cd ./tools/localization
83+ # yarn start download
84+ run : echo "Skipping update for testing"
8085
8186 - name : Extract downloaded ankidroid.zip file
82- run : |
83- cd ./tools/localization
84- yarn start extract
87+ # run: |
88+ # cd ./tools/localization
89+ # yarn start extract
90+ run : echo "Skipping update for testing"
8591
8692 - name : Update translation to AnkiDroid res
87- run : |
88- cd ./tools/localization
89- yarn start update
93+ # run: |
94+ # cd ./tools/localization
95+ # yarn start update
96+ run : echo "Skipping update for testing"
9097
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
98+ - name : Check for changes and handle Neutral result
10099 id : tr_check
101- 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
107- echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT
108- fi
100+ if : always()
101+ uses : actions/github-script@v7
102+ with :
103+ script : |
104+ const { execSync } = require('child_process');
105+
106+ try {
107+ execSync('git add docs/marketing/localized_description AnkiDroid/src/main/res');
108+ } catch (e) {
109+ console.log("No files found to step, continuing...")
110+ }
111+
112+ const status = execSync('git diff --cached --name-only').toString().trim();
113+
114+ if(!status) {
115+ console.log("No changes detected. Setting status to neutral.");
116+
117+ await github.rest.checks.create({
118+ owner: context.repo.owner,
119+ repo: context.repo.repo,
120+ name: 'Sync Translations with Crowdin',
121+ head_sha: context.sha,
122+ status: 'completed',
123+ conclusion: 'neutral',
124+ output: {
125+ title: 'Translation Sync',
126+ summary: 'No translation changes were found on Crowdin to sync'
127+ }
128+ });
129+
130+ core.setOutput('HAS_CHANGES', 'false');
131+ } else {
132+ core.setOutput('HAS_CHANGES', 'true');
133+ execSync("git commit -m 'Updated strings from Crowdin'");
134+ execSync("git push --set-upstream origin +i18n_sync");
135+ console.log("Changes pushed to i18n_sync branch");
136+ }
109137
110138 - name : Create PR for strings changes if needed
111- if : ${{ steps.tr_check.outputs.HAS_CHANGES }}
139+ if : steps.tr_check.outputs.HAS_CHANGES == 'true'
112140 uses : actions/github-script@v9
113141 with :
114- github-token : ${{ secrets.MACHINE_ACCOUNT_PAT }}
142+ github-token : ${{ secrets.GITHUB_TOKEN }}
115143 script : |
116144 const now = new Date();
117145 // Date format used: YYYY/MM/DD HH:MM , UTC time(ex: 2023/01/13 08:38)
0 commit comments