Skip to content

Commit ee4ab4e

Browse files
feat: add 'command' and 'command_args' options (#176)
- deprecate the _branch options_ in favor of the new _command options_ - add the `test-action.yml` GitHub workflow to test the Action - refine Readme - improve Examples - enforce conventional commits specification
1 parent 3133cc9 commit ee4ab4e

File tree

8 files changed

+190
-52
lines changed

8 files changed

+190
-52
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: lint-pr-title
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- reopened
8+
- edited
9+
- synchronize
10+
11+
jobs:
12+
main:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: amannn/action-semantic-pull-request@v5
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test-action.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'test'
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- '*'
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Crowdin Action
17+
uses: ./
18+
with:
19+
command: 'push'
20+
command_args: '-h'
21+
22+
- name: Get CLI version
23+
uses: ./
24+
with:
25+
command: 'init'
26+
command_args: '-V'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ Unsure where to begin contributing to Crowdin Action? You can start by looking t
6363

6464
Before sending your pull requests, make sure you followed the list below:
6565

66-
- Read this guidelines.
66+
- Read these guidelines.
6767
- Read [Code of Conduct](/CODE_OF_CONDUCT.md).
6868
- Ensure that your code adheres to standard conventions, as used in the rest of the project.
6969
- Ensure that your changes are well tested.
70+
71+
> **Note**
72+
> This project uses the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification for commit messages and PR titles.

EXAMPLES.md

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
- [When a new GitHub Release is published](#when-a-new-github-release-is-published)
1717
- [Dealing with concurrency](#dealing-with-concurrency)
1818
- [Handling parallel runs](#handling-parallel-runs)
19+
- [Tips and tricks](#tips-and-tricks)
20+
- [Checking the translation progress](#checking-the-translation-progress)
21+
- [Pre-Translation](#pre-translation)
1922

2023
---
2124

@@ -106,18 +109,17 @@ jobs:
106109
with:
107110
upload_sources: true
108111
upload_translations: false
109-
110-
# Sources pattern
111-
source: src/locale/en.json
112-
# Translations pattern
113-
translation: src/locale/%android_code%.json
114-
115-
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
116-
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
112+
source: src/locale/en.json # Sources pattern
113+
translation: src/locale/%android_code%.json # Translations pattern
114+
project_id: ${{ secrets.CROWDIN_PROJECT_ID }} # Crowdin Project ID
115+
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} # Crowdin Personal Access Token
117116
env:
118117
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119118
```
120119
120+
> **Note**
121+
> To avoid any conflicts, do not use the `crowdin.yml` file in the repository when using the above configuration approach.
122+
121123
### Upload sources only
122124

123125
```yaml
@@ -167,16 +169,17 @@ jobs:
167169
upload_sources: true
168170
upload_translations: false
169171
download_translations: false
170-
crowdin_branch_name: "${{ env.BRANCH_NAME }}"
172+
crowdin_branch_name: ${{ env.BRANCH_NAME }}
171173
env:
172174
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
173175
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
174176
```
175177

178+
Note that the value of the `crowdin_branch_name` is `env.BRANCH_NAME` - this is the name of the current branch on which the action is running.
179+
176180
### Download only translations without pushing to a branch
177181

178-
It's possible only to download the translations without immediate PR creation.
179-
It allows you to post-process the downloaded translations and create a PR later.
182+
It's possible to just download the translations without creating a PR immediately. It allows you to post-process the downloaded translations and create a PR later.
180183

181184
```yaml
182185
name: Crowdin Action
@@ -205,6 +208,8 @@ jobs:
205208
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
206209
```
207210

211+
You can use the [Create Pull Request](https://github.com/marketplace/actions/create-pull-request) GitHub Action to create a PR with the downloaded translations.
212+
208213
### Advanced Pull Request configuration
209214

210215
There is a possibility to specify labels, assignees, reviewers for PR created by the Action.
@@ -247,19 +252,22 @@ jobs:
247252

248253
### Custom `crowdin.yml` file location
249254

255+
By default, the Action looks for the `crowdin.yml` file in the repository root. You can specify a custom location of the configuration file:
256+
250257
```yaml
251-
...
258+
# ...
252259
253260
- name: Crowdin
254261
uses: crowdin/github-action@v1
255262
with:
256263
config: '.github/crowdin.yml'
257-
258-
...
264+
#...
259265
```
260266

261267
### Separate PRs for each target language
262268

269+
You can use the [`matrix`](https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs) feature of GitHub Actions to create separate PRs for each target language:
270+
263271
```yaml
264272
name: Crowdin Action
265273
@@ -296,7 +304,6 @@ jobs:
296304
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
297305
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
298306
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
299-
300307
```
301308

302309
## Triggers
@@ -356,3 +363,60 @@ strategy:
356363
```
357364

358365
[Read more](https://github.com/crowdin/github-action/wiki/Handling-parallel-runs)
366+
367+
## Tips and Tricks
368+
369+
### Checking the translation progress
370+
371+
```yaml
372+
name: Crowdin Action
373+
374+
on:
375+
push:
376+
branches: [ main ]
377+
378+
jobs:
379+
crowdin:
380+
runs-on: ubuntu-latest
381+
steps:
382+
- name: Checkout
383+
uses: actions/checkout@v3
384+
385+
- name: Check translation progress
386+
uses: crowdin/github-action@v1
387+
with:
388+
command: 'status translation'
389+
command_args: '--fail-if-incomplete'
390+
```
391+
392+
In the example above, the workflow will fail if the translation progress is less than 100%.
393+
394+
Visit the [official documentation](https://crowdin.github.io/crowdin-cli/commands/crowdin-status) to learn more about the available translation status options.
395+
396+
### Pre-Translation
397+
398+
```yaml
399+
name: Crowdin Action
400+
401+
on:
402+
push:
403+
branches: [ main ]
404+
405+
jobs:
406+
crowdin:
407+
runs-on: ubuntu-latest
408+
steps:
409+
- name: Checkout
410+
uses: actions/checkout@v3
411+
412+
- name: Pre-translate
413+
uses: crowdin/github-action@v1
414+
with:
415+
command: 'pre-translate'
416+
command_args: '--language uk --method tm'
417+
env:
418+
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
419+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
420+
```
421+
422+
Visit the [official documentation](https://crowdin.github.io/crowdin-cli/commands/crowdin-pre-translate) to learn more about the available pre-translation options.

README.md

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,30 @@ A GitHub action to manage and synchronize localization resources with your Crowd
1111
[**`Configuration File`**](https://developer.crowdin.com/configuration-file/) |
1212
[**`Wiki`**](https://github.com/crowdin/github-action/wiki)
1313

14+
[![test](https://github.com/crowdin/github-action/actions/workflows/test-action.yml/badge.svg)](https://github.com/crowdin/github-action/actions/workflows/test-action.yml)
1415
[![GitHub Used by](https://img.shields.io/static/v1?label=Used%20by&message=7k&color=brightgreen&logo=github&cacheSeconds=10000)](https://github.com/crowdin/github-action/network/dependents?package_id=UGFja2FnZS0yOTQyNTU3MzA0)
1516
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/crowdin/github-action?cacheSeconds=5000&logo=github)](https://github.com/crowdin/github-action/releases/latest)
16-
[![GitHub Release Date](https://img.shields.io/github/release-date/crowdin/github-action?cacheSeconds=5000)](https://github.com/crowdin/github-action/releases/latest)
1717
[![GitHub contributors](https://img.shields.io/github/contributors/crowdin/github-action?cacheSeconds=5000)](https://github.com/crowdin/github-action/graphs/contributors)
1818
[![GitHub](https://img.shields.io/github/license/crowdin/github-action?cacheSeconds=50000)](https://github.com/crowdin/github-action/blob/master/LICENSE)
1919

2020
</div>
2121

2222
## What does this action do?
23-
- Uploads sources to Crowdin.
24-
- Uploads translations to Crowdin.
23+
24+
This action allows you to easily integrate and automate the localization of your Crowdin project into the GitHub Actions workflow.
25+
26+
- Upload sources to Crowdin.
27+
- Upload translations to Crowdin.
2528
- Downloads translations from Crowdin.
29+
- Download sources from Crowdin.
2630
- Creates a PR with the translations.
31+
- Run any Crowdin CLI command.
2732

2833
## Usage
34+
2935
Set up a workflow in *.github/workflows/crowdin.yml* (or add a job to your existing workflows).
3036

31-
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.
37+
Read the [Configuring a workflow](https://help.github.com/en/articles/configuring-a-workflow) article for more details on creating and setting up GitHub workflows.
3238

3339
```yaml
3440
name: Crowdin Action
@@ -67,12 +73,9 @@ jobs:
6773
> **Note**
6874
> In case you want to use an [automatic GitHub authentication token](https://docs.github.com/en/actions/security-guides/automatic-token-authentication), you need to assign the [`write` permission to your job](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs) and [allow GH Actions to create Pull Requests](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests).
6975

70-
:file_folder: For more examples see the [EXAMPLES.md](/EXAMPLES.md)
71-
72-
:clipboard: To explore the common questions about Crowdin GitHub Action usage visit the [Wiki](https://github.com/crowdin/github-action/wiki).
73-
7476
## Supported options
75-
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.
77+
78+
The default action is to upload sources. However, you can set different actions using the "with" options. If you don't want to upload your sources to Crowdin, just set the `upload_sources` option to false.
7679

7780
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.
7881

@@ -82,6 +85,7 @@ In case you don’t want to download translations from Crowdin (`download_transl
8285

8386
```yaml
8487
- name: crowdin action
88+
uses: crowdin/github-action@v1
8589
with:
8690
# Upload sources option
8791
upload_sources: true
@@ -126,18 +130,6 @@ In case you don’t want to download translations from Crowdin (`download_transl
126130
# If not specified default repository branch will be used.
127131
pull_request_base_branch_name: not_default_branch
128132

129-
# Branch options
130-
131-
add_crowdin_branch: branch_name
132-
# Title as it appears to translators
133-
new_branch_title: 'development / main'
134-
# Defines branch name and path in resulting translations bundle
135-
new_branch_export_pattern: '/translations/%two_letters_code%/%original_file_name%'
136-
# [LOW, NORMAL, HIGH]
137-
new_branch_priority: 'HIGH'
138-
139-
delete_crowdin_branch: branch_name
140-
141133
# Global options
142134

143135
# This is the name of the top-level directory that Crowdin will use for files.
@@ -160,22 +152,33 @@ In case you don’t want to download translations from Crowdin (`download_transl
160152
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
161153

162154
# Config options
163-
164-
# The numeric project ID. Visit the Tools > API section in your Crowdin project
165-
project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
166-
167-
# A Personal Access Token (see https://crowdin.com/settings#api-key)
168-
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
155+
token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} # A Personal Access Token (see https://crowdin.com/settings#api-key)
156+
project_id: ${{ secrets.CROWDIN_PROJECT_ID }} # The numeric project ID. Visit the Tools > API section in your Crowdin project
169157
source: 'path/to/your/file'
170158
translation: 'file/export/pattern'
171-
base_url: 'https://crowdin.com'
172-
base_path: 'project-base-path'
159+
base_url: 'https://api.crowdin.com'
160+
base_path: 'project-base-path' # Default: '.'
173161
```
174162
175-
**Note:** For Crowdin Enterprise `base_url` is required and should be passed in the following way: `base_url: 'https://{organization-name}.crowdin.com'`
176-
177163
For more detailed descriptions of these options, see [`action.yml`](https://github.com/crowdin/github-action/blob/master/action.yml).
178164

165+
> **Note**
166+
> The `base_url` is required For Crowdin Enterprise and should be passed in the following way: `base_url: 'https://{organization-name}.api.crowdin.com'`
167+
168+
### Crowdin CLI command
169+
170+
You can also run any other Crowdin CLI command by specifying the `command` and `command_args` _(optional)_ options. For example:
171+
172+
```yaml
173+
- name: crowdin action
174+
uses: crowdin/github-action@v1
175+
with:
176+
command: 'pre-translate'
177+
command_args: '-l uk --method tm --branch main'
178+
```
179+
180+
To see the full list of available commands, visit the [official documentation](https://crowdin.github.io/crowdin-cli/).
181+
179182
### Crowdin configuration file
180183

181184
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`):
@@ -189,15 +192,14 @@ When the workflow runs, the real values of your token and project ID will be inj
189192

190193
## Contributing
191194

192-
If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
195+
If you would like to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
193196

194197
## Seeking Assistance
195-
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).
196198

197-
Need help working with Crowdin GitHub Action or have any questions?
198-
[Contact Customer Success Service](https://crowdin.com/contacts).
199+
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).
199200

200201
## License
202+
201203
<pre>
202204
The Crowdin GitHub Action is licensed under the MIT License.
203205
See the LICENSE file distributed with this work for additional

0 commit comments

Comments
 (0)