Bake commit hash into build; log it via console.info on startup
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:
parent
93e5660a5c
commit
38f0c04b3e
@ -27,6 +27,8 @@ jobs:
|
||||
run: npm run test:run
|
||||
|
||||
- name: Build (single-file bundle)
|
||||
env:
|
||||
VITE_COMMIT_HASH: ${{ github.sha }}
|
||||
run: npm run build
|
||||
|
||||
- name: Verify build output
|
||||
@ -50,6 +52,8 @@ jobs:
|
||||
run: npm ci
|
||||
|
||||
- name: Build (single-file bundle)
|
||||
env:
|
||||
VITE_COMMIT_HASH: ${{ github.sha }}
|
||||
run: npm run build
|
||||
|
||||
- name: Verify build output
|
||||
|
||||
3
dist/index.html
vendored
3
dist/index.html
vendored
@ -8574,6 +8574,9 @@ delegate([
|
||||
"touchstart",
|
||||
"touchend"
|
||||
]);
|
||||
//#endregion
|
||||
//#region src/main.js
|
||||
console.info({ commit_hash: "93e5660a5c76fd41088193f5ca3e3a35cd7478b1" });
|
||||
mount(App, { target: document.getElementById("app") });
|
||||
//#endregion</script>
|
||||
<style rel="stylesheet" crossorigin>/* ===== CSS Reset & Base ===== */
|
||||
|
||||
@ -2,6 +2,9 @@ import { mount } from 'svelte'
|
||||
import './styles/main.css'
|
||||
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, {
|
||||
target: document.getElementById('app'),
|
||||
})
|
||||
|
||||
@ -1,9 +1,25 @@
|
||||
import { execSync } from 'node:child_process'
|
||||
import { defineConfig } from 'vite'
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||
import { viteSingleFile } from 'vite-plugin-singlefile'
|
||||
|
||||
// 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 }) => ({
|
||||
define: {
|
||||
__WEATHER_COMMIT__: JSON.stringify(getCommitHash()),
|
||||
},
|
||||
plugins: [
|
||||
svelte(),
|
||||
...(command === 'build'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user