Browse Source
* Adding monorepo functionality to a custom crowdin action * fixing a syntax issue and adding some logging * Reverting the safe.directory change * removing test codepull/46/head
5 changed files with 700 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||||||
|
FROM crowdin/cli:3.7.8 |
||||||
|
|
||||||
|
RUN apk --no-cache add curl git jq gnupg; |
||||||
|
|
||||||
|
COPY . . |
||||||
|
COPY entrypoint.sh /entrypoint.sh |
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"] |
||||||
@ -0,0 +1,21 @@ |
|||||||
|
MIT License |
||||||
|
|
||||||
|
Copyright (c) 2021 Crowdin |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
of this software and associated documentation files (the "Software"), to deal |
||||||
|
in the Software without restriction, including without limitation the rights |
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
copies of the Software, and to permit persons to whom the Software is |
||||||
|
furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all |
||||||
|
copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||||
|
SOFTWARE. |
||||||
@ -0,0 +1,177 @@ |
|||||||
|
[<p align='center'><img src='https://support.crowdin.com/assets/logos/crowdin-dark-symbol.png' data-canonical-src='https://support.crowdin.com/assets/logos/crowdin-dark-symbol.png' width='200' height='200' align='center'/></p>](https://crowdin.com) |
||||||
|
|
||||||
|
# Github Crowdin Action [](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Fcrowdin%2Fgithub-action&text=Easily%20integrate%20the%20localization%20of%20your%20Crowdin%20project%20into%20the%20GitHub%20Actions%20workflow) |
||||||
|
|
||||||
|
[](https://github.com/crowdin/github-action/releases/latest) |
||||||
|
[](https://github.com/crowdin/github-action/releases/latest) |
||||||
|
[](https://github.com/crowdin/github-action/graphs/contributors) |
||||||
|
[](https://github.com/crowdin/github-action/blob/master/LICENSE) |
||||||
|
|
||||||
|
## What does this action do? |
||||||
|
- Uploads sources to Crowdin. |
||||||
|
- Uploads translations to Crowdin. |
||||||
|
- Downloads translations from Crowdin. |
||||||
|
|
||||||
|
## Usage |
||||||
|
Set up a workflow in *.github/workflows/crowdin.yml* (or add a job to your existing workflows). |
||||||
|
|
||||||
|
Read the [Configuring a workflow](https://help.github.com/en/articles/configuring-a-workflow) article for more details on how to create and set up custom workflows. |
||||||
|
```yaml |
||||||
|
name: Crowdin Action |
||||||
|
|
||||||
|
on: |
||||||
|
push: |
||||||
|
branches: [ master ] |
||||||
|
|
||||||
|
jobs: |
||||||
|
synchronize-with-crowdin: |
||||||
|
runs-on: ubuntu-latest |
||||||
|
|
||||||
|
steps: |
||||||
|
|
||||||
|
- name: Checkout |
||||||
|
uses: actions/checkout@v2 |
||||||
|
|
||||||
|
- name: crowdin action |
||||||
|
uses: crowdin/github-action@1.4.9 |
||||||
|
with: |
||||||
|
upload_translations: true |
||||||
|
download_translations: true |
||||||
|
env: |
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
||||||
|
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} |
||||||
|
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} |
||||||
|
``` |
||||||
|
|
||||||
|
:clipboard: To explore the common questions about Crowdin GitHub Action usage visit the [Wiki](https://github.com/crowdin/github-action/wiki). |
||||||
|
|
||||||
|
## Supported options |
||||||
|
The default action is to upload sources. Though, you can set different actions through the “with” options. If you don't want to upload your sources to Crowdin, just set the `upload_sources` option to false. |
||||||
|
|
||||||
|
By default sources and translations are being uploaded to the root of your Crowdin project. Still, if you use branches, you can set the preferred source branch. |
||||||
|
|
||||||
|
You can also specify what GitHub branch you’d like to download your translations to (default translation branch is `l10n_crowdin_action`). |
||||||
|
|
||||||
|
In case you don’t want to download translations from Crowdin (`download_translations: false`), `localization_branch_name` and `create_pull_request` options aren't required either. |
||||||
|
|
||||||
|
```yaml |
||||||
|
- name: crowdin action |
||||||
|
with: |
||||||
|
# upload sources option |
||||||
|
upload_sources: true |
||||||
|
# this can be used to pass down any supported argument of the `upload sources` cli command, e.g. |
||||||
|
upload_sources_args: '--no-auto-update label=web' |
||||||
|
|
||||||
|
# upload translations options |
||||||
|
upload_translations: true |
||||||
|
upload_language: 'uk' |
||||||
|
auto_approve_imported: true |
||||||
|
import_eq_suggestions: true |
||||||
|
# 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 translations options |
||||||
|
download_translations: true |
||||||
|
download_language: 'uk' |
||||||
|
skip_untranslated_strings: true |
||||||
|
skip_untranslated_files: true |
||||||
|
export_only_approved: true |
||||||
|
push_translations: true |
||||||
|
commit_message: 'New Crowdin translations by Github Action' |
||||||
|
# this can be used to pass down any supported argument of the `download translations` cli command, e.g. |
||||||
|
download_translations_args: '--all --skip-untranslated-strings' |
||||||
|
|
||||||
|
# This is the name of the git branch that Crowdin will create when opening a pull request. |
||||||
|
# This branch does NOT need to be manually created. It will be created automatically by the action. |
||||||
|
localization_branch_name: l10n_crowdin_action |
||||||
|
create_pull_request: true |
||||||
|
pull_request_title: 'New Crowdin translations' |
||||||
|
pull_request_body: 'New Crowdin pull request with translations' |
||||||
|
pull_request_labels: 'enhancement, good first issue' |
||||||
|
# This is the name of the git branch to with pull request will be created. |
||||||
|
# If not specified default repository branch will be used. |
||||||
|
pull_request_base_branch_name: not_default_branch |
||||||
|
|
||||||
|
# branch options |
||||||
|
add_crowdin_branch: branch_name |
||||||
|
# Title as it appears to translators |
||||||
|
new_branch_title: 'development / main' |
||||||
|
# Defines branch name and path in resulting translations bundle |
||||||
|
new_branch_export_pattern: '/translations/%two_letters_code%/%original_file_name%' |
||||||
|
# [LOW, NORMAL, HIGH] |
||||||
|
new_branch_priority: 'HIGH' |
||||||
|
|
||||||
|
delete_crowdin_branch: branch_name |
||||||
|
|
||||||
|
# global options |
||||||
|
|
||||||
|
# This is the name of the top-level directory that Crowdin will use for files. |
||||||
|
# Note that this is not a "branch" in the git sense, but more like a top-level directory in your Crowdin project. |
||||||
|
# This branch does NOT need to be manually created. It will be created automatically by the action. |
||||||
|
crowdin_branch_name: l10n_branch |
||||||
|
identity: 'path/to/your/credentials/file' |
||||||
|
config: 'path/to/your/crowdin.yml' |
||||||
|
dryrun_action: true |
||||||
|
|
||||||
|
# GitHub (Enterprise) configuration |
||||||
|
|
||||||
|
github_base_url: github.com |
||||||
|
github_api_base_url: api.[github_base_url] |
||||||
|
github_user_name: Crowdin Bot |
||||||
|
github_user_email: support+bot@crowdin.com |
||||||
|
|
||||||
|
# For signed commits, add your ASCII-armored key and export "gpg --armor --export-secret-key GPG_KEY_ID" |
||||||
|
# Ensure that all emails are the same: for account profile that holds private key, the one specified during key generation, and for commit author (github_user_email parameter) |
||||||
|
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} |
||||||
|
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} |
||||||
|
|
||||||
|
# config options |
||||||
|
|
||||||
|
# This is a numeric id, not to be confused with Crowdin API v1 "project identifier" string |
||||||
|
# See "API v2" on https://crowdin.com/project/<your-project>/settings#api |
||||||
|
project_id: ${{ secrets.CROWDIN_PROJECT_ID }} |
||||||
|
|
||||||
|
# A personal access token, not to be confused with Crowdin API v1 "API key" |
||||||
|
# See https://crowdin.com/settings#api-key to generate a token |
||||||
|
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} |
||||||
|
source: 'path/to/your/file' |
||||||
|
translation: 'file/export/pattern' |
||||||
|
base_url: 'https://crowdin.com' |
||||||
|
base_path: 'project-base-path' |
||||||
|
``` |
||||||
|
|
||||||
|
**Note:** For Crowdin Enterprise `base_url` is required and should be passed in the following way: `base_url: 'https://{organization-name}.crowdin.com'` |
||||||
|
|
||||||
|
For more detailed descriptions of these options, see [`action.yml`](https://github.com/crowdin/github-action/blob/master/action.yml). |
||||||
|
|
||||||
|
### Crowdin configuration file |
||||||
|
|
||||||
|
If your workflow file specifies the `config` property, you'll need to add the following to your [Crowdin configuration file](https://support.crowdin.com/configuration-file/) (e.g. `crowdin.yml`): |
||||||
|
|
||||||
|
```yml |
||||||
|
project_id_env: CROWDIN_PROJECT_ID |
||||||
|
api_token_env: CROWDIN_PERSONAL_TOKEN |
||||||
|
``` |
||||||
|
|
||||||
|
When the workflow runs, the real values of your token and project ID will be injected into the config using the secrets in the environment. |
||||||
|
|
||||||
|
## Contributing |
||||||
|
|
||||||
|
If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines. |
||||||
|
|
||||||
|
## Seeking Assistance |
||||||
|
If you find any problems or would like to suggest a feature, please feel free to file an issue on Github at [Issues Page](https://github.com/crowdin/github-action/issues). |
||||||
|
|
||||||
|
Need help working with Crowdin GitHub Action or have any questions? |
||||||
|
[Contact Customer Success Service](https://crowdin.com/contacts). |
||||||
|
|
||||||
|
## License |
||||||
|
<pre> |
||||||
|
The Crowdin GitHub Action is licensed under the MIT License. |
||||||
|
See the LICENSE file distributed with this work for additional |
||||||
|
information regarding copyright ownership. |
||||||
|
|
||||||
|
Except as contained in the LICENSE file, the name(s) of the above copyright |
||||||
|
holders shall not be used in advertising or otherwise to promote the sale, |
||||||
|
use or other dealings in this Software without prior written authorization. |
||||||
|
</pre> |
||||||
@ -0,0 +1,175 @@ |
|||||||
|
name: 'crowdin-action' |
||||||
|
|
||||||
|
description: 'This action allows you to manage and synchronize localization resources with your Crowdin project' |
||||||
|
|
||||||
|
branding: |
||||||
|
icon: 'refresh-cw' |
||||||
|
color: 'green' |
||||||
|
|
||||||
|
inputs: |
||||||
|
# upload sources options |
||||||
|
upload_sources: |
||||||
|
description: 'Upload sources to Crowdin' |
||||||
|
default: 'true' |
||||||
|
required: false |
||||||
|
upload_sources_args: |
||||||
|
description: 'Additional arguments which will be passed to the `upload sources` cli command' |
||||||
|
default: '' |
||||||
|
required: false |
||||||
|
|
||||||
|
# upload translations options |
||||||
|
upload_translations: |
||||||
|
description: 'Upload translations to Crowdin' |
||||||
|
default: 'false' |
||||||
|
required: false |
||||||
|
upload_language: |
||||||
|
description: 'Use this option to upload translations for a single specified language - Case-Sensitive' |
||||||
|
required: false |
||||||
|
auto_approve_imported: |
||||||
|
description: 'Automatically approves uploaded translations' |
||||||
|
default: 'false' |
||||||
|
required: false |
||||||
|
import_eq_suggestions: |
||||||
|
description: 'Defines whether to add translation if it is equal to source string in Crowdin project' |
||||||
|
default: 'false' |
||||||
|
required: false |
||||||
|
upload_translations_args: |
||||||
|
description: 'Additional arguments which will be passed to the `upload translations` cli command' |
||||||
|
default: '' |
||||||
|
required: false |
||||||
|
|
||||||
|
# download translations options |
||||||
|
download_translations: |
||||||
|
description: 'Make pull request of Crowdin translations' |
||||||
|
default: 'false' |
||||||
|
required: false |
||||||
|
download_language: |
||||||
|
description: 'Use this option to download translations for a single specified language' |
||||||
|
required: false |
||||||
|
skip_untranslated_strings: |
||||||
|
description: 'Skip untranslated strings in exported files (does not work with .docx, .html, .md and other document files)' |
||||||
|
default: 'false' |
||||||
|
required: false |
||||||
|
skip_untranslated_files: |
||||||
|
description: 'Omit downloading not fully translated files' |
||||||
|
default: 'false' |
||||||
|
required: false |
||||||
|
export_only_approved: |
||||||
|
description: 'Include approved translations only in exported files. If not combined with --skip-untranslated-strings option, strings without approval are fulfilled with the source language' |
||||||
|
default: 'false' |
||||||
|
required: false |
||||||
|
push_translations: |
||||||
|
description: 'Download translations with pushing to branch' |
||||||
|
default: 'true' |
||||||
|
required: false |
||||||
|
commit_message: |
||||||
|
description: 'Commit message for download translations' |
||||||
|
default: 'New Crowdin translations by Github Action' |
||||||
|
required: false |
||||||
|
localization_branch_name: |
||||||
|
description: 'To download translations to the specified version branch' |
||||||
|
default: 'l10n_crowdin_action' |
||||||
|
required: false |
||||||
|
create_pull_request: |
||||||
|
description: 'Create pull request after pushing to branch' |
||||||
|
default: 'true' |
||||||
|
required: false |
||||||
|
pull_request_title: |
||||||
|
description: 'The title of the new pull request' |
||||||
|
default: 'New Crowdin translations by Github Action' |
||||||
|
required: false |
||||||
|
pull_request_body: |
||||||
|
description: 'The contents of the pull request' |
||||||
|
required: false |
||||||
|
pull_request_labels: |
||||||
|
description: 'To add labels for created pull request' |
||||||
|
required: false |
||||||
|
pull_request_base_branch_name: |
||||||
|
description: 'Create pull request to specified branch instead of default one' |
||||||
|
required: false |
||||||
|
download_translations_args: |
||||||
|
description: 'Additional arguments which will be passed to the `download translations` cli command' |
||||||
|
default: '' |
||||||
|
required: false |
||||||
|
|
||||||
|
# branch options |
||||||
|
add_crowdin_branch: |
||||||
|
description: 'Option to create specified version branch in your Crowdin project' |
||||||
|
required: false |
||||||
|
new_branch_title: |
||||||
|
description: 'Use to provide more details for translators. Title is available in UI only' |
||||||
|
required: false |
||||||
|
new_branch_export_pattern: |
||||||
|
description: 'Branch export pattern. Defines branch name and path in resulting translations bundle' |
||||||
|
required: false |
||||||
|
new_branch_priority: |
||||||
|
description: 'Defines priority level for each branch [LOW, NORMAL, HIGH]' |
||||||
|
required: false |
||||||
|
|
||||||
|
delete_crowdin_branch: |
||||||
|
description: 'Option to remove specified version branch in your Crowdin project' |
||||||
|
required: false |
||||||
|
|
||||||
|
# global options |
||||||
|
crowdin_branch_name: |
||||||
|
description: 'Option to upload or download files to the specified version branch in your Crowdin project' |
||||||
|
required: false |
||||||
|
identity: |
||||||
|
description: 'Option to specify a path to user-specific credentials, without / at the beginning' |
||||||
|
required: false |
||||||
|
config: |
||||||
|
description: 'Option to specify a path to the configuration file, without / at the beginning' |
||||||
|
required: false |
||||||
|
dryrun_action: |
||||||
|
description: 'Option to preview the list of managed files' |
||||||
|
default: 'false' |
||||||
|
required: false |
||||||
|
|
||||||
|
# GitHub (Enterprise) configuration |
||||||
|
github_base_url: |
||||||
|
description: 'Option to configure the base URL of GitHub server, if using GHE.' |
||||||
|
default: 'github.com' |
||||||
|
required: false |
||||||
|
github_api_base_url: |
||||||
|
description: 'Options to configure the base URL of GitHub server for API requests, if using GHE and different from api.github_base_url.' |
||||||
|
required: false |
||||||
|
github_user_name: |
||||||
|
description: 'Option to configure GitHub user name on commits.' |
||||||
|
default: 'Crowdin Bot' |
||||||
|
required: false |
||||||
|
github_user_email: |
||||||
|
description: 'Option to configure GitHub user email on commits.' |
||||||
|
default: 'support+bot@crowdin.com' |
||||||
|
required: false |
||||||
|
gpg_private_key: |
||||||
|
description: 'GPG private key in ASCII-armored format' |
||||||
|
required: false |
||||||
|
|
||||||
|
# config options |
||||||
|
project_id: |
||||||
|
description: 'Numerical ID of the project' |
||||||
|
required: false |
||||||
|
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, without / at the beginning' |
||||||
|
required: false |
||||||
|
source: |
||||||
|
description: 'Path to the source files, without / at the beginning' |
||||||
|
required: false |
||||||
|
translation: |
||||||
|
description: 'Path to the translation files' |
||||||
|
required: false |
||||||
|
|
||||||
|
# Misc configuration |
||||||
|
working_directory: |
||||||
|
description: "Path to project directory (to support monorepo projects)" |
||||||
|
required: false |
||||||
|
|
||||||
|
runs: |
||||||
|
using: docker |
||||||
|
image: 'Dockerfile' |
||||||
@ -0,0 +1,319 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
if [ "$INPUT_DEBUG_MODE" = true ]; then |
||||||
|
echo '---------------------------' |
||||||
|
printenv |
||||||
|
echo '---------------------------' |
||||||
|
fi |
||||||
|
|
||||||
|
upload_sources() { |
||||||
|
if [ -n "$INPUT_UPLOAD_SOURCES_ARGS" ]; then |
||||||
|
UPLOAD_SOURCES_OPTIONS="${UPLOAD_SOURCES_OPTIONS} ${INPUT_UPLOAD_SOURCES_ARGS}" |
||||||
|
fi |
||||||
|
|
||||||
|
echo "UPLOAD SOURCES" |
||||||
|
crowdin upload sources "$@" $UPLOAD_SOURCES_OPTIONS |
||||||
|
} |
||||||
|
|
||||||
|
upload_translations() { |
||||||
|
if [ -n "$INPUT_UPLOAD_LANGUAGE" ]; then |
||||||
|
UPLOAD_TRANSLATIONS_OPTIONS="${UPLOAD_TRANSLATIONS_OPTIONS} --language=${INPUT_UPLOAD_LANGUAGE}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_AUTO_APPROVE_IMPORTED" = true ]; then |
||||||
|
UPLOAD_TRANSLATIONS_OPTIONS="${UPLOAD_TRANSLATIONS_OPTIONS} --auto-approve-imported" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_IMPORT_EQ_SUGGESTIONS" = true ]; then |
||||||
|
UPLOAD_TRANSLATIONS_OPTIONS="${UPLOAD_TRANSLATIONS_OPTIONS} --import-eq-suggestions" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_UPLOAD_TRANSLATIONS_ARGS" ]; then |
||||||
|
UPLOAD_TRANSLATIONS_OPTIONS="${UPLOAD_TRANSLATIONS_OPTIONS} ${INPUT_UPLOAD_TRANSLATIONS_ARGS}" |
||||||
|
fi |
||||||
|
|
||||||
|
echo "UPLOAD TRANSLATIONS" |
||||||
|
crowdin upload translations "$@" $UPLOAD_TRANSLATIONS_OPTIONS |
||||||
|
} |
||||||
|
|
||||||
|
download_translations() { |
||||||
|
if [ -n "$INPUT_DOWNLOAD_LANGUAGE" ]; then |
||||||
|
DOWNLOAD_TRANSLATIONS_OPTIONS="${DOWNLOAD_TRANSLATIONS_OPTIONS} --language=${INPUT_DOWNLOAD_LANGUAGE}" |
||||||
|
elif [ -n "$INPUT_LANGUAGE" ]; then #back compatibility for older versions |
||||||
|
DOWNLOAD_TRANSLATIONS_OPTIONS="${DOWNLOAD_TRANSLATIONS_OPTIONS} --language=${INPUT_LANGUAGE}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_SKIP_UNTRANSLATED_STRINGS" = true ]; then |
||||||
|
DOWNLOAD_TRANSLATIONS_OPTIONS="${DOWNLOAD_TRANSLATIONS_OPTIONS} --skip-untranslated-strings" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_SKIP_UNTRANSLATED_FILES" = true ]; then |
||||||
|
DOWNLOAD_TRANSLATIONS_OPTIONS="${DOWNLOAD_TRANSLATIONS_OPTIONS} --skip-untranslated-files" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_EXPORT_ONLY_APPROVED" = true ]; then |
||||||
|
DOWNLOAD_TRANSLATIONS_OPTIONS="${DOWNLOAD_TRANSLATIONS_OPTIONS} --export-only-approved" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_DOWNLOAD_TRANSLATIONS_ARGS" ]; then |
||||||
|
DOWNLOAD_TRANSLATIONS_OPTIONS="${DOWNLOAD_TRANSLATIONS_OPTIONS} ${INPUT_DOWNLOAD_TRANSLATIONS_ARGS}" |
||||||
|
fi |
||||||
|
|
||||||
|
echo "DOWNLOAD TRANSLATIONS" |
||||||
|
crowdin download "$@" $DOWNLOAD_TRANSLATIONS_OPTIONS |
||||||
|
} |
||||||
|
|
||||||
|
create_pull_request() { |
||||||
|
LOCALIZATION_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" |
||||||
|
|
||||||
|
if [ -n "$INPUT_GITHUB_API_BASE_URL" ]; then |
||||||
|
REPO_URL="https://${INPUT_GITHUB_API_BASE_URL}/repos/${GITHUB_REPOSITORY}" |
||||||
|
else |
||||||
|
REPO_URL="https://api.${INPUT_GITHUB_BASE_URL}/repos/${GITHUB_REPOSITORY}" |
||||||
|
fi |
||||||
|
|
||||||
|
PULLS_URL="${REPO_URL}/pulls" |
||||||
|
|
||||||
|
echo "CHECK IF ISSET SAME PULL REQUEST" |
||||||
|
|
||||||
|
if [ -n "$INPUT_PULL_REQUEST_BASE_BRANCH_NAME" ]; then |
||||||
|
BASE_BRANCH="$INPUT_PULL_REQUEST_BASE_BRANCH_NAME" |
||||||
|
else |
||||||
|
if [ -n "$GITHUB_HEAD_REF" ]; then |
||||||
|
BASE_BRANCH=${GITHUB_HEAD_REF} |
||||||
|
else |
||||||
|
BASE_BRANCH=${GITHUB_REF#refs/heads/} |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
PULL_REQUESTS_QUERY_PARAMS="?base=${BASE_BRANCH}&head=${LOCALIZATION_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 |
||||||
|
echo "PULL REQUEST ALREADY EXIST" |
||||||
|
else |
||||||
|
echo "CREATE PULL REQUEST" |
||||||
|
|
||||||
|
if [ -n "$INPUT_PULL_REQUEST_BODY" ]; then |
||||||
|
BODY=",\"body\":\"${INPUT_PULL_REQUEST_BODY//$'\n'/\\n}\"" |
||||||
|
fi |
||||||
|
|
||||||
|
PULL_RESPONSE_DATA="{\"title\":\"${INPUT_PULL_REQUEST_TITLE}\", \"base\":\"${BASE_BRANCH}\", \"head\":\"${LOCALIZATION_BRANCH}\" ${BODY}}" |
||||||
|
# create pull request |
||||||
|
PULL_RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X POST --data "${PULL_RESPONSE_DATA}" "${PULLS_URL}") |
||||||
|
|
||||||
|
set +x |
||||||
|
PULL_REQUESTS_URL=$(echo "${PULL_RESPONSE}" | jq '.html_url') |
||||||
|
PULL_REQUESTS_NUMBER=$(echo "${PULL_RESPONSE}" | jq '.number') |
||||||
|
view_debug_output |
||||||
|
|
||||||
|
if [ -n "$INPUT_PULL_REQUEST_LABELS" ]; then |
||||||
|
PULL_REQUEST_LABELS=$(echo "[\"${INPUT_PULL_REQUEST_LABELS}\"]" | sed 's/, \|,/","/g') |
||||||
|
|
||||||
|
if [ "$(echo "$PULL_REQUEST_LABELS" | jq -e . > /dev/null 2>&1; echo $?)" -eq 0 ]; then |
||||||
|
echo "ADD LABELS TO PULL REQUEST" |
||||||
|
|
||||||
|
ISSUE_URL="${REPO_URL}/issues/${PULL_REQUESTS_NUMBER}" |
||||||
|
|
||||||
|
LABELS_DATA="{\"labels\":${PULL_REQUEST_LABELS}}" |
||||||
|
|
||||||
|
# add labels to created pull request |
||||||
|
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" -X PATCH --data "${LABELS_DATA}" "${ISSUE_URL}" |
||||||
|
else |
||||||
|
echo "JSON OF pull_request_labels IS INVALID: ${PULL_REQUEST_LABELS}" |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
echo "PULL REQUEST CREATED: ${PULL_REQUESTS_URL}" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
push_to_branch() { |
||||||
|
LOCALIZATION_BRANCH=${INPUT_LOCALIZATION_BRANCH_NAME} |
||||||
|
|
||||||
|
REPO_URL="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${INPUT_GITHUB_BASE_URL}/${GITHUB_REPOSITORY}.git" |
||||||
|
|
||||||
|
echo "CONFIGURATION GIT USER" |
||||||
|
git config --global user.email "${INPUT_GITHUB_USER_EMAIL}" |
||||||
|
git config --global user.name "${INPUT_GITHUB_USER_NAME}" |
||||||
|
|
||||||
|
if [ ${GITHUB_REF#refs/heads/} != $GITHUB_REF ]; then |
||||||
|
git checkout "${GITHUB_REF#refs/heads/}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$(git show-ref refs/heads/${LOCALIZATION_BRANCH})" ]; then |
||||||
|
git checkout "${LOCALIZATION_BRANCH}" |
||||||
|
else |
||||||
|
git checkout -b "${LOCALIZATION_BRANCH}" |
||||||
|
fi |
||||||
|
|
||||||
|
git add . |
||||||
|
|
||||||
|
if [ ! -n "$(git status -s)" ]; then |
||||||
|
echo "NOTHING TO COMMIT" |
||||||
|
return |
||||||
|
fi |
||||||
|
|
||||||
|
echo "PUSH TO BRANCH ${LOCALIZATION_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}" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
view_debug_output() { |
||||||
|
if [ "$INPUT_DEBUG_MODE" = true ]; then |
||||||
|
set -x |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
setup_commit_signing() { |
||||||
|
echo "FOUND PRIVATE KEY, WILL SETUP GPG KEYSTORE" |
||||||
|
|
||||||
|
echo "${INPUT_GPG_PRIVATE_KEY}" > private.key |
||||||
|
|
||||||
|
gpg --import --batch private.key |
||||||
|
|
||||||
|
GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format=long | grep -o "rsa\d\+\/\(\w\+\)" | head -n1 | sed "s/rsa\d\+\/\(\w\+\)/\1/") |
||||||
|
GPG_KEY_OWNER_NAME=$(gpg --list-secret-keys --keyid-format=long | grep "uid" | sed "s/.\+] \(.\+\) <\(.\+\)>/\1/") |
||||||
|
GPG_KEY_OWNER_EMAIL=$(gpg --list-secret-keys --keyid-format=long | grep "uid" | sed "s/.\+] \(.\+\) <\(.\+\)>/\2/") |
||||||
|
echo "Imported key information:" |
||||||
|
echo " Key id: ${GPG_KEY_ID}" |
||||||
|
echo " Owner name: ${GPG_KEY_OWNER_NAME}" |
||||||
|
echo " Owner email: ${GPG_KEY_OWNER_EMAIL}" |
||||||
|
|
||||||
|
git config --global user.signingkey "$GPG_KEY_ID" |
||||||
|
git config --global commit.gpgsign true |
||||||
|
|
||||||
|
export GPG_TTY=$(tty) |
||||||
|
# generate sign to store passphrase in cache for "git commit" |
||||||
|
echo "test" | gpg --clearsign --pinentry-mode=loopback --passphrase "${INPUT_GPG_PASSPHRASE}" > /dev/null 2>&1 |
||||||
|
|
||||||
|
rm private.key |
||||||
|
} |
||||||
|
|
||||||
|
get_branch_available_options() { |
||||||
|
for OPTION in "$@" ; do |
||||||
|
if echo "$OPTION" | egrep -vq "^(--dryrun|--branch|--source|--translation)"; then |
||||||
|
AVAILABLE_OPTIONS="${AVAILABLE_OPTIONS} ${OPTION}" |
||||||
|
fi |
||||||
|
done |
||||||
|
|
||||||
|
echo "$AVAILABLE_OPTIONS" |
||||||
|
} |
||||||
|
|
||||||
|
echo "STARTING CROWDIN ACTION" |
||||||
|
|
||||||
|
if [ -n "INPUT_WORKING_DIRECTORY" ]; then |
||||||
|
WORKING_DIRECTORY="${GITHUB_WORKSPACE}/${INPUT_WORKING_DIRECTORY}" |
||||||
|
else |
||||||
|
WORKING_DIRECTORY="${GITHUB_WORKSPACE}" |
||||||
|
fi |
||||||
|
|
||||||
|
cd "${WORKING_DIRECTORY}" || exit 1 |
||||||
|
|
||||||
|
git config --global --add safe.directory $GITHUB_WORKSPACE |
||||||
|
|
||||||
|
view_debug_output |
||||||
|
|
||||||
|
set -e |
||||||
|
|
||||||
|
#SET OPTIONS |
||||||
|
set -- --no-progress --no-colors |
||||||
|
|
||||||
|
if [ "$INPUT_DEBUG_MODE" = true ]; then |
||||||
|
set -- "$@" --verbose --debug |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_CROWDIN_BRANCH_NAME" ]; then |
||||||
|
set -- "$@" --branch="${INPUT_CROWDIN_BRANCH_NAME}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_IDENTITY" ]; then |
||||||
|
set -- "$@" --identity="${INPUT_IDENTITY}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_CONFIG" ]; then |
||||||
|
set -- "$@" --config="${INPUT_CONFIG}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_DRYRUN_ACTION" = true ]; then |
||||||
|
set -- "$@" --dryrun |
||||||
|
fi |
||||||
|
|
||||||
|
#SET CONFIG OPTIONS |
||||||
|
if [ -n "$INPUT_PROJECT_ID" ]; then |
||||||
|
set -- "$@" --project-id=${INPUT_PROJECT_ID} |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_TOKEN" ]; then |
||||||
|
set -- "$@" --token="${INPUT_TOKEN}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_BASE_URL" ]; then |
||||||
|
set -- "$@" --base-url="${INPUT_BASE_URL}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_BASE_PATH" ]; then |
||||||
|
set -- "$@" --base-path="${INPUT_BASE_PATH}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_SOURCE" ]; then |
||||||
|
set -- "$@" --source="${INPUT_SOURCE}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_TRANSLATION" ]; then |
||||||
|
set -- "$@" --translation="${INPUT_TRANSLATION}" |
||||||
|
fi |
||||||
|
|
||||||
|
#EXECUTE COMMANDS |
||||||
|
|
||||||
|
if [ -n "$INPUT_ADD_CROWDIN_BRANCH" ]; then |
||||||
|
NEW_BRANCH_OPTIONS=$( get_branch_available_options "$@" ) |
||||||
|
|
||||||
|
if [ -n "$INPUT_NEW_BRANCH_PRIORITY" ]; then |
||||||
|
NEW_BRANCH_OPTIONS="${NEW_BRANCH_OPTIONS} --priority=${INPUT_NEW_BRANCH_PRIORITY}" |
||||||
|
fi |
||||||
|
|
||||||
|
echo "CREATING BRANCH $INPUT_ADD_CROWDIN_BRANCH" |
||||||
|
|
||||||
|
crowdin branch add $INPUT_ADD_CROWDIN_BRANCH $NEW_BRANCH_OPTIONS --title="${INPUT_NEW_BRANCH_TITLE}" --export-pattern="${INPUT_NEW_BRANCH_EXPORT_PATTERN}" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_UPLOAD_SOURCES" = true ]; then |
||||||
|
upload_sources "$@" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_UPLOAD_TRANSLATIONS" = true ]; then |
||||||
|
upload_translations "$@" |
||||||
|
fi |
||||||
|
|
||||||
|
if [ "$INPUT_DOWNLOAD_TRANSLATIONS" = true ]; then |
||||||
|
download_translations "$@" |
||||||
|
|
||||||
|
if [ "$INPUT_PUSH_TRANSLATIONS" = true ]; then |
||||||
|
[ -z "${GITHUB_TOKEN}" ] && { |
||||||
|
echo "CAN NOT FIND 'GITHUB_TOKEN' IN ENVIRONMENT VARIABLES" |
||||||
|
exit 1 |
||||||
|
} |
||||||
|
|
||||||
|
[ -n "${INPUT_GPG_PRIVATE_KEY}" ] && [ -n "${INPUT_GPG_PASSPHRASE}" ] && { |
||||||
|
setup_commit_signing |
||||||
|
} |
||||||
|
|
||||||
|
push_to_branch |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
if [ -n "$INPUT_DELETE_CROWDIN_BRANCH" ]; then |
||||||
|
echo "REMOVING BRANCH $INPUT_DELETE_CROWDIN_BRANCH" |
||||||
|
|
||||||
|
crowdin branch delete $INPUT_DELETE_CROWDIN_BRANCH $( get_branch_available_options "$@" ) |
||||||
|
fi |
||||||
Loading…
Reference in new issue