Skip to content

Commit f94dc74

Browse files
committed
add more options
1 parent 0e996c1 commit f94dc74

File tree

3 files changed

+124
-33
lines changed

3 files changed

+124
-33
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
uses: actions/checkout@v2
3030

3131
- name: crowdin action
32-
uses: crowdin/github-action@1.0.2
32+
uses: crowdin/github-action@1.0.3
3333
with:
3434
upload_translations: true
3535
download_translations: true
@@ -51,15 +51,29 @@ In case you don’t want to download translations from Crowdin (download_transla
5151
```yaml
5252
- name: crowdin action
5353
with:
54+
# upload options
5455
upload_sources: true
5556
upload_translations: true
56-
crowdin_branch_name: l10n_branch
57-
config: new-crowdin-config-location.yml
58-
dryrun_action: true
5957

58+
# download options
6059
download_translations: true
60+
language: 'uk'
6161
localization_branch_name: l10n_crowdin_action
6262
create_pull_request: true
63+
64+
# global options
65+
crowdin_branch_name: l10n_branch
66+
identity: '/path/to/your/credentials/file'
67+
config: '/path/to/your/config/file'
68+
dryrun_action: true
69+
70+
# config options
71+
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
72+
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
73+
source: '/path/to/your/file'
74+
translation: 'file/export/pattern'
75+
base_url: 'https://crowdin.com'
76+
base_path: '/project-base-path'
6377
```
6478
6579
## Contributing

action.yml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ branding:
77
color: 'green'
88

99
inputs:
10+
# upload options
1011
upload_sources:
1112
description: 'Upload sources to Crowdin'
1213
default: 'true'
@@ -15,9 +16,31 @@ inputs:
1516
description: 'Upload translations to Crowdin'
1617
default: 'false'
1718
required: false
19+
20+
# download options
21+
download_translations:
22+
description: 'Make pull request of Crowdin translations'
23+
default: 'false'
24+
required: false
25+
language:
26+
description: 'Use this option to download translations for a single specified language'
27+
required: false
28+
localization_branch_name:
29+
description: 'To download translations to the specified version branch'
30+
default: 'l10n_crowdin_action'
31+
required: false
32+
create_pull_request:
33+
description: 'To download translations to the specified version branch'
34+
default: 'true'
35+
required: false
36+
37+
# global options
1838
crowdin_branch_name:
1939
description: 'To upload or download files to the specified version branch'
2040
required: false
41+
identity:
42+
description: 'Option to specify a path to user-specific credentials'
43+
required: false
2144
config:
2245
description: 'Option to specify a path to the configuration file'
2346
required: false
@@ -26,16 +49,24 @@ inputs:
2649
default: 'false'
2750
required: false
2851

29-
download_translations:
30-
description: 'Make pull request of Crowdin translations'
31-
default: 'false'
32-
localization_branch_name:
33-
description: 'To download translations to the specified version branch'
34-
default: 'l10n_crowdin_action'
52+
# config options
53+
project_id:
54+
description: 'Numerical ID of the project'
3555
required: false
36-
create_pull_request:
37-
description: 'To download translations to the specified version branch'
38-
default: 'true'
56+
token:
57+
description: 'Personal access token required for authentication'
58+
required: false
59+
base_url:
60+
description: 'Base URL of Crowdin server for API requests execution'
61+
required: false
62+
base_path:
63+
description: 'Path to your project directory on a local machine'
64+
required: false
65+
source:
66+
description: 'Path to the source files'
67+
required: false
68+
translation:
69+
description: 'Path to the translation files'
3970
required: false
4071

4172
runs:

entrypoint.sh

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,63 @@
11
#!/bin/sh
22

3+
init_options() {
4+
OPTIONS="--no-progress";
5+
6+
if [[ "$INPUT_DEBUG_MODE" = true ]]; then
7+
set -x;
8+
9+
OPTIONS="${OPTIONS} --verbose"
10+
fi
11+
12+
if [[ -n "$INPUT_CROWDIN_BRANCH_NAME" ]]; then
13+
OPTIONS="${OPTIONS} --branch=${INPUT_CROWDIN_BRANCH_NAME}"
14+
fi
15+
16+
if [[ -n "$INPUT_IDENTITY" ]]; then
17+
OPTIONS="${OPTIONS} --identity=${INPUT_IDENTITY}"
18+
fi
19+
20+
if [[ -n "$INPUT_CONFIG" ]]; then
21+
OPTIONS="${OPTIONS} --config=${INPUT_CONFIG}"
22+
fi
23+
24+
if [[ "$INPUT_DRYRUN_ACTION" = true ]]; then
25+
OPTIONS="${OPTIONS} --dryrun"
26+
fi
27+
28+
echo ${OPTIONS};
29+
}
30+
31+
init_config_options() {
32+
CONFIG_OPTIONS="";
33+
34+
if [[ -n "$INPUT_PROJECT_ID" ]]; then
35+
CONFIG_OPTIONS="${CONFIG_OPTIONS} --project-id=${INPUT_PROJECT_ID}"
36+
fi
37+
38+
if [[ -n "$INPUT_TOKEN" ]]; then
39+
CONFIG_OPTIONS="${CONFIG_OPTIONS} --token=${INPUT_TOKEN}"
40+
fi
41+
42+
if [[ -n "$INPUT_BASE_URL" ]]; then
43+
CONFIG_OPTIONS="${CONFIG_OPTIONS} --base-url=${INPUT_BASE_URL}"
44+
fi
45+
46+
if [[ -n "$INPUT_BASE_PATH" ]]; then
47+
CONFIG_OPTIONS="${CONFIG_OPTIONS} --base-path=${INPUT_BASE_PATH}"
48+
fi
49+
50+
if [[ -n "$INPUT_SOURCE" ]]; then
51+
CONFIG_OPTIONS="${CONFIG_OPTIONS} --source=${INPUT_SOURCE}"
52+
fi
53+
54+
if [[ -n "$INPUT_TRANSLATION" ]]; then
55+
CONFIG_OPTIONS="${CONFIG_OPTIONS} --translation=${INPUT_TRANSLATION}"
56+
fi
57+
58+
echo ${CONFIG_OPTIONS};
59+
}
60+
361
upload_sources() {
462
echo "UPLOAD SOURCES";
563
crowdin upload sources ${CONFIG_OPTIONS} ${OPTIONS};
@@ -11,6 +69,10 @@ upload_translations() {
1169
}
1270

1371
download_translations() {
72+
if [[ -n "$INPUT_LANGUAGE" ]]; then
73+
OPTIONS="${OPTIONS} --language=${INPUT_LANGUAGE}"
74+
fi
75+
1476
echo "DOWNLOAD TRANSLATIONS";
1577
crowdin download ${CONFIG_OPTIONS} ${OPTIONS};
1678
}
@@ -34,7 +96,7 @@ create_pull_request() {
3496
if [[ "${PULL_REQUESTS#*$LOCALIZATION_BRANCH}" == "$PULL_REQUESTS" ]]; then
3597
echo "CREATE PULL REQUEST";
3698

37-
DATA="{\"title\":\"${TITLE}\", \"body\":\"${BODY}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\"}";
99+
DATA="{\"title\":\"${TITLE}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\"}";
38100
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X POST --data "${DATA}" ${PULLS_URL};
39101
else
40102
echo "PULL REQUEST ALREADY EXIST";
@@ -71,28 +133,13 @@ push_to_branch() {
71133
fi
72134
}
73135

136+
# STARTING WORK
74137
echo "STARTING CROWDIN ACTION";
75138

76139
set -e;
77140

78-
if [[ "$INPUT_DEBUG_MODE" = true ]]; then
79-
set -x;
80-
fi
81-
82-
CONFIG_OPTIONS="";
83-
OPTIONS="--no-progress";
84-
85-
if [[ -n "$INPUT_CROWDIN_BRANCH_NAME" ]]; then
86-
OPTIONS="${OPTIONS} --branch=${INPUT_CROWDIN_BRANCH_NAME}"
87-
fi
88-
89-
if [[ -n "$INPUT_CONFIG" ]]; then
90-
OPTIONS="${OPTIONS} --config=${INPUT_CONFIG}"
91-
fi
92-
93-
if [[ "$INPUT_DRYRUN_ACTION" = true ]]; then
94-
OPTIONS="${OPTIONS} --dryrun"
95-
fi
141+
OPTIONS=$( init_options );
142+
CONFIG_OPTIONS=$( init_config_options );
96143

97144
if [[ "$INPUT_UPLOAD_SOURCES" = true ]]; then
98145
upload_sources;
@@ -102,7 +149,6 @@ if [[ "$INPUT_UPLOAD_TRANSLATIONS" = true ]]; then
102149
upload_translations;
103150
fi
104151

105-
106152
if [[ "$INPUT_DOWNLOAD_TRANSLATIONS" = true ]]; then
107153
[[ -z "${GITHUB_TOKEN}" ]] && {
108154
echo "CAN NOT FIND 'GITHUB_TOKEN' IN ENVIRONMENT VARIABLES";

0 commit comments

Comments
 (0)