Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display git commit version #556

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"prebuild": "pnpm run git-hash",
"build": "next build",
"dev": "next dev",
"lint": "next lint",
Expand All @@ -11,7 +12,8 @@
"prettier": "prettier -c .",
"prettier:fix": "prettier -w .",
"types": "tsc -p tsconfig.json --noEmit",
"eas:registerSchemas": "npx tsx src/lib/eas/registerSchemas"
"eas:registerSchemas": "npx tsx src/lib/eas/registerSchemas",
"git-hash": "node ./scripts/genGitHash.js"
},
"dependencies": {
"@ethereum-attestation-service/eas-sdk": "^2.7.0",
Expand Down
31 changes: 31 additions & 0 deletions packages/interface/scripts/genGitHash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");

const commitHash = execSync('git log --pretty=format:"%h" -n1').toString().trim();

const key = "NEXT_PUBLIC_COMMIT_HASH";

const envFile = path.resolve(__dirname, "../.env");

let data = "";
if (fs.existsSync(envFile)) {
data = fs.readFileSync(envFile, "utf8");
}

const indexOfCommitHash = data.indexOf(key);

if (indexOfCommitHash === -1) {
fs.writeFileSync(envFile, `${data}\n${key}=${commitHash}\n`, "utf8");
} else {
const indexOfNextLine = data.indexOf("\n", indexOfCommitHash);
fs.writeFileSync(
envFile,
data
.slice(0, indexOfCommitHash)
.concat(data.slice(indexOfNextLine + 1))
.concat(`${key}=${commitHash}\n`),
"utf8",
);
}
4 changes: 4 additions & 0 deletions packages/interface/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Image from "next/image";
import { FaGithub, FaDiscord } from "react-icons/fa";
import { FaXTwitter } from "react-icons/fa6";

import { config } from "~/config";

import { Logo } from "./ui/Logo";

export const Footer = (): JSX.Element => (
Expand All @@ -26,6 +28,8 @@ export const Footer = (): JSX.Element => (
</div>

<div className="flex justify-end gap-4">
<p className="text-red flex items-center">Git Version: {config.commitHash}</p>

<a className="flex items-center gap-1" href="https://maci.pse.dev" rel="noreferrer" target="_blank">
<span>Docs</span>

Expand Down
1 change: 1 addition & 0 deletions packages/interface/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const config = {
roundLogo: process.env.NEXT_PUBLIC_ROUND_LOGO,
semaphoreSubgraphUrl: process.env.NEXT_PUBLIC_SEMAPHORE_SUBGRAPH,
treeUrl: process.env.NEXT_PUBLIC_TREE_URL,
commitHash: process.env.NEXT_PUBLIC_COMMIT_HASH,
};

export const theme = {
Expand Down
4 changes: 4 additions & 0 deletions packages/interface/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module.exports = createEnv({

NEXT_PUBLIC_SEMAPHORE_SUBGRAPH: z.string().url().optional(),
NEXT_PUBLIC_TREE_URL: z.string().url().optional(),

NEXT_PUBLIC_COMMIT_HASH: z.string(),
},

/**
Expand Down Expand Up @@ -83,6 +85,8 @@ module.exports = createEnv({

NEXT_PUBLIC_SEMAPHORE_SUBGRAPH: process.env.NEXT_PUBLIC_SEMAPHORE_SUBGRAPH,
NEXT_PUBLIC_TREE_URL: process.env.NEXT_PUBLIC_TREE_URL,

NEXT_PUBLIC_COMMIT_HASH: process.env.NEXT_PUBLIC_COMMIT_HASH,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
Expand Down
11 changes: 10 additions & 1 deletion packages/interface/src/pages/coordinator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { config } from "~/config";
import { Layout } from "~/layouts/DefaultLayout";

const CoordinatorPage = (): JSX.Element => <Layout requireAuth>This is the coordinator page.</Layout>;
const CoordinatorPage = (): JSX.Element => (
<Layout requireAuth>
<div>
<p>This is the coordinator page.</p>

<p>You are using version with commit: {config.commitHash}</p>
</div>
</Layout>
);

export default CoordinatorPage;
Loading