Skip to content

Commit 09eb039

Browse files
committed
chore: release 0.0.1
1 parent ccdab34 commit 09eb039

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scripts/release.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ async function main(): Promise<void> {
3838
await Promise.all(manifests.packageJson.map(file => updatePackageJson(file, version)));
3939
await Promise.all(manifests.cargoToml.map(file => updateCargoToml(file, version)));
4040

41+
await createAndPushCommit(version);
42+
4143
await runCommand('pnpm', ['publish'], path.join(repoRoot, 'typescript'));
4244
await runCommand('cargo', ['publish'], path.join(repoRoot, 'rust'));
4345
}
@@ -175,6 +177,47 @@ async function runCommand(command: string, args: string[], cwd: string): Promise
175177
});
176178
}
177179

180+
async function createAndPushCommit(version: string): Promise<void> {
181+
if (!(await hasPendingChanges())) {
182+
console.warn('No changes detected, skipping commit and push');
183+
return;
184+
}
185+
186+
await runCommand('git', ['add', '--all'], repoRoot);
187+
await runCommand('git', ['commit', '-m', `chore: release ${version}`], repoRoot);
188+
await runCommand('git', ['push'], repoRoot);
189+
}
190+
191+
async function hasPendingChanges(): Promise<boolean> {
192+
const output = await captureCommand('git', ['status', '--porcelain'], repoRoot);
193+
return output.trim().length > 0;
194+
}
195+
196+
async function captureCommand(command: string, args: string[], cwd: string): Promise<string> {
197+
return new Promise<string>((resolve, reject) => {
198+
const child = spawn(command, args, {
199+
cwd,
200+
stdio: ['ignore', 'pipe', 'inherit'],
201+
env: process.env
202+
});
203+
204+
let output = '';
205+
206+
child.stdout?.on('data', chunk => {
207+
output += chunk.toString();
208+
});
209+
210+
child.on('error', reject);
211+
child.on('close', code => {
212+
if (code === 0) {
213+
resolve(output);
214+
} else {
215+
reject(new Error(`${command} ${args.join(' ')} exited with code ${code}`));
216+
}
217+
});
218+
});
219+
}
220+
178221
function relative(filePath: string): string {
179222
return path.relative(repoRoot, filePath) || '.';
180223
}

0 commit comments

Comments
 (0)