Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0510d06

Browse files
authored
infra: automate continuous deployment (google-gemini#157)
1 parent 4dc98b3 commit 0510d06

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

.gcp/cd.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
steps:
2+
# Install dependencies
3+
- name: 'gcr.io/cloud-builders/npm'
4+
args: ['install']
5+
6+
# Run prerelease versioning script across workspaces with dynamic version
7+
- name: 'gcr.io/cloud-builders/npm'
8+
entrypoint: 'bash'
9+
args:
10+
- '-c'
11+
- |
12+
npm run prerelease:version --workspaces -- --suffix="$(date +%Y%m%d)-$_SHORT_SHA.$_BUILD_ID"
13+
14+
# Run prerelease dependency script across workspaces
15+
- name: 'gcr.io/cloud-builders/npm'
16+
args: ['run', 'prerelease:deps', '--workspaces']
17+
18+
# Authenticate with our registry
19+
- name: gcr.io/cloud-builders/npm
20+
args: ['run', 'artifactregistry-login']
21+
22+
# Publish packages from workspaces with 'dogfood' tag
23+
- name: 'gcr.io/cloud-builders/npm'
24+
args: ['publish', '--tag=head', '--workspaces']

scripts/bind_package_version.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,29 @@ function getBaseVersion() {
1818
// Read root package.json
1919
const rootPackageJsonPath = path.join(rootDir, 'package.json');
2020
const rootPackage = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'));
21-
let baseVersion = rootPackage.version;
21+
return rootPackage.version;
22+
}
2223

24+
function getDefaultSuffix() {
2325
// Get latest commit hash
2426
const commitHash = execSync('git rev-parse --short HEAD', {
2527
encoding: 'utf8',
2628
}).trim();
2729

2830
// Append dev suffix with commit hash
29-
const devSuffix = `-dev-${commitHash}.0`;
30-
return `${baseVersion}${devSuffix}`;
31+
return `dev-${commitHash}.0`;
3132
}
3233

3334
const argv = yargs(hideBin(process.argv))
34-
.option('pkg-version', {
35+
.option('suffix', {
3536
type: 'string',
36-
description: 'Set the package version',
37+
description: 'Set the package version suffix',
3738
})
3839
.parse();
3940

40-
const newVersion = argv['pkg-version'] ?? getBaseVersion();
41-
if (argv['pkg-version']) {
42-
console.log(`Using provided package version (--pkg-version): ${newVersion}`);
43-
} else {
44-
console.log(
45-
`Using base version with dev suffix and commit hash: ${newVersion}`,
46-
);
47-
}
48-
41+
const baseVersion = getBaseVersion();
42+
const suffix = argv['suffix'] ?? getDefaultSuffix();
43+
const newVersion = `${baseVersion}${suffix.length ? '-' : ''}${suffix}`;
4944
console.log(`Setting package version to: ${newVersion}`);
5045

5146
const packageJsonPath = path.join(packageDir, 'package.json');

0 commit comments

Comments
 (0)