Skip to content

Commit

Permalink
feat: add git commit version to organizer dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
kittybest committed Dec 17, 2024
1 parent de29d50 commit 2dd3260
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
9 changes: 5 additions & 4 deletions packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev",
"build": "pnpm run git-hash && next build",
"dev": "pnpm run git-hash && next dev",
"lint": "next lint",
"lint:fix": "next lint --fix",
"start": "next start",
"start": "pnpm run git-hash && next start",
"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;

0 comments on commit 2dd3260

Please sign in to comment.