-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathvite.config.ts
More file actions
72 lines (61 loc) · 2.14 KB
/
vite.config.ts
File metadata and controls
72 lines (61 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { defineConfig } from "vite"
import { execSync } from "child_process"
function getCommitInfo() {
let hash = "unknown"
let tag = "unknown"
let ahead = 0
let prNumber = null
const isGitHubActions = process.env.GITHUB_ACTIONS === 'true'
if (isGitHubActions) {
if (process.env.GITHUB_EVENT_NAME === 'pull_request' && process.env.GITHUB_PR_HEAD_SHA) {
hash = process.env.GITHUB_PR_HEAD_SHA.substring(0, 8)
prNumber = process.env.GITHUB_PR_NUMBER
tag = `PR #${prNumber}`
ahead = 0
console.log(`GitHub Actions PR build: hash=${hash}, PR=${prNumber}`)
} else {
hash = process.env.GITHUB_SHA?.substring(0, 8) || "unknown"
}
if (process.env.GITHUB_REF?.startsWith('refs/tags/')) {
tag = process.env.GITHUB_REF.replace('refs/tags/', '')
ahead = 0
console.log(`GitHub Actions tag build: hash=${hash}, tag=${tag}`)
} else {
tag = process.env.GITHUB_REF_NAME || "unknown"
ahead = 0
console.log(`GitHub Actions branch build: hash=${hash}, ref=${tag}`)
}
return { hash, tag, ahead, prNumber }
}
try {
hash = execSync("git rev-parse --short=8 HEAD", { encoding: "utf8" }).trim()
try {
execSync("git fetch --tags --force", { stdio: 'ignore' })
tag = execSync("git describe --tags --abbrev=0", { encoding: "utf8" }).trim()
try {
const aheadOutput = execSync(`git rev-list --count ${tag}..HEAD`, { encoding: "utf8" }).trim()
ahead = parseInt(aheadOutput, 10) || 0
} catch (countError) {
console.warn("Could not count commits ahead:", countError.message)
}
} catch (tagError) {
console.warn("Could not get git tag info:", tagError.message)
tag = "dev"
}
console.log(`Local build: hash=${hash}, tag=${tag}, ahead=${ahead}`)
} catch (error) {
console.warn("Could not get git commit info:", error.message)
hash = "unknown"
tag = "unknown"
}
return { hash, tag, ahead, prNumber }
}
export default defineConfig({
define: {
__COMMIT_INFO__: JSON.stringify(getCommitInfo()),
},
server: {
port: process.env.PORT ? parseInt(process.env.PORT) : 5173
},
plugins: [],
})