diff --git a/package.json b/package.json index c48c08f..d4d3aec 100644 --- a/package.json +++ b/package.json @@ -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 .", diff --git a/scripts/set-version.sh b/scripts/set-version.sh new file mode 100755 index 0000000..ec56a7b --- /dev/null +++ b/scripts/set-version.sh @@ -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"