Skip to content

Commit

Permalink
build: allow build ui without git info
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Jun 10, 2024
1 parent 38a6720 commit 995e0bb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
29 changes: 17 additions & 12 deletions ui/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ export function getSha(): string | undefined {
return envs.GITHUB_SHA;
}

export function getVersionTag(): HtmlTagDescriptor {
const commitDate = execSync('git log -1 --format=%cI').toString().trimEnd();
const branchName = execSync('git rev-parse --abbrev-ref HEAD').toString().trimEnd();
const commitHash = execSync('git rev-parse HEAD').toString().trimEnd();
const lastCommitMessage = execSync('git show -s --format=%s').toString().trimEnd();
export function getVersionTag(): HtmlTagDescriptor | null {
try {
const commitDate = execSync('git log -1 --format=%cI').toString().trimEnd();
const branchName = execSync('git rev-parse --abbrev-ref HEAD').toString().trimEnd();
const commitHash = execSync('git rev-parse HEAD').toString().trimEnd();
const lastCommitMessage = execSync('git show -s --format=%s').toString().trimEnd();

return {
tag: "script",
children:
`console.info("Branch: ${branchName}");` +
`console.info("Commit: ${commitHash}");` +
`console.info("Date: ${commitDate}");` +
`console.info("Message: ${lastCommitMessage}");`,
return {
tag: "script",
children:
`console.info("Branch: ${branchName}");` +
`console.info("Commit: ${commitHash}");` +
`console.info("Date: ${commitDate}");` +
`console.info("Message: ${lastCommitMessage}");`,
}
} catch (e) {
console.warn("Failed to get git info", e)
return null;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/src/tool/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {parseResult, Result} from "../generated/schema.ts";
import {Result, parseResult} from "../generated/schema.ts";

export function loadDataFromEmbed(): Result {
const doc = document.querySelector("#data")!;
Expand Down
7 changes: 6 additions & 1 deletion ui/vite.config-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import {defineConfig} from 'vite';
import {build, codecov, commonPlugin, getVersionTag} from "./common";
import {createHtmlPlugin} from "vite-plugin-html";

const tags = [getVersionTag()];
const tags = [];
const versionTag = getVersionTag();
if (versionTag) {
tags.push(versionTag);
}

if (process.env.GSA_TELEMETRY) {
tags.push({
tag: "script",
Expand Down
34 changes: 19 additions & 15 deletions ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {defineConfig} from 'vite';
import {HtmlTagDescriptor, defineConfig} from 'vite';
import {viteSingleFile} from "vite-plugin-singlefile"
import * as fs from "node:fs"
import {build, codecov, commonPlugin, getVersionTag} from "./common";
Expand All @@ -23,26 +23,30 @@ const getPlaceHolder = (): string => {
}
}

const tags: HtmlTagDescriptor[] = [
{
injectTo: "head",
tag: "script",
attrs: {
type: "application/json",
id: "data"
},
children: getPlaceHolder()
},

]
const versionTag = getVersionTag();
if (versionTag) {
tags.push(versionTag);
}

export default defineConfig({
plugins: [
...commonPlugin(),
createHtmlPlugin({
minify: true,
entry: './src/main.tsx',
inject: {
tags: [
{
injectTo: "head",
tag: "script",
attrs: {
type: "application/json",
id: "data"
},
children: getPlaceHolder()
},
getVersionTag(),
]
}
inject: {tags}
}),
viteSingleFile(
{
Expand Down

0 comments on commit 995e0bb

Please sign in to comment.