-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathupdate-manifest.js
More file actions
30 lines (25 loc) · 1 KB
/
update-manifest.js
File metadata and controls
30 lines (25 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const fs = require('fs');
const path = require('path');
// Get the tag from the environment variable GitHub Actions provides
const tag = process.env.GITHUB_REF_NAME;
if (!tag) {
console.error("Error: GITHUB_REF_NAME environment variable not set.");
process.exit(1);
}
const version = tag.startsWith('v') ? tag.substring(1) : tag;
if (!/^\d+\.\d+\.\d+(-[\w.-]+)?$/.test(version)) {
console.error(`Invalid version format: "${version}". Expected semver like v1.2.3 or v1.2.3-beta.1`);
process.exit(1);
}
// Path to the manifest file
const manifestPath = path.resolve(__dirname, '../../frontend/manifest.json');
// Read, update, and write the manifest file
try {
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
manifest.version = version;
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
console.log(`Successfully updated ${manifestPath} to version ${version}`);
} catch (error) {
console.error(`Error updating manifest file: ${error.message}`);
process.exit(1);
}