-
Notifications
You must be signed in to change notification settings - Fork 4
286 lines (244 loc) · 10.8 KB
/
Copy pathstart-translation.yml
File metadata and controls
286 lines (244 loc) · 10.8 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# Sync existing Boost submodules (update docs and submodule pointers).
#
# Trigger: repository_dispatch with event_type EVENT_START_TRANSLATION (start-translation).
# Example: POST /repos/{owner}/{repo}/dispatches
# Body: {"event_type": "start-translation", "client_payload": {"version": "boost-1.90.0"}}
#
# Submodules list is taken from .gitmodules of this repository at master
# (only libs/ entries). No new org repos are created; run add-submodules first.
#
# Jobs:
# setup — validate lang_codes and emit matrix JSON.
# sync-mirrors — sync mirror master for all submodules; update super-repo master.
# Zero libs/ entries in .gitmodules is a fatal precondition (run add-submodules first).
# On partial submodule failure: finalize successful pointers, then exit non-zero.
# start-local (matrix per lang) — local-{lang_code} in mirrors + super-repo + Weblate.
# Runs per language when sync-mirrors succeeded (see job if:).
# Requires a non-empty updated_submodules handoff; empty array is a job failure.
#
# client_payload:
# lang_codes: (optional) Comma-separated lang codes (e.g. zh_Hans,ja). Defaults to vars.LANG_CODES.
# version: (optional) Boost release ref (e.g. boost-1.90.0). Defaults to develop.
# extensions: (optional) File extensions for Weblate (e.g. [.adoc, .md]). Default empty.
#
# Required secrets: SYNC_TOKEN, WEBLATE_URL, WEBLATE_TOKEN.
# SYNC_TOKEN: push/PR access in MODULE_ORG. Repository variable SUBMODULES_ORG: org for
# library repos (e.g. CppDigest). If unset, MODULE_ORG is this repo's org.
# Optional: LANG_CODES (used when lang_codes not in client_payload).
name: Start translation
on:
repository_dispatch:
# Must match EVENT_START_TRANSLATION in assets/env.sh
types: [start-translation]
permissions:
contents: read
jobs:
setup:
runs-on: ubuntu-latest
outputs:
json: ${{ steps.langs.outputs.json }}
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.SYNC_TOKEN }}
persist-credentials: false
- name: Prepare language matrix
id: langs
env:
LANG_CODES: ${{ github.event.client_payload.lang_codes || vars.LANG_CODES }}
run: |
set -euo pipefail
# shellcheck source=assets/env.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/env.sh"
# shellcheck source=assets/lib.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/lib.sh"
begin_phase "$PHASE_SETUP" "Validate language matrix"
parse_and_validate_lang_codes
langs_json=$(submodule_names_to_json "${lang_codes_arr[@]}")
echo "json=$langs_json" >> "$GITHUB_OUTPUT"
echo "Lang codes: ${lang_codes_arr[*]}" >&2
end_phase
sync-mirrors:
needs: setup
runs-on: ubuntu-latest
outputs:
updated_submodules: ${{ steps.sync.outputs.updated_submodules }}
concurrency:
group: translations-mirror-master
cancel-in-progress: false
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.SYNC_TOKEN }}
persist-credentials: false
- name: Checkout master for .gitmodules
run: |
set -euo pipefail
# shellcheck source=assets/env.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/env.sh"
git checkout "$MASTER_BRANCH"
- name: Sync mirror master
id: sync
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.SYNC_TOKEN }}
LIBS_REF: ${{ github.event.client_payload.version || 'develop' }}
SUBMODULES_ORG: ${{ vars.SUBMODULES_ORG }}
run: |
set -euo pipefail
# shellcheck disable=SC2034
lang_codes_arr=()
# shellcheck source=assets/env.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/env.sh"
# shellcheck source=assets/lib.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/lib.sh"
# shellcheck source=assets/translation.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/translation.sh"
# shellcheck source=assets/submodule_ops.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/submodule_ops.sh"
init_translation_state
init_submodule_summary_buckets
begin_phase "$PHASE_SETUP" "Prepare workspace"
validate_secrets
init_translation_work_dirs with_org_work
gh auth setup-git
# shellcheck disable=SC2034
START_PHASE="$START_PHASE_MIRRORS"
# libs_ref is read by translation.sh (sourced).
# shellcheck disable=SC2034
libs_ref="${LIBS_REF:?}"
[[ ! -f .gitmodules ]] && {
phase_err ".gitmodules not found (run from translations repo with master checked out)"
end_phase
exit 1
}
require_libs_submodules_in_gitmodules ".gitmodules" || {
end_phase
exit 1
}
mapfile -t submodule_names < <(libs_submodule_names_from_gitmodules_file ".gitmodules")
end_phase
begin_phase "$PHASE_PROCESS_SUBMODULES" "Sync mirror master"
echo "Syncing mirror master for ${#submodule_names[@]} submodules." >&2
rc=0
ensure_translations_cloned "$ORG" "$TRANSLATIONS_REPO" "$TRANS_DIR" || rc=$?
if [[ $rc -ne 0 ]]; then
end_phase
exit $rc
fi
process_submodule_list sync_one_submodule "${submodule_names[@]}"
end_phase
begin_phase "$PHASE_FINALIZE_TRANSLATIONS" "Finalize translations master"
rc=0
finalize_translations_master "$TRANS_DIR" "$LIBS_REF" || rc=$?
end_phase
combine_batch_and_finalize_rc "$rc" || exit_rc=$?
if [[ ${exit_rc:-0} -eq 0 ]]; then
updated_json=$(submodule_names_to_json "${UPDATES[@]}")
echo "updated_submodules=$updated_json" >> "$GITHUB_OUTPUT"
echo "Submodules for start-local: $updated_json" >&2
echo "Done." >&2
else
exit "$exit_rc"
fi
start-local:
# Run when sync-mirrors succeeded; empty updated_submodules is a fatal error inside the job.
if: ${{ always() && !cancelled() && needs.setup.result == 'success' && needs.sync-mirrors.result == 'success' }}
needs: [setup, sync-mirrors]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
lang: ${{ fromJson(needs.setup.outputs.json) }}
concurrency:
group: local-branch-${{ matrix.lang }}
cancel-in-progress: false
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.SYNC_TOKEN }}
persist-credentials: false
- name: Checkout master for .gitmodules
run: |
set -euo pipefail
# shellcheck source=assets/env.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/env.sh"
git checkout "$MASTER_BRANCH"
- name: Start translation for ${{ matrix.lang }}
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.SYNC_TOKEN }}
LIBS_REF: ${{ github.event.client_payload.version || 'develop' }}
LANG_CODE: ${{ matrix.lang }}
EXTENSIONS: ${{ github.event.client_payload.extensions || '' }}
WEBLATE_URL: ${{ secrets.WEBLATE_URL }}
WEBLATE_TOKEN: ${{ secrets.WEBLATE_TOKEN }}
SUBMODULES_ORG: ${{ vars.SUBMODULES_ORG }}
SYNC_MIRROR_UPDATES: ${{ needs.sync-mirrors.outputs.updated_submodules }}
run: |
set -euo pipefail
# shellcheck source=assets/env.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/env.sh"
# shellcheck source=assets/lib.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/lib.sh"
# shellcheck source=assets/translation.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/translation.sh"
# shellcheck source=assets/submodule_ops.sh
source "$GITHUB_WORKSPACE/.github/workflows/assets/submodule_ops.sh"
init_translation_state
init_submodule_summary_buckets
begin_phase "$PHASE_SETUP" "Prepare workspace"
validate_secrets weblate
init_translation_work_dirs with_org_work
gh auth setup-git
# shellcheck disable=SC2034
START_PHASE="$START_PHASE_LOCAL"
# shellcheck disable=SC2034,SC2153
libs_ref="${LIBS_REF:?}"
echo "Lang code: $LANG_CODE" >&2
# Read by sync_one_submodule in translation.sh (sourced above).
# shellcheck disable=SC2034
lang_codes_arr=("$LANG_CODE")
init_add_or_update_lang "$LANG_CODE"
echo "Submodules from sync-mirrors: ${SYNC_MIRROR_UPDATES:-[]}" >&2
mapfile -t submodule_names < <(parse_submodule_names_json "${SYNC_MIRROR_UPDATES:-[]}")
[[ ${#submodule_names[@]} -eq 0 ]] && {
phase_err "No submodules from sync-mirrors to process (updated_submodules is empty)."
end_phase
exit 1
}
end_phase
begin_phase "$PHASE_ENSURE_BRANCHES" "Ensure local branch in translations repo"
rc=0
ensure_translations_cloned "$ORG" "$TRANSLATIONS_REPO" "$TRANS_DIR" || rc=$?
if [[ $rc -eq 0 ]]; then
ensure_local_branch_in_translations "$TRANS_DIR" "$LANG_CODE" || rc=$?
fi
end_phase
[[ $rc -ne 0 ]] && exit $rc
begin_phase "$PHASE_PROCESS_SUBMODULES" "Process local branches"
echo "Processing local branches for ${#submodule_names[@]} submodules." >&2
process_submodule_list sync_one_submodule "${submodule_names[@]}"
end_phase
begin_phase "$PHASE_FINALIZE_TRANSLATIONS" "Finalize translations local branch"
rc=0
finalize_translations_local "$TRANS_DIR" "$LIBS_REF" "$LANG_CODE" || rc=$?
end_phase
weblate_rc=0
if [[ $rc -eq 0 ]]; then
begin_phase "$PHASE_TRIGGER_WEBLATE" "Trigger Weblate add-or-update"
ext_arr=()
[[ -n "${EXTENSIONS:-}" ]] && mapfile -t ext_arr < <(parse_extensions "$EXTENSIONS")
exts_json="[]"
[[ ${#ext_arr[@]} -gt 0 ]] && \
exts_json=$(printf '%s\n' "${ext_arr[@]}" | jq -R . | jq -s .)
trigger_weblate "$WEBLATE_URL" "$WEBLATE_TOKEN" "$LIBS_REF" "$exts_json" "$LANG_CODE" || weblate_rc=$?
end_phase
else
echo "Skipping Weblate add-or-update: finalize_translations_local failed (rc=$rc)." >&2
fi
combine_batch_and_finalize_rc "$rc" "$weblate_rc" || exit $?
echo "Done." >&2