Skip to content

Commit 9f8a139

Browse files
committed
Prevent deploying the same docs when nothing has changed
Use GitHub Action caching mechanism to store the last built versions, keyed using both this repo's and MacVim's commit. This prevents us from unnecessarily re-generating the page every day and help with browser caching behaviors. We still build the page regardless as it finishes quickly and good for sanity checking that nothing broke. We do allow manual workflow dispatch to always deploy, since that's a manual action that indicates we want to do so.
1 parent d4445d2 commit 9f8a139

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

.github/workflows/ci.yaml

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ jobs:
1919
# Build the page and upload it as an artifact
2020
build:
2121
runs-on: ubuntu-latest
22+
23+
outputs:
24+
docs_commit: ${{ steps.setup-env-vars.outputs.docs_commit }}
25+
macvim_commit: ${{ steps.setup-env-vars.outputs.macvim_commit }}
26+
macvim_commit_cache_hit: ${{ steps.restore-cache-macvim-commit.outputs.cache-hit }}
27+
2228
permissions:
2329
contents: read
2430
steps:
@@ -30,6 +36,32 @@ jobs:
3036
repository: ${{ env.MACVIM_REPO }}
3137
path: 'macvim'
3238

39+
- name: Set up commit / version environmental vars
40+
id: setup-env-vars
41+
run: |
42+
printf 'docs_commit=%s\n' $(git rev-parse HEAD) >> $GITHUB_OUTPUT
43+
44+
cd "$MACVIM_DIR"
45+
printf 'MACVIM_COMMIT=%s\n' $(git rev-parse HEAD) >> $GITHUB_ENV
46+
printf 'MACVIM_VERSION=%s\n' $(${GITHUB_WORKSPACE}/scripts/extract_macvim_version ./src) >> $GITHUB_ENV
47+
printf 'VIM_VERSION=%s\n' $(${GITHUB_WORKSPACE}/scripts/extract_vim_version ./src) >> $GITHUB_ENV
48+
49+
printf 'macvim_commit=%s\n' $(git rev-parse HEAD) >> $GITHUB_OUTPUT
50+
51+
# We cache the last built commit info, so that we could choose not to
52+
# deploy if we have already built this version already. This is useful to
53+
# prevent the daily workflow stomping previously generated versions.
54+
# Useful for preserving browser caching.
55+
# We do make an exception for manual dispatch as that usually means we
56+
# want to re-built the page.
57+
- name: Cache last used MacVim commit
58+
id: restore-cache-macvim-commit
59+
if: ${{ github.event_name != 'workflow_dispatch' }}
60+
uses: actions/cache/restore@v3
61+
with:
62+
path: ${{ github.workspace }}/macvim-last-commit.txt
63+
key: macvim-built-commit-${{ steps.setup-env-vars.outputs.docs_commit}}-${{ steps.setup-env-vars.outputs.macvim_commit }}
64+
3365
- uses: actions/setup-python@v4
3466
with:
3567
python-version: '3.x'
@@ -40,13 +72,6 @@ jobs:
4072
run: |
4173
pip install -r vimhelp/requirements.txt
4274
43-
- name: Set up commit / version environmental vars
44-
run: |
45-
cd "$MACVIM_DIR"
46-
printf 'MACVIM_COMMIT=%s\n' $(git rev-parse HEAD) >> $GITHUB_ENV
47-
printf 'MACVIM_VERSION=%s\n' $(${GITHUB_WORKSPACE}/scripts/extract_macvim_version ./src) >> $GITHUB_ENV
48-
printf 'VIM_VERSION=%s\n' $(${GITHUB_WORKSPACE}/scripts/extract_vim_version ./src) >> $GITHUB_ENV
49-
5075
- name: Build the documentation
5176
run: |
5277
echo "MacVim commit: ${MACVIM_COMMIT}"
@@ -68,7 +93,10 @@ jobs:
6893
deploy:
6994
needs: build
7095

71-
if: ${{ github.ref == 'refs/heads/main' }}
96+
# Only allow deployment if on main branch (environmental protection would
97+
# block it otherwise anyway), and if we haven't already built this version
98+
# already.
99+
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'workflow_dispatch' || needs.build.outputs.macvim_commit_cache_hit != 'true') }}
72100

73101
permissions:
74102
pages: write # to deploy to Pages
@@ -83,3 +111,19 @@ jobs:
83111
- name: Deploy to GitHub Pages
84112
id: deployment
85113
uses: actions/deploy-pages@v1
114+
115+
# Deployment is good. Finish caching the commit info so we won't run
116+
# again until either this repo or MacVim got updated.
117+
- name: Check MacVim last built commit
118+
id: check-macvim-commit
119+
if: ${{ needs.build.outputs.macvim_commit_cache_hit != 'true' && github.event_name != 'workflow_dispatch' }}
120+
run: |
121+
date > "${GITHUB_WORKSPACE}/macvim-last-commit.txt"
122+
123+
- name: Cache last used MacVim commit
124+
id: save-cache-macvim-commit
125+
uses: actions/cache/save@v3
126+
if: ${{ needs.build.outputs.macvim_commit_cache_hit != 'true' && github.event_name != 'workflow_dispatch' }}
127+
with:
128+
path: ${{ github.workspace }}/macvim-last-commit.txt
129+
key: macvim-built-commit-${{ needs.build.outputs.docs_commit }}-${{ needs.build.outputs.macvim_commit }}

notes/Design_Notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ vimhelp was modified to export a tags.json file during build. This file embeds a
1717

1818
Publish the documentation using GitHub pages for simplicity and so we don't have to run a server. Since everything is generated by vimhelp, we don't really need an intermediate step of pushing to a gh-pages branch first. Instead, GitHub has a newer feature that allows us to directly publish the page as an artifact and deploy from it, thus saving us from having to push to a gh-pages branch, which would actually have bogged down the repo by storing useless history.
1919

20-
Currently it's configured to run nightly as of this writing. Ideally we have a way to check whether any change has actually happeed at the MacVim repo but that would require finding some way to store a persistent state in CI, or store a JSON file in the published page that we could query (for the last built commit). Since the whole thing finishes in like 1 minute, there really isn't a pressing need to do so.
20+
Currently it's configured to run nightly as of this writing, but it will only deploy the page if something has changed (otherwise it will just build the artifact but does not deploy it) to help preserve browser caching.

0 commit comments

Comments
 (0)