-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
169 lines (160 loc) · 6.13 KB
/
action.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
name: 'Pull from Lokalise'
description: GitHub action to download translation files from Lokalise TMS to your GitHub repository in the form of a pull request.
author: 'Lokalise Group, Ilya Krukowski'
inputs:
api_token:
description: 'API token for Lokalise with read/write permissions'
required: true
secret: true
project_id:
description: 'Project ID for Lokalise'
required: true
base_lang:
description: 'Base language (e.g., en, fr_FR)'
required: true
default: 'en'
translations_path:
description: 'Paths to translation files'
required: true
default: |
locales
file_format:
description: 'Format of the translation files (e.g., json). Find all supported file formats at https://developers.lokalise.com/reference/api-file-formats'
required: true
default: 'json'
additional_params:
description: 'Additional parameters for Lokalise CLI on pull. Find all supported options at https://github.com/lokalise/lokalise-cli-2-go/blob/main/docs/lokalise2_file_download.md'
required: false
default: ''
temp_branch_prefix:
description: 'Prefix for the temp branch to create pull request'
required: false
default: 'lok'
always_pull_base:
description: 'By default, changes in the base language translation files are ignored. Set this to true to include base language translations in the PR.'
required: false
default: false
flat_naming:
description: 'Use flat naming convention (true/false). If true, expects files like locales/en.json instead of locales/en/file.json'
required: false
default: false
skip_include_tags:
description: 'Skip setting the include-tags argument during download. This will download all translation keys for the specified format, regardless of tags.'
required: false
default: false
pr_labels:
description: 'Comma-separated list of labels to apply to the created pull request'
required: false
default: ''
max_retries:
description: 'Maximum number of retries on rate limit errors'
required: false
default: 3
sleep_on_retry:
description: 'Number of seconds to sleep before retrying'
required: false
default: 1
download_timeout:
description: 'Timeout for the download operation (in seconds)'
default: 120
required: false
permissions:
contents: write
pull-requests: write
branding:
icon: 'download-cloud'
color: 'orange'
outputs:
created_branch:
description: 'The branch that was created and used for the pull request'
value: ${{ steps.create-commit.outputs.branch_name }}
pr_created:
description: 'A boolean value specifying whether the pull request with translation updates has been created'
value: ${{ steps.check-pr-created.outputs.pr_created }}
pr_number:
description: 'Number of the created pull request'
value: ${{ steps.create-update-pr.outputs.pr_number }}
pr_id:
description: 'ID of the created pull request'
value: ${{ steps.create-update-pr.outputs.pr_id }}
runs:
using: "composite"
steps:
- name: Install Lokalise CLIv2
uses: bodrovis/[email protected]
- name: Pull translation files from Lokalise
id: pull-files
shell: bash
env:
CLI_ADD_PARAMS: ${{ inputs.additional_params }}
MAX_RETRIES: ${{ inputs.max_retries }}
SLEEP_TIME: ${{ inputs.sleep_on_retry }}
FILE_FORMAT: ${{ inputs.file_format }}
TRANSLATIONS_PATH: "${{ inputs.translations_path }}"
BASE_LANG: "${{ inputs.base_lang }}"
ALWAYS_PULL_BASE: "${{ inputs.always_pull_base }}"
FLAT_NAMING: "${{ inputs.flat_naming }}"
DOWNLOAD_TIMEOUT: "${{ inputs.download_timeout }}"
SKIP_INCLUDE_TAGS: "${{ inputs.skip_include_tags }}"
run: |
set -e
CMD_PATH="${{ github.action_path }}/bin/lokalise_download"
chmod +x "$CMD_PATH"
"$CMD_PATH" "${{ inputs.project_id }}" "${{ inputs.api_token }}" || {
echo "Error: lokalise_download script failed with exit code $?"
exit 1
}
CMD_PATH="${{ github.action_path }}/bin/detect_changed_files"
chmod +x "$CMD_PATH"
"$CMD_PATH" || {
echo "Error: detect_changed_files script failed with exit code $?"
exit 1
}
- name: Commit changes
id: create-commit
if: steps.pull-files.outputs.has_changes == 'true'
env:
FILE_FORMAT: ${{ inputs.file_format }}
TRANSLATIONS_PATH: "${{ inputs.translations_path }}"
BASE_LANG: "${{ inputs.base_lang }}"
ALWAYS_PULL_BASE: "${{ inputs.always_pull_base }}"
FLAT_NAMING: "${{ inputs.flat_naming }}"
TEMP_BRANCH_PREFIX: "${{ inputs.temp_branch_prefix }}"
shell: bash
run: |
set -e
CMD_PATH="${{ github.action_path }}/bin/commit_changes"
chmod +x "$CMD_PATH"
$("$CMD_PATH") || {
echo "Error: commit_changes script failed with exit code $?"
echo "has_changes=false" >> $GITHUB_OUTPUT
exit 1
}
- name: Create or Update Pull Request
if: steps.pull-files.outputs.has_changes == 'true' && steps.create-commit.outputs.commit_created == 'true'
env:
BRANCH_NAME: ${{ steps.create-commit.outputs.branch_name }}
BASE_REF: ${{ github.ref_name }}
PR_LABELS: ${{ inputs.pr_labels }}
id: create-update-pr
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
result-encoding: string
script: |
const path = require('path');
const createOrUpdatePR = require(path.join(process.env.GITHUB_ACTION_PATH, 'js/create-update-pr.js'));
const result = await createOrUpdatePR({ github, context });
core.setOutput('pr_created', result.created);
core.setOutput('pr_number', result.pr.number);
core.setOutput('pr_id', result.pr.id);
return result.created;
- name: Verify PR created
id: check-pr-created
shell: bash
run: |
if [ "${{ steps.create-update-pr.outputs.pr_created }}" != "true" ]; then
echo "pr_created=false" >> $GITHUB_OUTPUT
else
echo "pr_created=true" >> $GITHUB_OUTPUT
fi