-
Notifications
You must be signed in to change notification settings - Fork 528
151 lines (135 loc) Β· 5.51 KB
/
tx-pull.yml
File metadata and controls
151 lines (135 loc) Β· 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Transifex sync
on:
workflow_dispatch:
schedule:
- cron: '0 9 * * 1'
permissions:
contents: write
pull-requests: write
jobs:
tx-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup i18n-sync branch
run: |
# Fetch i18n-sync branch if it exists remotely
if git ls-remote --exit-code --heads origin i18n-sync; then
git fetch origin i18n-sync:i18n-sync
git checkout i18n-sync
else
# Create new branch from main
git checkout -b i18n-sync
fi
- name: Install Transifex client
run: |
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
chmod +x ./tx
- name: Pull translations from Transifex
run: |
# Pull only translated strings, leaving untranslated ones empty
# This prevents replacing existing translations with English
# -f: force download, always use Transifex as source of truth (ignore timestamps)
# --mode onlytranslated: only includes translated strings, untranslated keys will be empty
# --minimum-perc 75: only pulls files that are at least 75% translated
# Empty strings will fallback to English at runtime via i18next
./tx --token "${{ secrets.TX_TOKEN }}" pull --all --force --mode onlytranslated --minimum-perc 75
- name: Commit and push changes
id: commit
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add translation files
git add -A public/locales
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "::notice::No translation changes detected from Transifex"
{
echo "## π Transifex Sync Summary"
echo ""
echo "β
**No changes detected**"
echo ""
echo "All translations are up to date."
} >> "$GITHUB_STEP_SUMMARY"
echo "changes=false" >> "$GITHUB_OUTPUT"
else
# Get statistics before committing
STATS=$(git diff --staged --stat)
FILES_CHANGED=$(git diff --staged --name-only)
FILES_COUNT=$(echo "$FILES_CHANGED" | wc -l)
# Commit changes
git commit --no-verify --signoff -m "chore: pull transifex translations"
SYNC_TIME=$(date -u +%Y-%m-%d\ %H:%M)
# Push to remote (force to handle any conflicts)
git push origin i18n-sync --force
# Create GitHub annotations
echo "::notice::Translation updates committed - $FILES_COUNT file(s) changed"
# Create job summary
{
echo "## π Transifex Sync Summary"
echo ""
echo "β
**Translation updates found and committed**"
echo ""
echo "**Sync time:** $SYNC_TIME UTC"
echo "**Files changed:** $FILES_COUNT"
echo ""
echo "### π Changed files:"
echo "\`\`\`"
echo "$FILES_CHANGED"
echo "\`\`\`"
echo ""
echo "### π Statistics:"
echo "\`\`\`diff"
echo "$STATS"
echo "\`\`\`"
} >> "$GITHUB_STEP_SUMMARY"
{
echo "changes=true"
echo "sync_time=$SYNC_TIME"
echo "files_count=$FILES_COUNT"
} >> "$GITHUB_OUTPUT"
fi
- name: Create pull request
if: steps.commit.outputs.changes == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if PR already exists
existing_pr=$(gh pr list --base main --head i18n-sync --state open --json number,url --jq '.[0]' || true)
if [ -n "$existing_pr" ]; then
PR_NUMBER=$(echo "$existing_pr" | jq -r '.number')
PR_URL=$(echo "$existing_pr" | jq -r '.url')
echo "::warning::Pull request #$PR_NUMBER already exists for i18n-sync branch"
# Update job summary with PR info
{
echo ""
echo "### π Pull Request"
echo "β οΈ **Existing PR updated:** [#$PR_NUMBER]($PR_URL)"
} >> "$GITHUB_STEP_SUMMARY"
else
# Create new PR
body="Automated translation update from Transifex.
**Sync time:** ${{ steps.commit.outputs.sync_time }} UTC
**Files changed:** ${{ steps.commit.outputs.files_count }}
- Only pulls translated strings (empty strings fallback to English)
- Includes locales with 75%+ completion
To contribute translations: https://app.transifex.com/ipfs/ipfs-webui/"
PR_URL=$(gh pr create \
--base main \
--head i18n-sync \
--title "chore: pull new translations" \
--body "$body" \
--label "area/i18n/translations" || echo "")
if [ -n "$PR_URL" ]; then
echo "::notice::Pull request created: $PR_URL"
# Update job summary with PR info
{
echo ""
echo "### π Pull Request"
echo "β
**New PR created:** $PR_URL"
} >> "$GITHUB_STEP_SUMMARY"
else
echo "::error::Failed to create pull request"
fi
fi