From 0510d06ecfd58a29ea0e0e540eecf8ef33c3153e Mon Sep 17 00:00:00 2001 From: Brandon Keiji Date: Thu, 24 Apr 2025 21:36:58 +0000 Subject: [PATCH] infra: automate continuous deployment (#157) --- .gcp/cd.yaml | 24 ++++++++++++++++++++++++ scripts/bind_package_version.js | 23 +++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 .gcp/cd.yaml diff --git a/.gcp/cd.yaml b/.gcp/cd.yaml new file mode 100644 index 00000000..f3154efb --- /dev/null +++ b/.gcp/cd.yaml @@ -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'] diff --git a/scripts/bind_package_version.js b/scripts/bind_package_version.js index b0e56f2f..35c662d3 100644 --- a/scripts/bind_package_version.js +++ b/scripts/bind_package_version.js @@ -18,34 +18,29 @@ function getBaseVersion() { // Read root package.json const rootPackageJsonPath = path.join(rootDir, 'package.json'); const rootPackage = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8')); - let baseVersion = rootPackage.version; + return rootPackage.version; +} +function getDefaultSuffix() { // Get latest commit hash const commitHash = execSync('git rev-parse --short HEAD', { encoding: 'utf8', }).trim(); // Append dev suffix with commit hash - const devSuffix = `-dev-${commitHash}.0`; - return `${baseVersion}${devSuffix}`; + return `dev-${commitHash}.0`; } const argv = yargs(hideBin(process.argv)) - .option('pkg-version', { + .option('suffix', { type: 'string', - description: 'Set the package version', + description: 'Set the package version suffix', }) .parse(); -const newVersion = argv['pkg-version'] ?? getBaseVersion(); -if (argv['pkg-version']) { - console.log(`Using provided package version (--pkg-version): ${newVersion}`); -} else { - console.log( - `Using base version with dev suffix and commit hash: ${newVersion}`, - ); -} - +const baseVersion = getBaseVersion(); +const suffix = argv['suffix'] ?? getDefaultSuffix(); +const newVersion = `${baseVersion}${suffix.length ? '-' : ''}${suffix}`; console.log(`Setting package version to: ${newVersion}`); const packageJsonPath = path.join(packageDir, 'package.json');