Bake commit hash into build; log it via console.info on startup
Some checks failed
Test, Build & Deploy / test-and-build (push) Successful in 38s
Test, Build & Deploy / deploy (push) Failing after 20s

Build injects __WEATHER_COMMIT__ (VITE_COMMIT_HASH from CI's github.sha on
branch builds, git rev-parse HEAD locally) and main.js logs
console.info({ commit_hash }) so a deploy can be verified to match the
commit that produced it.
This commit is contained in:
hermes-explorigin 2026-08-30 19:01:13 +00:00
parent 93e5660a5c
commit 38f0c04b3e
4 changed files with 26 additions and 0 deletions

View File

@ -27,6 +27,8 @@ jobs:
run: npm run test:run run: npm run test:run
- name: Build (single-file bundle) - name: Build (single-file bundle)
env:
VITE_COMMIT_HASH: ${{ github.sha }}
run: npm run build run: npm run build
- name: Verify build output - name: Verify build output
@ -50,6 +52,8 @@ jobs:
run: npm ci run: npm ci
- name: Build (single-file bundle) - name: Build (single-file bundle)
env:
VITE_COMMIT_HASH: ${{ github.sha }}
run: npm run build run: npm run build
- name: Verify build output - name: Verify build output

3
dist/index.html vendored
View File

@ -8574,6 +8574,9 @@ delegate([
"touchstart", "touchstart",
"touchend" "touchend"
]); ]);
//#endregion
//#region src/main.js
console.info({ commit_hash: "93e5660a5c76fd41088193f5ca3e3a35cd7478b1" });
mount(App, { target: document.getElementById("app") }); mount(App, { target: document.getElementById("app") });
//#endregion</script> //#endregion</script>
<style rel="stylesheet" crossorigin>/* ===== CSS Reset & Base ===== */ <style rel="stylesheet" crossorigin>/* ===== CSS Reset & Base ===== */

View File

@ -2,6 +2,9 @@ import { mount } from 'svelte'
import './styles/main.css' import './styles/main.css'
import App from './App.svelte' import App from './App.svelte'
// Report the baked-in commit hash on startup (handy for verifying a deploy).
console.info({ commit_hash: __WEATHER_COMMIT__ })
const app = mount(App, { const app = mount(App, {
target: document.getElementById('app'), target: document.getElementById('app'),
}) })

View File

@ -1,9 +1,25 @@
import { execSync } from 'node:child_process'
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte' import { svelte } from '@sveltejs/vite-plugin-svelte'
import { viteSingleFile } from 'vite-plugin-singlefile' import { viteSingleFile } from 'vite-plugin-singlefile'
// https://vite.dev/config/ // https://vite.dev/config/
// Bake the commit hash into the bundle at build time so a deployed app can
// report exactly which commit produced it (logged via console.info at startup).
// CI sets VITE_COMMIT_HASH=${{ github.sha }}; local builds fall back to git HEAD.
function getCommitHash() {
if (process.env.VITE_COMMIT_HASH) return process.env.VITE_COMMIT_HASH
try {
return execSync('git rev-parse HEAD').toString().trim()
} catch {
return 'unknown'
}
}
export default defineConfig(({ command }) => ({ export default defineConfig(({ command }) => ({
define: {
__WEATHER_COMMIT__: JSON.stringify(getCommitHash()),
},
plugins: [ plugins: [
svelte(), svelte(),
...(command === 'build' ...(command === 'build'