fix: expose deployment metadata in system info
This commit is contained in:
1 parent
9a35f997b0
commit
ce6fe15aff
9 files changed
+81
-4
No files matched your search
@@ -35,6 +35,8 @@ jobs:
|
||||
EDGE_EVER_DEMO_MODE: "true"
|
||||
EDGE_EVER_DEMO_RESET_CRON: "0 19 * * *"
|
||||
DEMO_DEPLOY_DOMAIN: ${{ secrets.EDGE_EVER_DEMO_CUSTOM_DOMAIN }}
|
||||
EDGE_EVER_DEPLOYMENT_TRIGGER: ${{ github.event_name == 'release' && 'github_release' || 'manual' }}
|
||||
EDGE_EVER_DEPLOYMENT_METHOD: "github_actions"
|
||||
|
||||
steps:
|
||||
- name: Checkout release
|
||||
|
||||
@@ -14,3 +14,20 @@ export const resolveAppVersion = (packageVersion: string, gitDescription: string
|
||||
};
|
||||
|
||||
export const resolveReleaseTimestamp = (releaseTimestamp: string | undefined) => releaseTimestamp?.trim() ?? "";
|
||||
|
||||
export type DeploymentTrigger = "github_release" | "main_push" | "manual" | "unknown";
|
||||
export type DeploymentMethod = "github_actions" | "cloudflare_workers_builds" | "local_cli" | "unknown";
|
||||
|
||||
export const resolveDeploymentTrigger = (trigger: string | undefined): DeploymentTrigger => {
|
||||
if (trigger === "github_release" || trigger === "main_push" || trigger === "manual") {
|
||||
return trigger;
|
||||
}
|
||||
return "unknown";
|
||||
};
|
||||
|
||||
export const resolveDeploymentMethod = (method: string | undefined): DeploymentMethod => {
|
||||
if (method === "github_actions" || method === "cloudflare_workers_builds" || method === "local_cli") {
|
||||
return method;
|
||||
}
|
||||
return "unknown";
|
||||
};
|
||||
@@ -54,6 +54,12 @@ const detectOperatingSystem = (userAgent: string, platform: string) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
const getDeploymentDescription = (t: (key: string) => string) => {
|
||||
const trigger = t(`systemInfo.deploymentTriggers.${__EDGEEVER_DEPLOYMENT_TRIGGER__}`);
|
||||
const method = t(`systemInfo.deploymentMethods.${__EDGEEVER_DEPLOYMENT_METHOD__}`);
|
||||
return `${trigger} · ${method}`;
|
||||
};
|
||||
|
||||
export const getWebSystemInfoItems = (
|
||||
t: (key: string) => string,
|
||||
language: string
|
||||
@@ -73,6 +79,7 @@ export const getWebSystemInfoItems = (
|
||||
: t("systemInfo.unknown"),
|
||||
},
|
||||
{ label: t("systemInfo.build"), value: __EDGEEVER_BUILD_LABEL__ },
|
||||
{ label: t("systemInfo.deployment"), value: getDeploymentDescription(t) },
|
||||
{
|
||||
label: t("systemInfo.browser"),
|
||||
value: detectBrowser(userAgent) ?? t("systemInfo.unknown"),
|
||||
|
||||
Vendored
+2
@@ -5,3 +5,5 @@ declare const __EDGEEVER_BUILD_ID__: string;
|
||||
declare const __EDGEEVER_BUILD_LABEL__: string;
|
||||
declare const __EDGEEVER_APP_VERSION__: string;
|
||||
declare const __EDGEEVER_RELEASED_AT__: string;
|
||||
declare const __EDGEEVER_DEPLOYMENT_TRIGGER__: string;
|
||||
declare const __EDGEEVER_DEPLOYMENT_METHOD__: string;
|
||||
+25
-2
@@ -4,7 +4,7 @@ import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
import { defineConfig } from "vite";
|
||||
import { VitePWA } from "vite-plugin-pwa";
|
||||
import { resolveAppVersion, resolveReleaseTimestamp } from "./build-metadata";
|
||||
import { resolveAppVersion, resolveDeploymentMethod, resolveDeploymentTrigger, resolveReleaseTimestamp } from "./build-metadata";
|
||||
|
||||
const readPackageVersion = () => {
|
||||
try {
|
||||
@@ -34,6 +34,15 @@ const readGitDescription = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const readLatestReleaseCommitTimestamp = () => {
|
||||
try {
|
||||
const releaseTag = execSync('git describe --tags --abbrev=0 --match "v[0-9]*.[0-9]*.[0-9]*" HEAD', { encoding: "utf8" }).trim();
|
||||
return execSync(`git log -1 --format=%cI ${releaseTag}`, { encoding: "utf8" }).trim();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
const buildId = process.env.WORKERS_CI_COMMIT_SHA?.slice(0, 12)
|
||||
?? process.env.CF_PAGES_COMMIT_SHA?.slice(0, 12)
|
||||
?? process.env.GITHUB_SHA?.slice(0, 12)
|
||||
@@ -41,7 +50,19 @@ const buildId = process.env.WORKERS_CI_COMMIT_SHA?.slice(0, 12)
|
||||
?? "local";
|
||||
const gitDescription = readGitDescription();
|
||||
const appVersion = resolveAppVersion(readPackageVersion(), gitDescription);
|
||||
const releaseTimestamp = resolveReleaseTimestamp(process.env.EDGE_EVER_RELEASED_AT);
|
||||
const releaseTimestamp = resolveReleaseTimestamp(process.env.EDGE_EVER_RELEASED_AT) || readLatestReleaseCommitTimestamp();
|
||||
const deploymentTrigger = resolveDeploymentTrigger(
|
||||
process.env.EDGE_EVER_DEPLOYMENT_TRIGGER
|
||||
?? (process.env.WORKERS_CI_COMMIT_SHA ? "main_push" : undefined)
|
||||
);
|
||||
const deploymentMethod = resolveDeploymentMethod(
|
||||
process.env.EDGE_EVER_DEPLOYMENT_METHOD
|
||||
?? (process.env.WORKERS_CI_COMMIT_SHA
|
||||
? "cloudflare_workers_builds"
|
||||
: process.env.GITHUB_ACTIONS
|
||||
? "github_actions"
|
||||
: undefined)
|
||||
);
|
||||
|
||||
export default defineConfig({
|
||||
root: "apps/web",
|
||||
@@ -50,6 +71,8 @@ export default defineConfig({
|
||||
__EDGEEVER_BUILD_ID__: JSON.stringify(buildId),
|
||||
__EDGEEVER_BUILD_LABEL__: JSON.stringify(buildId === "local" ? "local" : buildId.slice(0, 7)),
|
||||
__EDGEEVER_RELEASED_AT__: JSON.stringify(releaseTimestamp),
|
||||
__EDGEEVER_DEPLOYMENT_TRIGGER__: JSON.stringify(deploymentTrigger),
|
||||
__EDGEEVER_DEPLOYMENT_METHOD__: JSON.stringify(deploymentMethod),
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@
|
||||
"deploy:doctor": "bun scripts/cloudflare-deploy.mjs doctor",
|
||||
"deploy:setup": "bun scripts/cloudflare-deploy.mjs setup",
|
||||
"deploy": "bun run build:cloudflare && EDGE_EVER_USE_EXISTING_AUTH_SECRET=true bun run deploy:ci",
|
||||
"deploy:manual": "bun run deploy:doctor && bun run build:cloudflare && bun run deploy:ci",
|
||||
"deploy:manual": "export EDGE_EVER_DEPLOYMENT_TRIGGER=manual EDGE_EVER_DEPLOYMENT_METHOD=local_cli && bun run deploy:doctor && bun run build:cloudflare && bun run deploy:ci",
|
||||
"deploy:ci": "bun run db:migrate:remote && bun run deploy:worker && bun run deploy:verify",
|
||||
"deploy:worker": "bun scripts/run-wrangler.mjs deploy",
|
||||
"deploy:cloudflare-builds": "bun run deploy:ci",
|
||||
|
||||
@@ -196,6 +196,19 @@ export const enUS = {
|
||||
version: "Version",
|
||||
releaseTime: "Release time",
|
||||
build: "Build",
|
||||
deployment: "Deployment",
|
||||
deploymentTriggers: {
|
||||
github_release: "GitHub Release trigger",
|
||||
main_push: "main push trigger",
|
||||
manual: "Manual trigger",
|
||||
unknown: "Unknown trigger",
|
||||
},
|
||||
deploymentMethods: {
|
||||
github_actions: "via GitHub Actions",
|
||||
cloudflare_workers_builds: "via Cloudflare Workers Builds",
|
||||
local_cli: "via local CLI",
|
||||
unknown: "Unknown method",
|
||||
},
|
||||
browser: "Browser",
|
||||
os: "System",
|
||||
language: "Language",
|
||||
|
||||
@@ -196,6 +196,19 @@ export const zhCN = {
|
||||
version: "版本号",
|
||||
releaseTime: "发版时间",
|
||||
build: "构建",
|
||||
deployment: "自动部署方式",
|
||||
deploymentTriggers: {
|
||||
github_release: "正式 Release 触发",
|
||||
main_push: "main 推送触发",
|
||||
manual: "手动触发",
|
||||
unknown: "触发来源未知",
|
||||
},
|
||||
deploymentMethods: {
|
||||
github_actions: "GitHub Actions 执行",
|
||||
cloudflare_workers_builds: "Cloudflare Workers Builds 执行",
|
||||
local_cli: "本地命令执行",
|
||||
unknown: "执行方式未知",
|
||||
},
|
||||
browser: "浏览器",
|
||||
os: "系统",
|
||||
language: "语言",
|
||||
|
||||
@@ -133,7 +133,7 @@ const triggerPayload = (workerTag, repoConnectionUuid, buildTokenUuid) => ({
|
||||
repo_connection_uuid: repoConnectionUuid,
|
||||
build_token_uuid: buildTokenUuid,
|
||||
trigger_name: "Deploy EdgeEver production",
|
||||
build_command: "bun install --frozen-lockfile && bun run build:cloudflare",
|
||||
build_command: "bun install --frozen-lockfile && EDGE_EVER_DEPLOYMENT_TRIGGER=main_push EDGE_EVER_DEPLOYMENT_METHOD=cloudflare_workers_builds bun run build:cloudflare",
|
||||
deploy_command: "bun run deploy:cloudflare-builds",
|
||||
root_directory: "/",
|
||||
branch_includes: ["main"],
|
||||
|
||||
Reference in new issue
Block a user