Skip to content

Commit 811a073

Browse files
committed
Update cache key creation to use date suffix
1 parent 308afb9 commit 811a073

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

.github/workflows/documentation.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ jobs:
4646
with:
4747
python-version: ${{ env.PYTHON_VERSION }}
4848

49+
- name: Set the date environmental variable
50+
run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
51+
4952
- name: Set up build cache
5053
uses: actions/cache@v3
5154
id: cache
5255
with:
53-
key: mkdocs-material-${{ github.ref }}
56+
key: mkdocs-material-${{ env.cache_id }}
5457
path: .cache
5558
restore-keys: |
5659
mkdocs-material-

docs/publishing-your-site.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ contents:
3838
- uses: actions/setup-python@v4
3939
with:
4040
python-version: 3.x
41+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV # (3)!
4142
- uses: actions/cache@v3
4243
with:
43-
key: mkdocs-material-${{ github.ref }} # (3)!
44+
key: mkdocs-material-${{ env.cache_id }}
4445
path: .cache
4546
restore-keys: |
4647
mkdocs-material-
@@ -53,8 +54,14 @@ contents:
5354
2. At some point, GitHub renamed `master` to `main`. If your default branch
5455
is named `master`, you can safely remove `main`, vice versa.
5556

56-
3. The `github.ref` property assures that the cache will
57-
update on each pull request merge.
57+
3. Store the `cache_id` environmental variable to access it later during cache
58+
`key` creation. The name is case-sensitive, so be sure to align it with `${{ env.cache_id }}`.
59+
60+
- The `--utc` option makes sure that each workflow runner uses the same time zone.
61+
- The `%V` format assures a cache update once a week.
62+
- You can change the format to `%F` to have daily cache updates.
63+
64+
You can read the [manual page] to learn more about the formatting options of the `date` command.
5865

5966
4. This is the place to install further [MkDocs plugins] or Markdown
6067
extensions with `pip` to be used during the build:
@@ -86,9 +93,10 @@ contents:
8693
- uses: actions/setup-python@v4
8794
with:
8895
python-version: 3.x
96+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
8997
- uses: actions/cache@v3
9098
with:
91-
key: mkdocs-material-${{ github.ref }}
99+
key: mkdocs-material-${{ env.cache_id }}
92100
path: .cache
93101
restore-keys: |
94102
mkdocs-material-
@@ -123,6 +131,7 @@ Your documentation should shortly appear at `<username>.github.io/<repository>`.
123131
[built-in optimize plugin]: setup/building-an-optimized-site.md#built-in-optimize-plugin
124132
[GitHub secrets]: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
125133
[publishing source branch]: https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site
134+
[manual page]: https://man7.org/linux/man-pages/man1/date.1.html
126135

127136
### with MkDocs
128137

docs/setup/ensuring-data-privacy.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ carried out. You might want to:
494494
`.cache` directory in between builds. Taking the example from the
495495
[publishing guide], add the following lines:
496496

497-
``` yaml hl_lines="15-20"
497+
``` yaml hl_lines="15-21"
498498
name: ci
499499
on:
500500
push:
@@ -509,9 +509,10 @@ carried out. You might want to:
509509
- uses: actions/setup-python@v4
510510
with:
511511
python-version: 3.x
512+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
512513
- uses: actions/cache@v3
513514
with:
514-
key: mkdocs-material-${{ github.ref }}
515+
key: mkdocs-material-${{ env.cache_id }}
515516
path: .cache
516517
restore-keys: |
517518
mkdocs-material-

0 commit comments

Comments
 (0)