Skip to content

Commit f13a603

Browse files
docs: enhance caching instructions for Crowdin CLI in workflow examples (#308)
1 parent ce33ce7 commit f13a603

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

docs/EXAMPLES.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ The Crowdin CLI supports a `--cache` parameter for the `upload sources` command
198198
> [!NOTE]
199199
> The cache feature is experimental. For any feedback, visit [Crowdin CLI Discussions](https://github.com/crowdin/crowdin-cli/discussions).
200200

201-
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+
The CLI writes the cache to the `.crowdin` directory in the current working directory. To persist the cache between workflow runs, restore and save this directory using `actions/cache/restore` and `actions/cache/save`.
202+
203+
Example workflow:
202204

203205
```yaml
204206
name: Crowdin Action
@@ -214,13 +216,12 @@ jobs:
214216
- name: Checkout
215217
uses: actions/checkout@v4
216218
217-
- name: Cache Crowdin source files
218-
uses: actions/cache@v4
219+
- name: Restore Crowdin cache
220+
uses: actions/cache/restore@v4
219221
with:
220-
path: ~/.crowdin/cache.json
221-
key: ${{ runner.os }}-crowdin-cache-${{ github.ref_name }}-${{ hashFiles('**/crowdin.yml') }}
222-
restore-keys: |
223-
${{ runner.os }}-crowdin-cache-${{ github.ref_name }}-
222+
path: .crowdin
223+
key: crowdin-${{ github.ref_name }}
224+
restore-keys: crowdin-${{ github.ref_name }}-
224225
225226
- name: Crowdin push
226227
uses: crowdin/github-action@v2
@@ -232,11 +233,16 @@ jobs:
232233
env:
233234
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
234235
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
235-
```
236236
237-
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+
- name: Save Crowdin cache
238+
uses: actions/cache/save@v4
239+
if: always()
240+
with:
241+
path: .crowdin
242+
key: crowdin-${{ github.ref_name }}-${{ github.run_id }}
243+
```
238244

239-
Make sure to pass the `--cache` argument to the `upload_sources_args` option to use the cache.
245+
The restore step first tries an exact match on `crowdin-${{ github.ref_name }}` and falls back to the `restore-keys` prefix to pick up the latest run's cache. The save step always runs (even if the upload fails) and writes a new cache entry keyed with the run ID. Make sure to pass `--cache` in `upload_sources_args` so the CLI uses the cache.
240246

241247
### Download only translations without pushing to a branch
242248

0 commit comments

Comments
 (0)