fix(release): keep index.html's cache-busting version tags in sync
Some checks are pending
Test and SonarQube / quality (push) Waiting to run
Some checks are pending
Test and SonarQube / quality (push) Waiting to run
static/index.html hardcodes ?v= query strings on style.css, the per-page CSS files and loader.js, plus an app-version meta tag. Nothing kept them in sync with VERSION, so they'd silently drifted to different stale versions each (found live: style.css one release behind, loader.js sixteen releases behind). The static-file middleware marks any CSS/JS request with a ?v= query as max-age=31536000 immutable, so a browser that had ever loaded e.g. magazine.js?v=1.26.10 kept serving that exact response for a year no matter how many times the file changed on disk or how hard the page was force-reloaded. release.py now rewrites every ?v=X.Y.Z and the app-version meta tag to the new version on every release, so a release is what invalidates the cache rather than a manual, easy-to-forget edit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
dd19ce1e5d
commit
03597d37f0
@ -32,9 +32,31 @@ from pathlib import Path
|
||||
REPO_ROOT = Path(__file__).parent.parent
|
||||
VERSION_FILE = REPO_ROOT / "VERSION"
|
||||
CHANGELOG_FILE = REPO_ROOT / "CHANGELOG.md"
|
||||
INDEX_HTML_FILE = REPO_ROOT / "static" / "index.html"
|
||||
GITHUB_REPO = "mARTin-B78/tts-voice-creator-clone-and-design-2"
|
||||
GITHUB_BASE = f"https://github.com/{GITHUB_REPO}"
|
||||
|
||||
# static/index.html hardcodes ?v= cache-busting query strings on style.css,
|
||||
# the per-page CSS files and loader.js, plus an <meta name="app-version">
|
||||
# tag. Nothing previously kept these in sync with VERSION, so they silently
|
||||
# drifted to different stale versions each (seen live: style.css one release
|
||||
# behind, loader.js sixteen releases behind) -- StaticCacheHeadersMiddleware
|
||||
# in server.py marks any *.css/js request WITH a ?v= query
|
||||
# "Cache-Control: public, max-age=31536000, immutable", so once a browser
|
||||
# had fetched e.g. magazine.js?v=1.26.10 it kept serving that exact response
|
||||
# for a year regardless of how many times the file changed on disk or how
|
||||
# hard the page was reloaded. Rewriting every ?v=X.Y.Z to the new version on
|
||||
# every release is what actually invalidates that cache.
|
||||
_VERSION_QUERY_RE = re.compile(r"(\?v=)\d+\.\d+\.\d+")
|
||||
_APP_VERSION_META_RE = re.compile(r'(<meta name="app-version" content=")[^"]*(")')
|
||||
|
||||
|
||||
def bump_index_html(new_str: str) -> str:
|
||||
html = INDEX_HTML_FILE.read_text()
|
||||
html = _VERSION_QUERY_RE.sub(rf"\g<1>{new_str}", html)
|
||||
html = _APP_VERSION_META_RE.sub(rf"\g<1>{new_str}\g<2>", html)
|
||||
return html
|
||||
|
||||
|
||||
def read_version() -> tuple[int, int, int]:
|
||||
text = VERSION_FILE.read_text().strip()
|
||||
@ -124,13 +146,17 @@ def main() -> None:
|
||||
print(f" {line}")
|
||||
print()
|
||||
|
||||
index_html = bump_index_html(new_str)
|
||||
|
||||
if not dry:
|
||||
CHANGELOG_FILE.write_text(changelog)
|
||||
VERSION_FILE.write_text(new_str + "\n")
|
||||
INDEX_HTML_FILE.write_text(index_html)
|
||||
print(f" ✓ Wrote VERSION → {new_str}")
|
||||
print(f" ✓ Wrote CHANGELOG.md")
|
||||
print(f" ✓ Wrote static/index.html cache-busting tags → {new_str}")
|
||||
|
||||
git("add", "VERSION", "CHANGELOG.md")
|
||||
git("add", "VERSION", "CHANGELOG.md", "static/index.html")
|
||||
git("commit", "--no-verify", "-m", f"Release v{new_str}")
|
||||
git("tag", "-a", f"v{new_str}", "-m", f"v{new_str}")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user