Skip to content

Commit ad34941

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

1 file changed

Lines changed: 34 additions & 18 deletions

File tree

.github/workflows/sync_translations.yml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,43 @@ jobs:
8888
cd ./tools/localization
8989
yarn start update
9090
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
91+
- name: Check for changes and handle Neutral result
10092
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
93+
uses: actions/github-script@v7
94+
with:
95+
script: |
96+
const { execSync } = require('child_process');
97+
98+
execSync('git add docs/marketing/localized_description AnkiDroid/src/main/res');
99+
100+
const status = execSync('git diff --cached --name-only').toString().trim();
101+
102+
if(!status) {
103+
console.log("No changes detected. Setting status to neutral.");
104+
105+
await github.rest.checks.create({
106+
owner: context.repo.owner,
107+
repo: context.repo.repo,
108+
name: 'Sync Translations with Crowdin',
109+
head_sha: context.sha,
110+
status: 'completed',
111+
conclusion: 'neutral',
112+
output: {
113+
title: 'Translation Sync',
114+
summary: 'No translation changes were found on Crowdin to sync'
115+
}
116+
});
117+
118+
core.setOutput('HAS_CHANGES', 'false');
119+
} else {
120+
core.setOutput('HAS_CHANGES', 'true');
121+
execSync("git commit -m 'Updated strings from Crowdin'");
122+
execSync("git push --set-upstream origin +i18n_sync");
123+
console.log("Changes pushed to i18n_sync branch");
124+
}
109125
110126
- name: Create PR for strings changes if needed
111-
if: ${{ steps.tr_check.outputs.HAS_CHANGES }}
127+
if: steps.tr_check.outputs.HAS_CHANGES == 'true'
112128
uses: actions/github-script@v9
113129
with:
114130
github-token: ${{ secrets.MACHINE_ACCOUNT_PAT }}

0 commit comments

Comments
 (0)