Skip to content

Commit 7c76aee

Browse files
committed
refactor(ci): improved tx sync
1 parent c14b38a commit 7c76aee

File tree

1 file changed

+142
-75
lines changed

1 file changed

+142
-75
lines changed

.github/workflows/tx-pull.yml

Lines changed: 142 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,150 @@ name: Transifex sync
22
on:
33
workflow_dispatch:
44
schedule:
5-
- cron: '0 0 * * 0'
5+
- cron: '0 9 * * 1'
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
610

711
jobs:
812
tx-sync:
913
runs-on: ubuntu-latest
1014
steps:
11-
- uses: actions/checkout@v4.1.2
12-
- name: Install Transifex client
13-
run: |
14-
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
15-
chmod +x ./tx
16-
- name: Pull translations from Transifex
17-
run: |
18-
# Pull only translated strings, leaving untranslated ones empty
19-
# This prevents replacing existing translations with English
20-
# -f: force download, always use Transifex as source of truth (ignore timestamps)
21-
# --mode onlytranslated: only includes translated strings, untranslated keys will be empty
22-
# --minimum-perc 75: only pulls files that are at least 75% translated
23-
# Empty strings will fallback to English at runtime via i18next
24-
./tx -t ${{ secrets.TX_TOKEN }} pull -a -f --mode onlytranslated --minimum-perc 75
25-
- uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842
26-
with:
27-
# Optional. Commit message for the created commit.
28-
# Defaults to "Apply automatic changes"
29-
commit_message: "chore: Pull transifex translations"
30-
31-
# Optional. Local and remote branch name where commit is going to be pushed
32-
# to. Defaults to the current branch.
33-
# You might need to set `create_branch: true` if the branch does not exist.
34-
branch: i18n-sync
35-
36-
# Optional. Options used by `git-commit`.
37-
# See https://git-scm.com/docs/git-commit#_options
38-
commit_options: '--no-verify --signoff'
39-
40-
# Optional glob pattern of files which should be added to the commit
41-
# Defaults to all (.)
42-
# See the `pathspec`-documentation for git
43-
# - https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203
44-
# - https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
45-
file_pattern: public/locales
46-
47-
# Optional. Local file path to the repository.
48-
# Defaults to the root of the repository.
49-
repository: .
50-
51-
# Optional. Options used by `git-add`.
52-
# See https://git-scm.com/docs/git-add#_options
53-
add_options: '-A'
54-
55-
# Optional. Options used by `git-push`.
56-
# See https://git-scm.com/docs/git-push#_options
57-
push_options: '--force'
58-
59-
# Optional. Disable dirty check and always try to create a commit and push
60-
skip_dirty_check: true
61-
62-
# Optional. Skip internal call to `git fetch`
63-
skip_fetch: true
64-
65-
# Optional. Skip internal call to `git checkout`
66-
skip_checkout: true
67-
68-
# Optional. Prevents the shell from expanding filenames.
69-
# Details: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
70-
disable_globbing: true
71-
72-
# Optional. Create given branch name in local and remote repository.
73-
create_branch: true
74-
- name: pull-request
75-
uses: repo-sync/pull-request@65785d95a5a466e46a9d0708933a3bd51bbf9dde
76-
with:
77-
source_branch: "i18n-sync"
78-
destination_branch: "main"
79-
pr_title: "chore: pull new translations"
80-
pr_body: "Automated PR created by .github/workflows/tx-pull.yml"
81-
pr_label: "area/i18n/translations"
82-
pr_draft: false
83-
pr_allow_empty: false
84-
github_token: ${{ secrets.GITHUB_TOKEN }}
15+
- uses: actions/checkout@v4
16+
- name: Setup i18n-sync branch
17+
run: |
18+
# Fetch i18n-sync branch if it exists remotely
19+
if git ls-remote --exit-code --heads origin i18n-sync; then
20+
git fetch origin i18n-sync:i18n-sync
21+
git checkout i18n-sync
22+
else
23+
# Create new branch from main
24+
git checkout -b i18n-sync
25+
fi
26+
- name: Install Transifex client
27+
run: |
28+
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
29+
chmod +x ./tx
30+
- name: Pull translations from Transifex
31+
run: |
32+
# Pull only translated strings, leaving untranslated ones empty
33+
# This prevents replacing existing translations with English
34+
# -f: force download, always use Transifex as source of truth (ignore timestamps)
35+
# --mode onlytranslated: only includes translated strings, untranslated keys will be empty
36+
# --minimum-perc 75: only pulls files that are at least 75% translated
37+
# Empty strings will fallback to English at runtime via i18next
38+
./tx --token "${{ secrets.TX_TOKEN }}" pull --all --force --mode onlytranslated --minimum-perc 75
39+
- name: Commit and push changes
40+
id: commit
41+
run: |
42+
# Configure git
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
45+
46+
# Add translation files
47+
git add -A public/locales
48+
49+
# Check if there are changes to commit
50+
if git diff --staged --quiet; then
51+
echo "::notice::No translation changes detected from Transifex"
52+
{
53+
echo "## 📋 Transifex Sync Summary"
54+
echo ""
55+
echo "✅ **No changes detected**"
56+
echo ""
57+
echo "All translations are up to date."
58+
} >> "$GITHUB_STEP_SUMMARY"
59+
echo "changes=false" >> "$GITHUB_OUTPUT"
60+
else
61+
# Get statistics before committing
62+
STATS=$(git diff --staged --stat)
63+
FILES_CHANGED=$(git diff --staged --name-only)
64+
FILES_COUNT=$(echo "$FILES_CHANGED" | wc -l)
65+
66+
# Commit changes
67+
git commit --no-verify --signoff -m "chore: pull transifex translations"
68+
SYNC_TIME=$(date -u +%Y-%m-%d\ %H:%M)
69+
70+
# Push to remote (force to handle any conflicts)
71+
git push origin i18n-sync --force
72+
73+
# Create GitHub annotations
74+
echo "::notice::Translation updates committed - $FILES_COUNT file(s) changed"
75+
76+
# Create job summary
77+
{
78+
echo "## 📋 Transifex Sync Summary"
79+
echo ""
80+
echo "✅ **Translation updates found and committed**"
81+
echo ""
82+
echo "**Sync time:** $SYNC_TIME UTC"
83+
echo "**Files changed:** $FILES_COUNT"
84+
echo ""
85+
echo "### 📁 Changed files:"
86+
echo "\`\`\`"
87+
echo "$FILES_CHANGED"
88+
echo "\`\`\`"
89+
echo ""
90+
echo "### 📊 Statistics:"
91+
echo "\`\`\`diff"
92+
echo "$STATS"
93+
echo "\`\`\`"
94+
} >> "$GITHUB_STEP_SUMMARY"
95+
96+
{
97+
echo "changes=true"
98+
echo "sync_time=$SYNC_TIME"
99+
echo "files_count=$FILES_COUNT"
100+
} >> "$GITHUB_OUTPUT"
101+
fi
102+
- name: Create pull request
103+
if: steps.commit.outputs.changes == 'true'
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
run: |
107+
# Check if PR already exists
108+
existing_pr=$(gh pr list --base main --head i18n-sync --state open --json number,url --jq '.[0]' || true)
109+
if [ -n "$existing_pr" ]; then
110+
PR_NUMBER=$(echo "$existing_pr" | jq -r '.number')
111+
PR_URL=$(echo "$existing_pr" | jq -r '.url')
112+
echo "::warning::Pull request #$PR_NUMBER already exists for i18n-sync branch"
113+
114+
# Update job summary with PR info
115+
{
116+
echo ""
117+
echo "### 🔗 Pull Request"
118+
echo "⚠️ **Existing PR updated:** [#$PR_NUMBER]($PR_URL)"
119+
} >> "$GITHUB_STEP_SUMMARY"
120+
else
121+
# Create new PR
122+
body="Automated translation update from Transifex.
123+
124+
**Sync time:** ${{ steps.commit.outputs.sync_time }} UTC
125+
**Files changed:** ${{ steps.commit.outputs.files_count }}
126+
127+
- Only pulls translated strings (empty strings fallback to English)
128+
- Includes locales with 75%+ completion
129+
130+
To contribute translations: https://app.transifex.com/ipfs/ipfs-webui/"
131+
132+
PR_URL=$(gh pr create \
133+
--base main \
134+
--head i18n-sync \
135+
--title "chore: pull new translations" \
136+
--body "$body" \
137+
--label "area/i18n/translations" || echo "")
138+
139+
if [ -n "$PR_URL" ]; then
140+
echo "::notice::Pull request created: $PR_URL"
141+
142+
# Update job summary with PR info
143+
{
144+
echo ""
145+
echo "### 🔗 Pull Request"
146+
echo "✅ **New PR created:** $PR_URL"
147+
} >> "$GITHUB_STEP_SUMMARY"
148+
else
149+
echo "::error::Failed to create pull request"
150+
fi
151+
fi

0 commit comments

Comments
 (0)