Skip to content

Commit a805caf

Browse files
committed
Update svelte config git meta fetcher
1 parent 5138d89 commit a805caf

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

svelte.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import process from 'process';
77

88
// Determine if we are running on Cloudflare Pages
99
const isCloudflare = process.env.CF_PAGES === '1';
10+
const isGithubActions = process.env.GITHUB_ACTIONS === 'true';
1011

1112
// Use the appropriate adapter
1213
const adapter = isCloudflare ? adapterCloudflare : adapterNode;
@@ -15,11 +16,27 @@ function readEnv(path) {
1516
return dotenv.config({ path })?.parsed ?? {};
1617
}
1718

19+
function getGitHash() {
20+
if (isGithubActions) return process.env.GITHUB_SHA;
21+
if (isCloudflare) return process.env.CF_COMMIT_SHA;
22+
23+
return child_process.execSync('git rev-parse HEAD').toString().trim();
24+
}
25+
function getGitBranch() {
26+
if (isGithubActions) return process.env.GITHUB_REF_NAME;
27+
if (isCloudflare) return process.env.CF_BRANCH;
28+
29+
return child_process.execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
30+
}
31+
1832
// Read environment variables from .env files
1933
readEnv('.env.local');
2034
readEnv(`.env.${process.env.NODE_ENV}`);
2135
readEnv('.env');
2236

37+
const commitHash = getGitHash();
38+
const branchName = getGitBranch();
39+
2340
/** @type {import('@sveltejs/kit').Config} */
2441
const config = {
2542
extensions: ['.svelte'],
@@ -68,7 +85,7 @@ const config = {
6885
},
6986
},
7087
version: {
71-
name: process.env.GIT_HASH ?? child_process.execSync('git rev-parse HEAD').toString().trim(),
88+
name: commitHash,
7289
},
7390
},
7491
};

0 commit comments

Comments
 (0)