Skip to content

Commit

Permalink
Commit ref fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mszula committed Jan 2, 2024
1 parent 2b1c115 commit beacd11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: npm ci
- name: Build
env:
COMMIT_HASH: ${{ toJson(github.sha) }}
VITE_GIT_COMMIT_REF: ${GITHUB_SHA::7}
run: npm run gh-pages-build
- name: Setup Pages
uses: actions/configure-pages@v3
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
target="_blank">mszula</a
>
using Svelte.
<span class="text-xs opacity-30">Version: {window.__COMMIT_HASH__}</span>
<span class="text-xs opacity-30"
>Version: {import.meta.env.VITE_GIT_COMMIT_REF}</span
>
</p>
</aside>
<nav
Expand Down
11 changes: 5 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import * as child_process from "node:child_process";

const commitHash = child_process
.execSync("git rev-parse --short HEAD")
.toString();
if (process.env.VITE_GIT_COMMIT_REF === undefined) {
process.env.VITE_GIT_COMMIT_REF = child_process
.execSync("git rev-parse --short HEAD")
.toString();
}

// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
define: {
__COMMIT_HASH__: process.env.COMMIT_HASH || JSON.stringify(commitHash),
},
});

0 comments on commit beacd11

Please sign in to comment.