Skip to content

Commit

Permalink
feat: add build info to environment (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoopDog committed Nov 12, 2024
1 parent 3441d03 commit d8c6cb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "./scripts/dev.sh brc-analytics && next dev",
"build:local": "./scripts/build.sh brc-analytics local && next build",
"dev": "./scripts/dev.sh brc-analytics && ./scripts/set-version.sh dev && next dev",
"build:local": "./scripts/build.sh brc-analytics local && ./scripts/set-version.sh && next build",
"start": "npx serve out",
"lint": "next lint --dir .",
"check-format": "prettier --check .",
Expand Down
23 changes: 23 additions & 0 deletions scripts/set-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

TARGET_ENV_FILE=".env.production"
if [ "$1" == "dev" ]; then
TARGET_ENV_FILE=".env.development"
fi

# Get the current git hash
GIT_HASH=$(git rev-parse HEAD)

# Get the current date and time in PST
BUILD_DATE=$(TZ="America/Los_Angeles" date +"%Y-%m-%d %H:%M:%S %Z")

# Get the current code version from git
VERSION=$(git tag --points-at HEAD)

# Append these values as NEXT_PUBLIC variables
echo "NEXT_PUBLIC_GIT_HASH='$GIT_HASH'" >> "$TARGET_ENV_FILE"
echo "NEXT_PUBLIC_BUILD_DATE='$BUILD_DATE'" >> "$TARGET_ENV_FILE"
echo "NEXT_PUBLIC_VERSION='$VERSION'" >> "$TARGET_ENV_FILE"

echo "Environment variables added to $TARGET_ENV_FILE"

0 comments on commit d8c6cb7

Please sign in to comment.