generated from IDEMSInternational/app-sample-content
-
Notifications
You must be signed in to change notification settings - Fork 1
238 lines (191 loc) · 8.57 KB
/
Translations down.yml
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
#Upload Translations to crowdin
#Get content repo
#Get Translations repo
#Get Translation content repo
# run script to post translations
#Download Translations from crowdin
#Get content repo
#Get Translations repo
#Get Translation content repo
# run script to get translations
# move and rename translation files
#File expecting : es_dictionary.json
#move to : translated.mx_es.json
# build and commit changes.
##################################################################################
# About
##################################################################################
# Get translations from crowdin
#
# Version : 1.0
#
##################################################################################
# Configuration
##################################################################################
env:
DEPLOYMENT_NAME: ${{vars.DEPLOYMENT_NAME}}
APP_CODE_BRANCH: ${{vars.APP_CODE_BRANCH}}
PARENT_DEPLOYMENT_REPO: ${{vars.PARENT_DEPLOYMENT_REPO}}
PARENT_DEPLOYMENT_NAME: ${{vars.PARENT_DEPLOYMENT_NAME}}
PARENT_DEPLOYMENT_BRANCH: ${{vars.PARENT_DEPLOYMENT_BRANCH}}
DEPLOYMENT_PRIVATE_KEY: ${{secrets.DEPLOYMENT_PRIVATE_KEY}}
FIREBASE_CONFIG: ${{secrets.FIREBASE_CONFIG}}
GDRIVE_CREDENTIALS: ${{ secrets.GDRIVE_CREDENTIALS }}
GDRIVE_TOKEN: ${{ secrets.GDRIVE_TOKEN }}
name: Update Translations, sync and create a PR
##################################################################################
# Main Code
##################################################################################
on:
workflow_dispatch:
inputs:
pr-title:
description: Title for PR
type: string
default: Translation sync from actions
pr-body:
description: Description for PR
type: string
default: Automated Translation PR creation from actions
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check translation repo #TODO this repo should be a variable
uses: actions/checkout@v3
with:
repository: "IDEMSInternational/plh-digital-content.git"
path: "plh-digital-content"
ref: "main"
- name: Check idems_translation
uses: actions/checkout@v3
with:
repository: "IDEMSInternational/idems_translation.git"
path: "idems_translation"
ref: "master"
- name: set up python enviroment
uses: actions/[email protected]
with:
python-version: '3.12'
- name: update idems_translation packages
working-directory: idems_translation
run:
npm ci || true
- name: List contents of current directory
run: ls -l
- name: Check out app code
uses: actions/checkout@v3
with:
repository: "IDEMSInternational/parenting-app-ui.git"
ref: ${{env.APP_CODE_BRANCH}}
path: "parenting-app-ui"
- name: List contents of current directory
run: ls -l
- name: Remove .git from the repository in order to nest
working-directory: parenting-app-ui
run: |
rm -rf .git
- name: Checkout parent repo if needed
if: env.PARENT_DEPLOYMENT_REPO != ''
uses: actions/checkout@v3
with:
path: "parenting-app-ui/.idems_app/deployments/${{env.PARENT_DEPLOYMENT_NAME}}"
repository: ${{env.PARENT_DEPLOYMENT_REPO}}
ref: ${{env.PARENT_DEPLOYMENT_BRANCH}}
- name: Checkout deployment
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
path: "parenting-app-ui/.idems_app/deployments/${{env.DEPLOYMENT_NAME}}"
- name: List contents of current directory
run: ls -l
- name: Run script to create translation files
working-directory: idems_translation
run: python app/scripts/merge_files_post_translation.py ../parenting-app-ui/.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/translator_settings.json
- name: Move and rename translation file
run: |
LANGUAGES=$(cat parenting-app-ui/.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/language_mappings.json)
# Loop through languages and move files
for lang in $(echo "${LANGUAGES}" | jq -r 'keys[]'); do
destination=$(echo "${LANGUAGES}" | jq -r ".[\"$lang\"]")
mv idems_translation/app/5_completed_dictionaries/${lang}_dictionary.json parenting-app-ui/.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/translations_source/translated_strings/translated.${destination}.json
done
- name: Populate Encryption key
if: env.DEPLOYMENT_PRIVATE_KEY != ''
working-directory: parenting-app-ui
run: echo "${{env.DEPLOYMENT_PRIVATE_KEY}}" > ./.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/encrypted/private.key
# TODO - populate firebase as part of deployment set
- name: Populate Firebase Config
if: env.FIREBASE_CONFIG != ''
working-directory: parenting-app-ui
run: echo 'export const firebaseConfig = ${{env.FIREBASE_CONFIG}}' > src/environments/firebaseConfig.ts
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Cache node modules
uses: actions/cache@v3
with:
path: ./parenting-app-ui/.yarn/cache
# If cachebusting required (e.g. breaking yarn changes on update) change `v1` to another number
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-yarn-v1-
- name: Install node modules
working-directory: parenting-app-ui
run: yarn install
- name: Set deployment
working-directory: parenting-app-ui
run: yarn workflow deployment set $DEPLOYMENT_NAME
- name: Add google credentials
working-directory: parenting-app-ui
run: echo "${{env.GDRIVE_CREDENTIALS}}" > ./packages/scripts/config/credentials.json
- name: Add google token
working-directory: parenting-app-ui
run: echo "$GDRIVE_TOKEN" > ./packages/scripts/config/token.json
env:
GDRIVE_TOKEN: ${{ env.GDRIVE_TOKEN }}
- name: Sync content
working-directory: parenting-app-ui
run: yarn workflow sync
- name: Increment version number
working-directory: parenting-app-ui
run: |
# Define the path to the file
FILE_PATH="./.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/config.ts"
# Extract the version number
VERSION=$(grep 'content_tag_latest:' $FILE_PATH | sed 's/content_tag_latest: *"\(.*\)",/\1/')
echo "Extracted Version: $VERSION"
# Split the version into major, minor, and patch components
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
if [[ ${#VERSION_PARTS[@]} -ne 3 ]]; then
echo "Error: Version format is not as expected."
exit 1
fi
PATCH_VERSION="${VERSION_PARTS[2]}"
# Increment the patch version
NEW_PATCH_VERSION=$((PATCH_VERSION + 1))
# Construct the new version
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$NEW_PATCH_VERSION"
echo "New Version: $NEW_VERSION"
echo "Command: s/$VERSION/$NEW_VERSION/ $FILE_PATH"
sed -i 's/\(content_tag_latest: "\)\([0-9]\+\.[0-9]\+\.\)\([0-9]\+\)"/\1\2'$((NEW_PATCH_VERSION))'"/' $FILE_PATH
- name: Commit changes
working-directory: parenting-app-ui/.idems_app/deployments/${{env.DEPLOYMENT_NAME}}
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add . # This adds all changes to the staging area
git diff --quiet && git diff --staged --quiet || git commit -m "Automated commit message" # Only commit if there are changes
# git checkout -b automated-changes
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
token: ${{ secrets.PAT }}
# Relative path under $GITHUB_WORKSPACE to the repository. Defaults to $GITHUB_WORKSPACE.
path: parenting-app-ui/.idems_app/deployments/${{env.DEPLOYMENT_NAME}}
# The title of the pull request.
title: ${{ inputs.pr-title }}
# The body of the pull request.
body: ${{ inputs.pr-body }}
labels: test - preview