Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9131c8e

Browse files
authored
Add check for manual updates
The action will now check if there have been non-Transifex updates to the repo. If so, it will open a PR; otherwise, it will automatically merge
1 parent 739c63c commit 9131c8e

1 file changed

Lines changed: 38 additions & 10 deletions

File tree

.github/workflows/pull-translations.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# Workflow from https://github.com/python-docs-translations/transifex-automations/blob/main/sample-workflows/transifex-pull.yml
1+
# Workflow adapted from https://github.com/python-docs-translations/transifex-automations/blob/main/sample-workflows/transifex-pull.yml
22
name: Pull Translations from Transifex
3-
43
on:
54
schedule:
65
- cron: '0 0 * * *'
76
workflow_dispatch:
87
permissions:
98
contents: write
10-
9+
pull-requests: write
1110
jobs:
1211
update-translation:
1312
runs-on: ubuntu-latest
@@ -32,6 +31,7 @@ jobs:
3231
with:
3332
ref: ${{ matrix.version }}
3433
fetch-depth: 0
34+
token: ${{ secrets.GITHUB_TOKEN }}
3535
- run: curl -O https://raw.githubusercontent.com/python-docs-translations/transifex-automations/master/sample-workflows/transifex-util.py
3636
- run: chmod +x transifex-util.py
3737
- run: ./transifex-util.py recreate_tx_config --language id --project-slug python-newest --version 3.14
@@ -45,18 +45,46 @@ jobs:
4545
run: |
4646
git config --local user.email [email protected]
4747
git config --local user.name "GitHub Action's update-translation job"
48+
- name: Check for recent manual changes
49+
run: |
50+
RECENT_COMMITS=$(git log --since="24 hours ago" --grep="Update translation from Transifex" --invert-grep --oneline | wc -l)
51+
if [ "$RECENT_COMMITS" -gt 0 ]; then
52+
echo "Recent manual commits detected:"
53+
git log --since="24 hours ago" --grep="Update translation from Transifex" --invert-grep --oneline
54+
echo "RECENT_MANUAL_CHANGES=1" >> $GITHUB_ENV
55+
else
56+
echo "No recent manual changes detected"
57+
echo "RECENT_MANUAL_CHANGES=0" >> $GITHUB_ENV
58+
fi
4859
- name: Filter files
4960
run: |
5061
! git diff -I'^"POT-Creation-Date: ' \
5162
-I'^"Language-Team: ' \
5263
-I'^# ' -I'^"Last-Translator: ' \
5364
--exit-code \
5465
&& echo "SIGNIFICANT_CHANGES=1" >> $GITHUB_ENV || exit 0
55-
- run: git add .
56-
- run: git commit -m 'Update translation from Transifex'
57-
if: env.SIGNIFICANT_CHANGES
58-
- uses: ad-m/github-push-action@master
59-
if: env.SIGNIFICANT_CHANGES
66+
- name: Create Pull Request if recent manual changes exist
67+
if: env.SIGNIFICANT_CHANGES == '1' && env.RECENT_MANUAL_CHANGES == '1'
68+
uses: peter-evans/create-pull-request@v5
6069
with:
61-
branch: ${{ matrix.version }}
62-
github_token: ${{ secrets.GITHUB_TOKEN }}
70+
token: ${{ secrets.GITHUB_TOKEN }}
71+
branch: transifex-updates-${{ matrix.version }}-${{ github.run_number }}
72+
title: 'Update translations from Transifex for ${{ matrix.version }}'
73+
body: |
74+
Automated translation updates from Transifex
75+
76+
**Manual changes detected in the last 24 hours** - please review carefully to avoid conflicts.
77+
78+
Recent manual commits:
79+
```
80+
$(git log --since="24 hours ago" --grep="Update translation from Transifex" --invert-grep --oneline)
81+
```
82+
83+
base: ${{ matrix.version }}
84+
delete-branch: true
85+
- name: Commit and push directly if no recent manual changes
86+
if: env.SIGNIFICANT_CHANGES == '1' && env.RECENT_MANUAL_CHANGES == '0'
87+
run: |
88+
git add .
89+
git commit -m 'Update translation from Transifex'
90+
git push origin ${{ matrix.version }}

0 commit comments

Comments
 (0)