Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"release": "node scripts/release.js",
"release:dev": "npm install && npm run build && node scripts/release.js"
"release:dev": "npm install && npm run build && node scripts/release.js",
"set-version": "node scripts/set-version.js",
"version": "node scripts/set-version.js && git add workspace-server/package.json workspace-server/src/index.ts"
},
"dependencies": {
"@google-apps/chat": "^0.21.0",
Expand Down
3 changes: 2 additions & 1 deletion scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ const main = async () => {
}
});

const version = process.env.GITHUB_REF_NAME || '0.0.1';
const packageJson = require('../package.json');
const version = process.env.GITHUB_REF_NAME || packageJson.version;

// Generate the gemini-extension.json file
const geminiExtensionJson = {
Expand Down
74 changes: 74 additions & 0 deletions scripts/set-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

const fs = require('node:fs');
const path = require('node:path');

const rootDir = path.join(__dirname, '..');
const packageJsonPath = path.join(rootDir, 'package.json');
const workspaceServerPackageJsonPath = path.join(rootDir, 'workspace-server', 'package.json');
const workspaceServerIndexPath = path.join(rootDir, 'workspace-server', 'src', 'index.ts');

const updateJsonFile = (filePath, version) => {
try {
const content = JSON.parse(fs.readFileSync(filePath, 'utf8'));
content.version = version;
fs.writeFileSync(filePath, JSON.stringify(content, null, 2) + '\n');
console.log(`Updated ${path.relative(rootDir, filePath)} to version ${version}`);
} catch (error) {
console.error(`Failed to update JSON file at ${path.relative(rootDir, filePath)}:`, error);
process.exit(1);
}
};

const updateTsFile = (filePath, version) => {
try {
const content = fs.readFileSync(filePath, 'utf8');
// Regex to find version: "x.y.z" and replace it
// Matches version: "..." or version: '...'
const regex = /(version:\s*["'])[^"']*(["'])/;

if (regex.test(content)) {
const newContent = content.replace(regex, `$1${version}$2`);
if (content !== newContent) {
fs.writeFileSync(filePath, newContent);
console.log(`Updated ${path.relative(rootDir, filePath)} to version ${version}`);
} else {
console.log(`Version in ${path.relative(rootDir, filePath)} is already ${version}`);
}
} else {
console.error(`Could not find version string in ${path.relative(rootDir, filePath)}`);
process.exit(1);
}
} catch (error) {
console.error(`Failed to update TS file at ${path.relative(rootDir, filePath)}:`, error);
process.exit(1);
}
};

const main = () => {
let version = process.argv[2];

if (version) {
// If version is provided as arg, update root package.json first
updateJsonFile(packageJsonPath, version);
} else {
// Otherwise read from root package.json
const packageJson = require(packageJsonPath);
version = packageJson.version;
console.log(`Using version from package.json: ${version}`);
}

if (!version) {
console.error('No version specified and no version found in package.json');
process.exit(1);
}

updateJsonFile(workspaceServerPackageJsonPath, version);
updateTsFile(workspaceServerIndexPath, version);
};

main();