Skip to content

Commit ae1ee8b

Browse files
strogonoffronaldtse
authored andcommitted
chore(ops): add manual caching
1 parent 1c532c0 commit ae1ee8b

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

.github/workflows/docker.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,57 @@ jobs:
3131

3232
- name: Print Metanorma version
3333
run: metanorma --version
34+
# In case of cache miss, the generate MN XML step will run
35+
# and the cache will be filled after job finishes.
36+
# Next time it’ll be a cache hit, unless sources changed.
37+
# See also “Upload cached Metanorma XML” step, which is important.
38+
- name: Restore cached Metanorma XML, if any
39+
id: cache-mn-xml
40+
uses: actions/cache@v4
41+
env:
42+
cache-name: _site
43+
with:
44+
path: _site
45+
46+
# NOTE: cache key does not include current MN version,
47+
# which means if sources did not change but it’s desirable
48+
# to rebuild XML using a newer MN version it may be impossible to do
49+
# without making a dummy/meaningless change in the content
50+
# to change the hash.
51+
#
52+
# The proper way to address this could be pinning MN version
53+
# somewhere and including it as part of the hash here;
54+
# alternatively, if we really want to always use whatever MN version
55+
# is latest, we could detect that version and include it
56+
# as part of this key.
57+
key: ${{ runner.os }}-mn-${{ env.cache-name }}-${{ hashFiles('sources/00*-v5/**', 'sources/xmi/**', 'sources/liquid_templates/**', 'sources/guidance/**') }}
58+
59+
# We can fuzzy-match latest available cache,
60+
# instead of precise hash.
61+
# This can speed up build in some scenarios,
62+
# but can in theory also cause issues where XML is not updated
63+
# after source changes.
64+
# restore-keys: |
65+
# ${{ runner.os }}-mn-${{ env.cache-name }}-
66+
# ${{ runner.os }}-mn-
67+
# ${{ runner.os }}-
3468

3569
- name: Generate Metanorma XML
3670
uses: actions-mn/build-and-publish@v2
71+
if: steps.cache-mn-xml.outputs.cache-hit != 'true'
3772
with:
3873
destination: artifact
3974
artifact-name: mn
4075
agree-to-terms: true
41-
cache-site-for-manifest: metanorma.yml
76+
77+
# In case of cache hit, we must explicitly upload the _site dir as artifact
78+
- name: Upload cached Metanorma XML
79+
uses: actions/upload-artifact@v4
80+
if: steps.cache-mn-xml.outputs.cache-hit == 'true'
81+
with:
82+
name: mn
83+
path: _site
84+
if-no-files-found: error
4285

4386
fl-build:
4487
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)