diff --git a/README.md b/README.md index bb8acf7..ac4aa12 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/action.yml b/action.yml index 05332b9..35a2c60 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,7 @@ branding: color: 'green' inputs: + # upload options upload_sources: description: 'Upload sources to Crowdin' default: 'true' @@ -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 @@ -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: diff --git a/entrypoint.sh b/entrypoint.sh index 53e9f67..553f4a4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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}; @@ -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}; } @@ -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"; @@ -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; @@ -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";