summaryrefslogtreecommitdiff
path: root/scripts/tag-release.js
diff options
context:
space:
mode:
authormatt korwel <[email protected]>2025-07-04 17:04:05 -0500
committerGitHub <[email protected]>2025-07-04 22:04:05 +0000
commite90e0015eacda0cf8315e30b72305e026f3768b3 (patch)
treecee3dd7cb2ff289223c36e9d8dce06b35694f576 /scripts/tag-release.js
parent9ff3592e01b8f7cd2c30d35b65ee132c37631bc6 (diff)
Signing tags (#3254)
Diffstat (limited to 'scripts/tag-release.js')
-rw-r--r--scripts/tag-release.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/tag-release.js b/scripts/tag-release.js
new file mode 100644
index 00000000..40385264
--- /dev/null
+++ b/scripts/tag-release.js
@@ -0,0 +1,58 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { execSync } from 'child_process';
+import { readFileSync } from 'fs';
+import path from 'path';
+
+function getVersion() {
+ const packageJsonPath = path.resolve(process.cwd(), 'package.json');
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
+ return packageJson.version;
+}
+
+function getShortSha() {
+ return execSync('git rev-parse --short HEAD').toString().trim();
+}
+
+function getNightlyTagName() {
+ const version = getVersion();
+ const now = new Date();
+ const year = now.getUTCFullYear().toString().slice(-2);
+ const month = (now.getUTCMonth() + 1).toString().padStart(2, '0');
+ const day = now.getUTCDate().toString().padStart(2, '0');
+ const date = `${year}${month}${day}`;
+
+ const sha = getShortSha();
+ return `v${version}-nightly.${date}.${sha}`;
+}
+
+function createAndPushTag(tagName, isSigned) {
+ const command = isSigned
+ ? `git tag -s -a ${tagName} -m ''`
+ : `git tag ${tagName}`;
+
+ try {
+ console.log(`Executing: ${command}`);
+ execSync(command, { stdio: 'inherit' });
+ console.log(`Successfully created tag: ${tagName}`);
+
+ console.log(`Pushing tag to origin...`);
+ execSync(`git push origin ${tagName}`, { stdio: 'inherit' });
+ console.log(`Successfully pushed tag: ${tagName}`);
+ } catch (error) {
+ console.error(`Failed to create or push tag: ${tagName}`);
+ console.error(error);
+ process.exit(1);
+ }
+}
+
+const tagName = getNightlyTagName();
+// In GitHub Actions, the CI variable is set to true.
+// We will create a signed commit if not in a CI environment.
+const shouldSign = !process.env.CI;
+
+createAndPushTag(tagName, shouldSign);