Skip to content

Commit 60debf3

Browse files
docs: add example for source files caching between workflow runs (#298)
1 parent 96b44e6 commit 60debf3

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

docs/EXAMPLES.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [No-crowdin.yml configuration](#no-crowdinyml-configuration)
66
- [Upload sources only](#upload-sources-only)
77
- [Upload sources to the branch in Crowdin](#upload-sources-to-the-branch-in-crowdin)
8+
- [Caching source files for faster uploads](#caching-source-files-for-faster-uploads)
89
- [Download only translations without pushing to a branch](#download-only-translations-without-pushing-to-a-branch)
910
- [Download Bundle](#download-bundle)
1011
- [Advanced Pull Request configuration](#advanced-pull-request-configuration)
@@ -189,6 +190,53 @@ jobs:
189190

190191
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.
191192

193+
### Caching source files for faster uploads
194+
195+
The Crowdin CLI supports a `--cache` parameter for the `upload sources` command that stores source file checksums locally. This allows the CLI to only upload files that have changed, significantly reducing upload time for large projects.
196+
197+
> **Note**
198+
> The cache feature is experimental. For any feedback, visit [Crowdin CLI Discussions](https://github.com/crowdin/crowdin-cli/discussions).
199+
200+
To persist the cache between workflow runs, use the `actions/cache` action to save and restore the cache file located at `~/.crowdin/cache.json`:
201+
202+
```yaml
203+
name: Crowdin Action
204+
205+
on:
206+
push:
207+
branches: [ main ]
208+
209+
jobs:
210+
crowdin:
211+
runs-on: ubuntu-latest
212+
steps:
213+
- name: Checkout
214+
uses: actions/checkout@v4
215+
216+
- name: Cache Crowdin source files
217+
uses: actions/cache@v4
218+
with:
219+
path: ~/.crowdin/cache.json
220+
key: ${{ runner.os }}-crowdin-cache-${{ github.ref_name }}-${{ hashFiles('**/crowdin.yml') }}
221+
restore-keys: |
222+
${{ runner.os }}-crowdin-cache-${{ github.ref_name }}-
223+
224+
- name: Crowdin push
225+
uses: crowdin/github-action@v2
226+
with:
227+
upload_sources: true
228+
upload_translations: false
229+
download_translations: false
230+
upload_sources_args: '--cache'
231+
env:
232+
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
233+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
234+
```
235+
236+
The cache key includes the current branch name and the `crowdin.yml` file hash, so each branch maintains its own cache and the cache will be invalidated when your Crowdin configuration changes. The `restore-keys` ensures that even if the exact key doesn't match (e.g., when `crowdin.yml` changes), a previous cache for the same branch will be restored, which is useful for incremental updates.
237+
238+
Make sure to pass the `--cache` argument to the `upload_sources_args` option to use the cache.
239+
192240
### Download only translations without pushing to a branch
193241

194242
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.

0 commit comments

Comments
 (0)