Skip to content

Commit

Permalink
add more options
Browse files Browse the repository at this point in the history
  • Loading branch information
VBeytok committed Apr 28, 2020
1 parent 0e996c1 commit f94dc74
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 33 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v2

- name: crowdin action
uses: crowdin/github-action@1.0.2
uses: crowdin/github-action@1.0.3
with:
upload_translations: true
download_translations: true
Expand All @@ -51,15 +51,29 @@ In case you don’t want to download translations from Crowdin (download_transla
```yaml
- name: crowdin action
with:
# upload options
upload_sources: true
upload_translations: true
crowdin_branch_name: l10n_branch
config: new-crowdin-config-location.yml
dryrun_action: true

# download options
download_translations: true
language: 'uk'
localization_branch_name: l10n_crowdin_action
create_pull_request: true

# global options
crowdin_branch_name: l10n_branch
identity: '/path/to/your/credentials/file'
config: '/path/to/your/config/file'
dryrun_action: true

# config options
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
source: '/path/to/your/file'
translation: 'file/export/pattern'
base_url: 'https://crowdin.com'
base_path: '/project-base-path'
```
## Contributing
Expand Down
49 changes: 40 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ branding:
color: 'green'

inputs:
# upload options
upload_sources:
description: 'Upload sources to Crowdin'
default: 'true'
Expand All @@ -15,9 +16,31 @@ inputs:
description: 'Upload translations to Crowdin'
default: 'false'
required: false

# download options
download_translations:
description: 'Make pull request of Crowdin translations'
default: 'false'
required: false
language:
description: 'Use this option to download translations for a single specified language'
required: false
localization_branch_name:
description: 'To download translations to the specified version branch'
default: 'l10n_crowdin_action'
required: false
create_pull_request:
description: 'To download translations to the specified version branch'
default: 'true'
required: false

# global options
crowdin_branch_name:
description: 'To upload or download files to the specified version branch'
required: false
identity:
description: 'Option to specify a path to user-specific credentials'
required: false
config:
description: 'Option to specify a path to the configuration file'
required: false
Expand All @@ -26,16 +49,24 @@ inputs:
default: 'false'
required: false

download_translations:
description: 'Make pull request of Crowdin translations'
default: 'false'
localization_branch_name:
description: 'To download translations to the specified version branch'
default: 'l10n_crowdin_action'
# config options
project_id:
description: 'Numerical ID of the project'
required: false
create_pull_request:
description: 'To download translations to the specified version branch'
default: 'true'
token:
description: 'Personal access token required for authentication'
required: false
base_url:
description: 'Base URL of Crowdin server for API requests execution'
required: false
base_path:
description: 'Path to your project directory on a local machine'
required: false
source:
description: 'Path to the source files'
required: false
translation:
description: 'Path to the translation files'
required: false

runs:
Expand Down
86 changes: 66 additions & 20 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
#!/bin/sh

init_options() {
OPTIONS="--no-progress";

if [[ "$INPUT_DEBUG_MODE" = true ]]; then
set -x;

OPTIONS="${OPTIONS} --verbose"
fi

if [[ -n "$INPUT_CROWDIN_BRANCH_NAME" ]]; then
OPTIONS="${OPTIONS} --branch=${INPUT_CROWDIN_BRANCH_NAME}"
fi

if [[ -n "$INPUT_IDENTITY" ]]; then
OPTIONS="${OPTIONS} --identity=${INPUT_IDENTITY}"
fi

if [[ -n "$INPUT_CONFIG" ]]; then
OPTIONS="${OPTIONS} --config=${INPUT_CONFIG}"
fi

if [[ "$INPUT_DRYRUN_ACTION" = true ]]; then
OPTIONS="${OPTIONS} --dryrun"
fi

echo ${OPTIONS};
}

init_config_options() {
CONFIG_OPTIONS="";

if [[ -n "$INPUT_PROJECT_ID" ]]; then
CONFIG_OPTIONS="${CONFIG_OPTIONS} --project-id=${INPUT_PROJECT_ID}"
fi

if [[ -n "$INPUT_TOKEN" ]]; then
CONFIG_OPTIONS="${CONFIG_OPTIONS} --token=${INPUT_TOKEN}"
fi

if [[ -n "$INPUT_BASE_URL" ]]; then
CONFIG_OPTIONS="${CONFIG_OPTIONS} --base-url=${INPUT_BASE_URL}"
fi

if [[ -n "$INPUT_BASE_PATH" ]]; then
CONFIG_OPTIONS="${CONFIG_OPTIONS} --base-path=${INPUT_BASE_PATH}"
fi

if [[ -n "$INPUT_SOURCE" ]]; then
CONFIG_OPTIONS="${CONFIG_OPTIONS} --source=${INPUT_SOURCE}"
fi

if [[ -n "$INPUT_TRANSLATION" ]]; then
CONFIG_OPTIONS="${CONFIG_OPTIONS} --translation=${INPUT_TRANSLATION}"
fi

echo ${CONFIG_OPTIONS};
}

upload_sources() {
echo "UPLOAD SOURCES";
crowdin upload sources ${CONFIG_OPTIONS} ${OPTIONS};
Expand All @@ -11,6 +69,10 @@ upload_translations() {
}

download_translations() {
if [[ -n "$INPUT_LANGUAGE" ]]; then
OPTIONS="${OPTIONS} --language=${INPUT_LANGUAGE}"
fi

echo "DOWNLOAD TRANSLATIONS";
crowdin download ${CONFIG_OPTIONS} ${OPTIONS};
}
Expand All @@ -34,7 +96,7 @@ create_pull_request() {
if [[ "${PULL_REQUESTS#*$LOCALIZATION_BRANCH}" == "$PULL_REQUESTS" ]]; then
echo "CREATE PULL REQUEST";

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

# STARTING WORK
echo "STARTING CROWDIN ACTION";

set -e;

if [[ "$INPUT_DEBUG_MODE" = true ]]; then
set -x;
fi

CONFIG_OPTIONS="";
OPTIONS="--no-progress";

if [[ -n "$INPUT_CROWDIN_BRANCH_NAME" ]]; then
OPTIONS="${OPTIONS} --branch=${INPUT_CROWDIN_BRANCH_NAME}"
fi

if [[ -n "$INPUT_CONFIG" ]]; then
OPTIONS="${OPTIONS} --config=${INPUT_CONFIG}"
fi

if [[ "$INPUT_DRYRUN_ACTION" = true ]]; then
OPTIONS="${OPTIONS} --dryrun"
fi
OPTIONS=$( init_options );
CONFIG_OPTIONS=$( init_config_options );

if [[ "$INPUT_UPLOAD_SOURCES" = true ]]; then
upload_sources;
Expand All @@ -102,7 +149,6 @@ if [[ "$INPUT_UPLOAD_TRANSLATIONS" = true ]]; then
upload_translations;
fi


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

0 comments on commit f94dc74

Please sign in to comment.