Repository navigation
Expand file tree
/
Copy pathtranslation-workflow-merged.yaml
More file actions
200 lines (173 loc) · 6.86 KB
/
Copy pathtranslation-workflow-merged.yaml
File metadata and controls
200 lines (173 loc) · 6.86 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
name: Generate memsource translations
on:
schedule:
# Run weekly and execute the sync only on even ISO weeks - to get the translations biweekly
- cron: '0 0 * * 0'
workflow_dispatch:
inputs:
version:
description: 'Version shown in the Memsource project name'
required: false
default: Openshift Pipelines
type: string
sprint:
description: 'Sprint shown in the Memsource project name'
required: false
type: string
base_branch:
description: 'Branch to update'
required: false
default: master
type: string
permissions:
contents: read
concurrency:
group: memsource-translations-${{ github.ref }}
cancel-in-progress: false
env:
BASE_BRANCH: ${{ inputs.base_branch || github.event.repository.default_branch }}
jobs:
cadence:
runs-on: ubuntu-latest
outputs:
run: ${{ steps.cadence.outputs.run }}
steps:
- id: cadence
name: Select biweekly week
env:
EVENT_NAME: ${{ github.event_name }}
run: |
set -euo pipefail
run_workflow=true
if [[ "$EVENT_NAME" == 'schedule' ]]; then
iso_week="$(date -u +%V)"
if (( 10#$iso_week % 2 != 0 )); then
run_workflow=false
echo "Skipping ISO week $iso_week; sync runs on even ISO weeks."
fi
fi
echo "run=$run_workflow" >> "$GITHUB_OUTPUT"
sync:
needs: cadence
if: needs.cadence.outputs.run == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
VERSION: ${{ inputs.version || github.ref_name }}
SPRINT: ${{ inputs.sprint || format('biweekly-{0}', github.run_number) }}
BRANCH: automation/memsource-translations-${{ github.run_id }}
steps:
- name: Checkout target branch
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
ref: ${{ inputs.base_branch || github.event.repository.default_branch }}
fetch-depth: 0
- name: Use a local branch for the sync scripts
run: git switch --force-create "$BASE_BRANCH" "origin/$BASE_BRANCH"
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version: '22'
- name: Enable Corepack
run: |
corepack enable
corepack install --global yarn@4.6.0
yarn --version
- name: Install project dependencies
run: yarn install --no-immutable
- name: Setup Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.4.0
with:
python-version: '3.12'
- name: Install Memsource CLI
run: |
python -m pip install --disable-pip-version-check --no-cache-dir pbr 'memsource-cli==0.3.8'
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
memsource --help >/dev/null
- name: Validate Memsource settings
env:
MEMSOURCE_URL: ${{ secrets.MEMSOURCE_URL }}
MEMSOURCE_USERNAME: ${{ secrets.MEMSOURCE_USERNAME }}
MEMSOURCE_PASSWORD: ${{ secrets.MEMSOURCE_PASSWORD }}
run: |
set -euo pipefail
[[ -n "${MEMSOURCE_URL:-}" ]] || { echo 'MEMSOURCE_URL is not set' >&2; exit 1; }
[[ -n "${MEMSOURCE_USERNAME:-}" ]] || { echo 'MEMSOURCE_USERNAME is not set' >&2; exit 1; }
[[ -n "${MEMSOURCE_PASSWORD:-}" ]] || { echo 'MEMSOURCE_PASSWORD is not set' >&2; exit 1; }
- name: Authenticate to Memsource
env:
MEMSOURCE_URL: ${{ secrets.MEMSOURCE_URL }}
MEMSOURCE_USERNAME: ${{ secrets.MEMSOURCE_USERNAME }}
MEMSOURCE_PASSWORD: ${{ secrets.MEMSOURCE_PASSWORD }}
run: |
set -euo pipefail
token="$(memsource auth login --user-name "$MEMSOURCE_USERNAME" --password "$MEMSOURCE_PASSWORD" -c token -f value)"
[[ -n "$token" ]] || { echo 'Memsource login returned an empty token' >&2; exit 1; }
echo "::add-mask::$token"
echo "MEMSOURCE_TOKEN=$token" >> "$GITHUB_ENV"
- name: Generate and upload source strings
id: upload
run: |
set -euo pipefail
yarn i18n
yarn i18n-to-po
yarn memsource-upload -v "$VERSION" -s "$SPRINT"
sleep 120
- name: Download and convert translations
run: |
set -euo pipefail
PROJECT_ID="${{ steps.upload.outputs.project_id }}"
[[ -n "$PROJECT_ID" ]] || { echo 'Could not determine PROJECT_ID from upload step' >&2; exit 1; }
rm -rf po-files json-locales
yarn memsource-download -p "$PROJECT_ID"
yarn po-to-i18n
- name: Copy converted files into repository locales
run: |
set -euo pipefail
source ./i18n-scripts/languages.sh
namespace='plugin__pipelines-console-plugin'
for language in "${LANGUAGES[@]}"; do
source_file="json-locales/${namespace}-${language}.json"
[[ -s "$source_file" ]] || {
echo "Missing converted translation file: $source_file" >&2
exit 1
}
target_language="$language"
[[ "$target_language" == 'zh-cn' ]] && target_language=zh
mkdir -p "locales/$target_language"
cp "$source_file" "locales/$target_language/${namespace}.json"
done
- name: Validate translated JSON files
run: |
set -euo pipefail
while IFS= read -r -d '' file; do
node -e 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"))' "$file"
done < <(find locales -type f -name 'plugin__pipelines-console-plugin.json' -print0)
- name: Commit and push translation branch
id: commit
run: |
set -euo pipefail
git config user.name openshift-pipelines-bot
git config user.email pipelines-extcomm@redhat.com
git add locales/*/plugin__pipelines-console-plugin.json
if git diff --cached --quiet; then
echo 'No translation changes found.'
echo 'changed=false' >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m 'chore(i18n): update Memsource translations'
git switch -c "$BRANCH"
git push --set-upstream origin "$BRANCH"
echo 'changed=true' >> "$GITHUB_OUTPUT"
- name: Open pull request
if: steps.commit.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr create \
--base "$BASE_BRANCH" \
--head "$BRANCH" \
--title 'chore(i18n): update Memsource translations' \
--body 'This PR was generated by the Memsource translation workflow. It uploads source strings, waits for instant translation, downloads the completed translations, and validates them as JSON.'