Skip to content

Commit

Permalink
feat: add build version info to environment (#64) (#65)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: hunterckx <118154470+hunterckx@users.noreply.github.com>
  • Loading branch information
NoopDog and hunterckx authored Nov 13, 2024
1 parent 56e349a commit ead8777
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.0.0",
"private": true,
"scripts": {
"dev": "./scripts/dev.sh hprc-data-explorer && next dev",
"build:local": "./scripts/build.sh hprc-data-explorer local && next build",
"dev": "./scripts/dev.sh hprc-data-explorer && ./scripts/set-version.sh dev && next dev",
"build:local": "./scripts/build.sh hprc-data-explorer 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 ead8777

Please sign in to comment.