fix: branch name env variable

This commit is contained in:
fbwoolf
2023-02-13 19:11:00 -06:00
committed by kyranjamie
parent 73bb4e3f64
commit afad562466
2 changed files with 12 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ const webpack = require('webpack');
const { version: _version } = require('../package.json');
const generateManifest = require('../scripts/generate-manifest');
const { execSync } = require('child_process');
const Dotenv = require('dotenv-webpack');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -26,6 +27,16 @@ const IS_DEV = NODE_ENV === 'development';
const IS_PROD = !IS_DEV;
const MAIN_BRANCH = 'refs/heads/main';
// https://stackoverflow.com/a/69167552
function executeGitCommand(command) {
return execSync(command)
.toString('utf8')
.replace(/[\n\r\s]+$/, '');
}
const BRANCH_NAME = executeGitCommand('git rev-parse --abbrev-ref HEAD');
process.env.BRANCH_NAME = BRANCH_NAME;
// For non main branch builds, add a random number
const getVersionWithRandomSuffix = ref => {
if (ref === MAIN_BRANCH || !ref || IS_PUBLISHING) return _version;