35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
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');
|