infra: automate continuous deployment (#157)
This commit is contained in:
parent
4dc98b3c7e
commit
0510d06ecf
|
@ -0,0 +1,24 @@
|
||||||
|
steps:
|
||||||
|
# Install dependencies
|
||||||
|
- name: 'gcr.io/cloud-builders/npm'
|
||||||
|
args: ['install']
|
||||||
|
|
||||||
|
# Run prerelease versioning script across workspaces with dynamic version
|
||||||
|
- name: 'gcr.io/cloud-builders/npm'
|
||||||
|
entrypoint: 'bash'
|
||||||
|
args:
|
||||||
|
- '-c'
|
||||||
|
- |
|
||||||
|
npm run prerelease:version --workspaces -- --suffix="$(date +%Y%m%d)-$_SHORT_SHA.$_BUILD_ID"
|
||||||
|
|
||||||
|
# Run prerelease dependency script across workspaces
|
||||||
|
- name: 'gcr.io/cloud-builders/npm'
|
||||||
|
args: ['run', 'prerelease:deps', '--workspaces']
|
||||||
|
|
||||||
|
# Authenticate with our registry
|
||||||
|
- name: gcr.io/cloud-builders/npm
|
||||||
|
args: ['run', 'artifactregistry-login']
|
||||||
|
|
||||||
|
# Publish packages from workspaces with 'dogfood' tag
|
||||||
|
- name: 'gcr.io/cloud-builders/npm'
|
||||||
|
args: ['publish', '--tag=head', '--workspaces']
|
|
@ -18,34 +18,29 @@ function getBaseVersion() {
|
||||||
// Read root package.json
|
// Read root package.json
|
||||||
const rootPackageJsonPath = path.join(rootDir, 'package.json');
|
const rootPackageJsonPath = path.join(rootDir, 'package.json');
|
||||||
const rootPackage = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'));
|
const rootPackage = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'));
|
||||||
let baseVersion = rootPackage.version;
|
return rootPackage.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultSuffix() {
|
||||||
// Get latest commit hash
|
// Get latest commit hash
|
||||||
const commitHash = execSync('git rev-parse --short HEAD', {
|
const commitHash = execSync('git rev-parse --short HEAD', {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
}).trim();
|
}).trim();
|
||||||
|
|
||||||
// Append dev suffix with commit hash
|
// Append dev suffix with commit hash
|
||||||
const devSuffix = `-dev-${commitHash}.0`;
|
return `dev-${commitHash}.0`;
|
||||||
return `${baseVersion}${devSuffix}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const argv = yargs(hideBin(process.argv))
|
const argv = yargs(hideBin(process.argv))
|
||||||
.option('pkg-version', {
|
.option('suffix', {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Set the package version',
|
description: 'Set the package version suffix',
|
||||||
})
|
})
|
||||||
.parse();
|
.parse();
|
||||||
|
|
||||||
const newVersion = argv['pkg-version'] ?? getBaseVersion();
|
const baseVersion = getBaseVersion();
|
||||||
if (argv['pkg-version']) {
|
const suffix = argv['suffix'] ?? getDefaultSuffix();
|
||||||
console.log(`Using provided package version (--pkg-version): ${newVersion}`);
|
const newVersion = `${baseVersion}${suffix.length ? '-' : ''}${suffix}`;
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`Using base version with dev suffix and commit hash: ${newVersion}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Setting package version to: ${newVersion}`);
|
console.log(`Setting package version to: ${newVersion}`);
|
||||||
|
|
||||||
const packageJsonPath = path.join(packageDir, 'package.json');
|
const packageJsonPath = path.join(packageDir, 'package.json');
|
||||||
|
|
Loading…
Reference in New Issue