forked from ton-community/ton-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (147 loc) · 6.05 KB
/
translation-flow.yml
File metadata and controls
171 lines (147 loc) · 6.05 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Translations - Pull from crowdin to github
on:
issue_comment:
types: [ created ]
jobs:
params:
name: Check if comment author has requested Crowdin synchronization
runs-on: ubuntu-latest
outputs:
command: ${{ steps.check.outputs.command }}
issue_number: ${{ github.event.issue.number }}
steps:
- id: check
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
if [[ "$COMMENT_BODY" =~ ^/previewdraft ]]
then
echo "command=previewdraft" >> $GITHUB_OUTPUT
elif [[ "$COMMENT_BODY" =~ ^/preview ]]
then
echo "command=preview" >> $GITHUB_OUTPUT
fi
pull-translations:
needs: params
if: needs.params.outputs.command == 'preview' || needs.params.outputs.command == 'previewdraft'
name: "Pull Translations for #${{ needs.params.outputs.issue_number }} from Crowdin to Github"
runs-on: ubuntu-latest
outputs:
refName: ${{ steps.vars.outputs.refName }}
steps:
- name: Env vars update
id: vars
run: |
echo "language=ru" >> $GITHUB_ENV
echo "issueNumber=${{ needs.params.outputs.issue_number }}" >> $GITHUB_ENV
echo "crowdinBranch=${{ format('translation-{0}-{1}', needs.params.outputs.issue_number, 'ru') }}" >> $GITHUB_ENV
echo "gitBranch=${{ format('translation-{0}-{1}{2}', needs.params.outputs.issue_number, 'ru', needs.params.outputs.command == 'previewdraft' && '-draft' || '') }}" >> $GITHUB_ENV
echo "thisWorkflowURL=${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV
echo "refName=${{ format('translation-{0}-{1}{2}', needs.params.outputs.issue_number, 'ru', needs.params.outputs.command == 'previewdraft' && '-draft' || '') }}" >> $GITHUB_OUTPUT
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ env.issueNumber }}
body: |
Started workflow: ${{ env.thisWorkflowURL }}
- name: Setup / Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.gitBranch }}
- name: Setup / Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Setup / Crowdin CLI
run: npm install -g @crowdin/cli
- name: Setup / Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Pull translations (preview)
if: needs.params.outputs.command == 'preview'
env:
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
run:
crowdin pull translations
-c crowdin-oss.yml
-b ${{ env.crowdinBranch }}
-l ${{ env.language }}
--skip-untranslated-files --export-only-approved
- name: Pull translations (preview draft)
if: needs.params.outputs.command == 'previewdraft'
env:
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
run:
crowdin pull translations
-c crowdin-oss.yml
-b ${{ env.crowdinBranch }}
-l ${{ env.language }}
--skip-untranslated-files
- name: Setup / Dev dependencies
run: npm ci
- name: Prepare commit
id: prepare-commit
run: |
git add i18n/
if [ -z "$(git diff --cached --name-only)" ]; then
echo "staged_files=false" >> $GITHUB_OUTPUT
else
echo "staged_files=true" >> $GITHUB_OUTPUT
fi
- name: Create comment if no staged files
if: steps.prepare-commit.outputs.staged_files == 'false'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ env.issueNumber }}
body: |
There is nothing to commit, possible reasons:
* there is no fully translated and approved files
* there is no difference with the current state of the branch
- name: Lint translated files
if: steps.prepare-commit.outputs.staged_files == 'true'
continue-on-error: true
id: lint-translated
run: |
./node_modules/.bin/eslint -c eslint.mdx.config.js --fix $(git diff --cached --name-only)
- name: Notify on failed linter
if: steps.lint-translated.outcome == 'failure'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ env.issueNumber }}
body: |
⚠️ Linting of the translated files failed, see ${{ env.thisWorkflowURL }}
- name: Commit
if: steps.prepare-commit.outputs.staged_files == 'true'
run: |
git add i18n/
git commit -m "chore: update ${{ env.language }} translations #${{ env.issueNumber }}"
git push -u origin ${{ env.gitBranch }}
- name: Create PullRequest if needed
if: steps.prepare-commit.outputs.staged_files == 'true' && needs.params.outputs.command == 'preview'
id: ensure-pr
uses: actions/github-script@v6
with:
script: |
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner, repo: context.repo.repo,
head: `${context.repo.owner}:${process.env.gitBranch}`,
state: 'open'
});
if (prs.length == 0) {
const { data: newPR } = await github.rest.pulls.create({
owner: context.repo.owner, repo: context.repo.repo,
title: `New translations for ${process.env.language}`,
head: process.env.gitBranch,
base: 'main',
body: `New translations from Crowdin. Closes #${process.env.issueNumber}`,
draft: true
});
}
deploy:
needs: pull-translations
uses: ./.github/workflows/deploy.yml
secrets: inherit
with:
ref_name: ${{ needs.pull-translations.outputs.refName }}