Skip to content

Commit 584bea1

Browse files
fix: auto-version css/js assets in deploy workflow to prevent stale cache issues
1 parent c7da9db commit 584bea1

5 files changed

Lines changed: 14 additions & 5 deletions

File tree

.github/workflows/deploy-pages.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ jobs:
4141
- name: Setup Pages
4242
uses: actions/configure-pages@v6
4343

44+
- name: Inject asset version
45+
shell: bash
46+
run: |
47+
set -euo pipefail
48+
VERSION="${GITHUB_SHA::12}"
49+
echo "Using asset version: $VERSION"
50+
find website -type f \( -name "*.html" -o -name "*.js" -o -name "*.css" \) \
51+
-exec sed -i "s/__ASSET_VERSION__/$VERSION/g" {} +
52+
4453
- name: Upload artifact
4554
uses: actions/upload-pages-artifact@v5
4655
with:

website/card.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { openHintsDialog } from "./hints-dialog.js";
1+
import { openHintsDialog } from "./hints-dialog.js?v=__ASSET_VERSION__";
22

33
const cardTemplate = document.getElementById("card-template");
44

website/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>MagicMirror² 3rd Party Modules</title>
77
<link rel="icon" type="image/x-icon" href="favicon.svg" />
8-
<link rel="stylesheet" href="index.css" />
8+
<link rel="stylesheet" href="index.css?v=__ASSET_VERSION__" />
99
<link
1010
rel="stylesheet"
1111
href="fonts/line-awesome-1.3.0/css/line-awesome.min.css"
@@ -196,6 +196,6 @@ <h3 id="hints-dialog-title"></h3>
196196
</div>
197197
</dialog>
198198

199-
<script src="script.js" type="module"></script>
199+
<script src="script.js?v=__ASSET_VERSION__" type="module"></script>
200200
</body>
201201
</html>

website/result.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title>Result of the module analysis</title>
55
<link rel="icon" type="image/x-icon" href="favicon.svg" />
6-
<link rel="stylesheet" href="result.css" />
6+
<link rel="stylesheet" href="result.css?v=__ASSET_VERSION__" />
77
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
88
</head>
99
<body>

website/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createCard } from "./card.js";
1+
import { createCard } from "./card.js?v=__ASSET_VERSION__";
22

33
let allModules = [];
44
let skippedModules = [];

0 commit comments

Comments
 (0)