forked from DOG729/wwm_russian
-
Notifications
You must be signed in to change notification settings - Fork 2
148 lines (124 loc) · 5.39 KB
/
apply-translations.yml
File metadata and controls
148 lines (124 loc) · 5.39 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
name: Apply Translation Suggestions
on:
issues:
types: [labeled]
# ========== FILA AUTOMÁTICA ==========
# Quando várias issues são aprovadas rapidamente, os workflows
# entram numa fila e são executados em sequência (não em paralelo)
concurrency:
group: apply-translations-queue
cancel-in-progress: false # Espera o anterior terminar, NÃO cancela
jobs:
apply-translations:
# Só executa quando a label "approved" é adicionada
if: github.event.label.name == 'approved'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
# Checkout do repositório de traduções (wwm_brasileiro_auto_path)
- name: Checkout translation repository
uses: actions/checkout@v4
with:
repository: rodrigomiquilino/wwm_brasileiro_auto_path
ref: dev
token: ${{ secrets.TRANSLATION_PAT }}
path: translation-repo
# Checkout do repositório principal (para o script Python)
- name: Checkout main repository
uses: actions/checkout@v4
with:
path: main-repo
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Extract and Apply Translations
id: apply
env:
ISSUE_BODY: ${{ github.event.issue.body }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_AUTHOR: ${{ github.event.issue.user.login }}
TARGET_REPO_PATH: translation-repo
run: |
python main-repo/.github/scripts/apply_translations.py
- name: Commit Changes
if: steps.apply.outputs.changes_made == 'true'
working-directory: translation-repo
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add pt-br.tsv
git commit -m "feat(translation): aplicar sugestões da Issue #${{ github.event.issue.number }}
Contribuição de @${{ github.event.issue.user.login }}
Co-authored-by: ${{ github.event.issue.user.login }} <${{ github.event.issue.user.id }}+${{ github.event.issue.user.login }}@users.noreply.github.com>"
# ========== PUSH COM RETRY ==========
# Sincroniza antes do push e tenta 3x com backoff exponencial
for attempt in 1 2 3; do
echo "📤 Tentativa $attempt de push..."
git pull --rebase origin dev 2>/dev/null || true
if git push origin dev; then
echo "✅ Push realizado com sucesso!"
break
else
if [ $attempt -lt 3 ]; then
echo "⚠️ Falha no push, aguardando $((attempt * 2))s..."
sleep $((attempt * 2))
else
echo "❌ Falha após 3 tentativas"
exit 1
fi
fi
done
- name: Close Issue with Success
if: steps.apply.outputs.changes_made == 'true'
uses: actions/github-script@v7
with:
script: |
const applied = process.env.APPLIED_COUNT || '0';
const skipped = process.env.SKIPPED_COUNT || '0';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## ✅ Traduções Aplicadas com Sucesso!
**Resultado:**
- ✅ Aplicadas: ${applied} tradução(ões)
- ⏭️ Ignoradas: ${skipped} (já existentes ou inválidas)
Obrigado pela contribuição, @${context.payload.issue.user.login}! 🎉
As alterações foram aplicadas na branch \`dev\` do repositório de traduções.`
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed',
labels: ['translation', 'applied']
});
env:
APPLIED_COUNT: ${{ steps.apply.outputs.applied_count }}
SKIPPED_COUNT: ${{ steps.apply.outputs.skipped_count }}
- name: Comment on Failure
if: failure() || steps.apply.outputs.changes_made == 'false'
uses: actions/github-script@v7
with:
script: |
const errorMsg = process.env.ERROR_MESSAGE || 'Erro desconhecido';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## ⚠️ Não foi possível aplicar as traduções
**Motivo:** ${errorMsg}
Por favor, verifique se o formato da Issue está correto e tente novamente.
Se o problema persistir, aplique as traduções manualmente.`
});
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'approved'
});
env:
ERROR_MESSAGE: ${{ steps.apply.outputs.error_message }}