-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathrelease-snapshot.js
More file actions
78 lines (66 loc) · 2.75 KB
/
Copy pathrelease-snapshot.js
File metadata and controls
78 lines (66 loc) · 2.75 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* This script creates a snapshot release by performing the following steps:
* 1. Ensures the script is running from the project root directory.
* 2. Defines a function to execute shell commands and log their output.
* 3. Defines a function to update the version in a given package.json file.
* - If the current version is already a snapshot, it increments the snapshot number.
* - If the current version is not a snapshot, it increments the patch version and sets the snapshot number to 0.
* 4. Retrieves the current commit short SHA.
* 5. Bumps the version in the specified package.json files.
* 6. Runs a series of commands to version, build, and publish the packages as a snapshot release.
*
* @file /Users/ahmadawais/Documents/Sandbox/baseai/.github/scripts/create-snapshot.js
* @requires child_process
* @requires path
* @requires fs
*/
const {execSync} = require('child_process');
const path = require('path');
const fs = require('fs');
// Ensure we're in the project root
process.chdir(path.resolve(__dirname, '../..'));
// Function to execute commands and log output
function run(command) {
console.log(`Running: ${command}`);
try {
execSync(command, {stdio: 'inherit'});
} catch (error) {
console.error(`Error executing command: ${command}`);
console.error(error);
process.exit(1);
}
}
// Function to update version in package.json
function bumpVersion(packagePath) {
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
const currentVersion = pkg.version;
let [major, minor, patch, snapshot] = currentVersion
.split(/[-.]/)
.map(v => (isNaN(parseInt(v)) ? v : parseInt(v)));
if (snapshot === 'snapshot') {
// If already a snapshot, increment the snapshot number
snapshot = parseInt(pkg.version.split('-snapshot.')[1]) + 1;
} else {
// If not a snapshot, increment patch and set snapshot to 0
patch += 1;
snapshot = 0;
}
pkg.version = `${major}.${minor}.${patch}-snapshot.${snapshot}`;
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2));
console.log(`Updated ${packagePath} to version ${pkg.version}`);
}
// Get the current commit short SHA
const SHORT_SHA = execSync('git rev-parse --short HEAD').toString().trim();
console.log('Creating snapshot release...');
// Bump versions
bumpVersion('./packages/baseai/package.json');
bumpVersion('./packages/core/package.json');
// Version and tag the snapshot release
run(`pnpm changeset version --snapshot ${SHORT_SHA}`);
// Build and publish the snapshot release
run('pnpm build:pkgs');
run('pnpm changeset publish --no-git-tag --tag snapshot');
// Reset Git changes
console.log('Git commit and push changes...');
run('git add . && git commit -m "📦 NEW: snapshot release" && git push');
console.log('All changes have been reset. Snapshot release process complete!');