Skip to content

Commit 8c1ead3

Browse files
committed
Add example with Github Actions
1 parent 86fbd9a commit 8c1ead3

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

docs/setup/adding-a-git-repository.md

+101
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,107 @@ The following configuration options are supported:
232232
!!! note
233233
To make this configuration work properly on your documentation site, you also need to do the CI configuration as described in the [git-revision-date-localized](https://github.com/timvink/mkdocs-git-revision-date-localized-plugin#note-when-using-build-environments) documentation.
234234

235+
[With Github Actions](../publishing-your-site.md#with-github-actions):
236+
237+
=== "Material for MkDocs"
238+
239+
``` yaml hl_lines="14 15"
240+
name: ci # (1)!
241+
on:
242+
push:
243+
branches:
244+
- master # (2)!
245+
- main
246+
permissions:
247+
contents: write
248+
jobs:
249+
deploy:
250+
runs-on: ubuntu-latest
251+
steps:
252+
- uses: actions/checkout@v3
253+
with:
254+
fetch-depth: 0
255+
- uses: actions/setup-python@v4
256+
with:
257+
python-version: 3.x
258+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV # (3)!
259+
- uses: actions/cache@v3
260+
with:
261+
key: mkdocs-material-${{ env.cache_id }}
262+
path: .cache
263+
restore-keys: |
264+
mkdocs-material-
265+
- run: pip install mkdocs-material # (4)!
266+
- run: mkdocs gh-deploy --force
267+
```
268+
269+
1. You can change the name to your liking.
270+
271+
2. At some point, GitHub renamed `master` to `main`. If your default branch
272+
is named `master`, you can safely remove `main`, vice versa.
273+
274+
3. Store the `cache_id` environmental variable to access it later during cache
275+
`key` creation. The name is case-sensitive, so be sure to align it with `${{ env.cache_id }}`.
276+
277+
- The `--utc` option makes sure that each workflow runner uses the same time zone.
278+
- The `%V` format assures a cache update once a week.
279+
- You can change the format to `%F` to have daily cache updates.
280+
281+
You can read the [manual page] to learn more about the formatting options of the `date` command.
282+
283+
4. This is the place to install further [MkDocs plugins] or Markdown
284+
extensions with `pip` to be used during the build:
285+
286+
``` sh
287+
pip install \
288+
mkdocs-material \
289+
mkdocs-awesome-pages-plugin \
290+
...
291+
```
292+
293+
=== "Insiders"
294+
295+
``` yaml hl_lines="15 16"
296+
name: ci
297+
on:
298+
push:
299+
branches:
300+
- master
301+
- main
302+
permissions:
303+
contents: write
304+
jobs:
305+
deploy:
306+
runs-on: ubuntu-latest
307+
if: github.event.repository.fork == false
308+
steps:
309+
- uses: actions/checkout@v3
310+
with:
311+
fetch-depth: 0
312+
- uses: actions/setup-python@v4
313+
with:
314+
python-version: 3.x
315+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
316+
- uses: actions/cache@v3
317+
with:
318+
key: mkdocs-material-${{ env.cache_id }}
319+
path: .cache
320+
restore-keys: |
321+
mkdocs-material-
322+
- run: apt-get install pngquant # (1)!
323+
- run: pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
324+
- run: mkdocs gh-deploy --force
325+
env:
326+
GH_TOKEN: ${{ secrets.GH_TOKEN }} # (2)!
327+
```
328+
329+
1. This step is only necessary if you want to use the
330+
[built-in optimize plugin] to automatically compress images.
331+
332+
2. Remember to set the `GH_TOKEN` environment variable to the value of your
333+
[personal access token] when deploying [Insiders], which can be done
334+
using [GitHub secrets].
335+
235336
[`fallback_to_build_date`](#+git-revision-date-localized.fallback_to_build_date){ #+git-revision-date-localized.fallback_to_build_date }
236337

237338
: :octicons-milestone-24: Default: `false` – Enables falling back to

0 commit comments

Comments
 (0)