attempting to fix docker image build by generating frontend version information before docker build.

This commit is contained in:
Jason Kulatunga
2022-05-27 12:59:32 -07:00
parent cf1bd3ea6b
commit 3971b37abc
8 changed files with 42 additions and 54 deletions
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
if [[ -z "${CI}" ]]; then
echo "running locally (not in Github Actions). generating version file from git client"
GIT_TAG=`git describe --tags`
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
if [[ "$GIT_BRANCH" == "master" ]]; then
VERSION_INFO="${GIT_TAG}"
else
VERSION_INFO="${GIT_BRANCH}#${GIT_TAG}"
fi
else
echo "running in Github Actions, generating version file from environmental variables"
# https://docs.github.com/en/actions/learn-github-actions/environment-variables
GITHUB_SHA
GITHUB_REF_NAME
GITHUB_REF_TYPE
VERSION_INFO="${GITHUB_REF_NAME}"
if [[ "$GITHUB_REF_TYPE" == "branch" ]]; then
VERSION_INFO="${VERSION_INFO}#${GITHUB_SHA::7}"
fi
fi
echo "writing version file (version: ${VERSION_INFO})"
cat <<EOT > src/environments/versions.ts
// this file is automatically generated by git.version.ts script
export const versionInfo = {
version: '${VERSION_INFO}',
};
EOT
-34
View File
@@ -1,34 +0,0 @@
import { writeFileSync } from 'fs';
import { dedent } from 'tslint/lib/utils';
import { promisify } from 'util';
import * as child from 'child_process';
const exec = promisify(child.exec);
async function createVersionsFile(filename: string) {
let versionInfo = ''
if(process.env.GITHUB_SHA){
// we're in a github action
versionInfo = process.env.GITHUB_REF_NAME
if(process.env.GITHUB_REF_TYPE === 'branch'){
versionInfo += `#${process.env.GITHUB_SHA}`
}
} else {
const tag = (await exec('git describe --tags')).stdout.toString().trim();
const branch = (await exec('git rev-parse --abbrev-ref HEAD')).stdout.toString().trim();
versionInfo = (branch === 'master' ? tag : branch + '#' + tag)
}
const content = dedent`
// this file is automatically generated by git.version.ts script
export const versionInfo = {
version: '${versionInfo}',
};`;
writeFileSync(filename, content, {encoding: 'utf8'});
}
createVersionsFile('src/environments/versions.ts');
-2
View File
@@ -4,10 +4,8 @@
"license": "https://themeforest.net/licenses/standard",
"scripts": {
"ng": "ng",
"prestart": "ts-node -O '{\"module\": \"commonjs\"}' git.version.ts",
"start": "ng serve --open",
"start:mem": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng serve --open",
"prebuild:prod": "ts-node -O '{\"module\": \"commonjs\"}' git.version.ts",
"build": "ng build",
"build:prod": "ng build --prod",
"build:prod:mem": "node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng build --prod",
+1 -2
View File
@@ -1,5 +1,4 @@
// this file is automatically generated by git.version.ts script
export const versionInfo = {
version: 'v0.0.0',
version: 'dev',
};