diff --git a/README.md b/README.md index 1c6367b..ad2805a 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,12 @@ In case you don’t want to download translations from Crowdin (`download_transl # This can be used to pass down any supported argument of the `upload translations` cli command, e.g. upload_translations_args: '--auto-approve-imported --translate-hidden' + # Download sources options + download_sources: true + push_sources: true + # this can be used to pass down any supported argument of the `download sources` cli command, e.g. + download_sources_args: '--reviewed' + # Download translations options download_translations: true download_language: 'uk' diff --git a/action.yml b/action.yml index 6736a61..6a60450 100644 --- a/action.yml +++ b/action.yml @@ -38,9 +38,23 @@ inputs: default: '' required: false + # download sources options + download_sources: + description: 'Defines whether to download source files from the Crowdin project' + default: 'false' + required: false + push_sources: + description: 'Push downloaded sources to the branch' + default: 'true' + required: false + download_sources_args: + description: 'Additional arguments which will be passed to the `download sources` cli command' + default: '' + required: false + # download translations options download_translations: - description: 'Make pull request of Crowdin translations' + description: 'Defines whether to download translation files from the Crowdin project' default: 'false' required: false download_language: @@ -59,7 +73,7 @@ inputs: default: 'false' required: false push_translations: - description: 'Download translations with pushing to branch' + description: 'Push downloaded translations to the branch' default: 'true' required: false commit_message: diff --git a/entrypoint.sh b/entrypoint.sh index ea46e67..3ec55d4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -36,6 +36,15 @@ upload_translations() { crowdin upload translations "$@" $UPLOAD_TRANSLATIONS_OPTIONS } +download_sources() { + if [ -n "$INPUT_DOWNLOAD_SOURCES_ARGS" ]; then + DOWNLOAD_SOURCES_OPTIONS="${DOWNLOAD_SOURCES_OPTIONS} ${INPUT_DOWNLOAD_SOURCES_ARGS}" + fi + + echo "DOWNLOAD SOURCES" + crowdin download sources "$@" $DOWNLOAD_SOURCES_OPTIONS +} + download_translations() { if [ -n "$INPUT_DOWNLOAD_LANGUAGE" ]; then DOWNLOAD_TRANSLATIONS_OPTIONS="${DOWNLOAD_TRANSLATIONS_OPTIONS} --language=${INPUT_DOWNLOAD_LANGUAGE}" @@ -64,7 +73,7 @@ download_translations() { } create_pull_request() { - LOCALIZATION_BRANCH="${1}" + BRANCH="${1}" AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}" HEADER="Accept: application/vnd.github.v3+json; application/vnd.github.antiope-preview+json; application/vnd.github.shadow-cat-preview+json" @@ -95,12 +104,12 @@ create_pull_request() { fi fi - PULL_REQUESTS_QUERY_PARAMS="?base=${BASE_BRANCH}&head=${LOCALIZATION_BRANCH}" + PULL_REQUESTS_QUERY_PARAMS="?base=${BASE_BRANCH}&head=${BRANCH}" PULL_REQUESTS=$(echo "$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X GET "${PULLS_URL}${PULL_REQUESTS_QUERY_PARAMS}")" | jq --raw-output '.[] | .head.ref ') # check if pull request exist - if echo "$PULL_REQUESTS " | grep -q "$LOCALIZATION_BRANCH "; then + if echo "$PULL_REQUESTS " | grep -q "$BRANCH "; then echo "PULL REQUEST ALREADY EXIST" else echo "CREATE PULL REQUEST" @@ -109,7 +118,7 @@ create_pull_request() { BODY=",\"body\":\"${INPUT_PULL_REQUEST_BODY//$'\n'/\\n}\"" fi - PULL_RESPONSE_DATA="{\"title\":\"${INPUT_PULL_REQUEST_TITLE}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\" ${BODY}}" + PULL_RESPONSE_DATA="{\"title\":\"${INPUT_PULL_REQUEST_TITLE}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${BRANCH}\" ${BODY}}" # create pull request PULL_RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X POST --data "${PULL_RESPONSE_DATA}" "${PULLS_URL}") @@ -172,7 +181,7 @@ create_pull_request() { } push_to_branch() { - LOCALIZATION_BRANCH=${INPUT_LOCALIZATION_BRANCH_NAME} + BRANCH=${INPUT_LOCALIZATION_BRANCH_NAME} REPO_URL="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${INPUT_GITHUB_BASE_URL}/${GITHUB_REPOSITORY}.git" @@ -184,10 +193,10 @@ push_to_branch() { git checkout "${GITHUB_REF#refs/heads/}" fi - if [ -n "$(git show-ref refs/heads/${LOCALIZATION_BRANCH})" ]; then - git checkout "${LOCALIZATION_BRANCH}" + if [ -n "$(git show-ref refs/heads/${BRANCH})" ]; then + git checkout "${BRANCH}" else - git checkout -b "${LOCALIZATION_BRANCH}" + git checkout -b "${BRANCH}" fi git add . @@ -197,12 +206,12 @@ push_to_branch() { return fi - echo "PUSH TO BRANCH ${LOCALIZATION_BRANCH}" + echo "PUSH TO BRANCH ${BRANCH}" git commit --no-verify -m "${INPUT_COMMIT_MESSAGE}" git push --no-verify --force "${REPO_URL}" if [ "$INPUT_CREATE_PULL_REQUEST" = true ]; then - create_pull_request "${LOCALIZATION_BRANCH}" + create_pull_request "${BRANCH}" fi } @@ -327,6 +336,23 @@ if [ "$INPUT_UPLOAD_TRANSLATIONS" = true ]; then upload_translations "$@" fi +if [ "$INPUT_DOWNLOAD_SOURCES" = true ]; then + download_sources "$@" + + if [ "$INPUT_PUSH_SOURCES" = true ]; then + [ -z "${GITHUB_TOKEN}" ] && { + echo "CAN NOT FIND 'GITHUB_TOKEN' IN ENVIRONMENT VARIABLES" + exit 1 + } + + [ -n "${INPUT_GPG_PRIVATE_KEY}" ] && { + setup_commit_signing + } + + push_to_branch + fi +fi + if [ "$INPUT_DOWNLOAD_TRANSLATIONS" = true ]; then download_translations "$@"