-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathpublish-versions.js
More file actions
executable file
Β·219 lines (182 loc) Β· 7.29 KB
/
publish-versions.js
File metadata and controls
executable file
Β·219 lines (182 loc) Β· 7.29 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const question = (query) => new Promise((resolve) => rl.question(query, resolve));
async function main() {
console.log('π Version Packages Publishing Tool\n');
// Check for uncommitted changes
try {
execSync('git diff --quiet && git diff --cached --quiet');
} catch (error) {
console.error('β You have uncommitted changes. Please commit or stash them first.');
process.exit(1);
}
// Get all version directories
const versionsDir = path.join(__dirname, '..', 'versions');
const versionDirs = fs.readdirSync(versionsDir)
.filter(dir => /^\d+$/.test(dir))
.sort((a, b) => parseInt(b) - parseInt(a)); // Sort descending
// Also check for full package
const fullPackagePath = path.join(__dirname, '..', 'full', 'package.json');
const hasFullPackage = fs.existsSync(fullPackagePath);
console.log('π¦ Available packages:');
versionDirs.forEach(v => console.log(` - PostgreSQL ${v} (versions/${v})`));
if (hasFullPackage) {
console.log(` - Full package (./full) - PostgreSQL 17`);
}
console.log();
// Ask which versions to publish
const publishAll = await question('Publish all packages? (y/N): ');
let selectedVersions = [];
let includeFullPackage = false;
if (publishAll.toLowerCase() === 'y') {
selectedVersions = versionDirs;
includeFullPackage = hasFullPackage;
} else {
// Let user select versions
for (const version of versionDirs) {
const publish = await question(`Publish PostgreSQL ${version}? (y/N): `);
if (publish.toLowerCase() === 'y') {
selectedVersions.push(version);
}
}
if (hasFullPackage) {
const publishFull = await question(`Publish full package (PostgreSQL 17)? (y/N): `);
includeFullPackage = publishFull.toLowerCase() === 'y';
}
}
if (selectedVersions.length === 0 && !includeFullPackage) {
console.log('\nβ No packages selected for publishing.');
rl.close();
return;
}
// Ask for version bump type
console.log('\nπ Version bump type:');
console.log(' 1. patch (0.0.x)');
console.log(' 2. minor (0.x.0)');
const bumpType = await question('Select bump type (1 or 2): ');
const bump = bumpType === '2' ? 'minor' : 'patch';
console.log(`\nπ Will publish:`);
selectedVersions.forEach(v => console.log(` - PostgreSQL ${v} (${bump} bump)`));
if (includeFullPackage) {
console.log(` - Full package (${bump} bump)`);
}
// Ask about building
const skipBuild = await question('\nSkip build step? (y/N): ');
const shouldBuild = skipBuild.toLowerCase() !== 'y';
if (!shouldBuild) {
console.log('β οΈ Build step will be skipped. Make sure packages are already built!');
}
const confirm = await question('\nProceed? (y/N): ');
if (confirm.toLowerCase() !== 'y') {
console.log('β Publishing cancelled.');
rl.close();
return;
}
console.log('\nπ¨ Starting publish process...\n');
// Process each selected version
for (const version of selectedVersions) {
console.log(`\nπ¦ Publishing PostgreSQL ${version}...`);
const versionPath = path.join(versionsDir, version);
try {
// Version bump
console.log(` π Bumping version (${bump})...`);
execSync(`pnpm version ${bump}`, { cwd: versionPath, stdio: 'inherit' });
// Commit
console.log(` πΎ Committing version bump...`);
execSync(`git add package.json`, { cwd: versionPath });
execSync(`git commit -m "release: bump libpg-query v${version} version"`, { stdio: 'inherit' });
// Build (if not skipped)
if (shouldBuild) {
console.log(` π¨ Building...`);
execSync('pnpm build', { cwd: versionPath, stdio: 'inherit' });
} else {
console.log(` βοΈ Skipping build step`);
}
// Test (always run)
console.log(` π§ͺ Running tests...`);
execSync('pnpm test', { cwd: versionPath, stdio: 'inherit' });
// Publish
console.log(` π€ Publishing to npm...`);
execSync('pnpm run publish:pkg', { cwd: versionPath, stdio: 'inherit' });
console.log(` β
PostgreSQL ${version} published successfully!`);
} catch (error) {
console.error(` β Failed to publish PostgreSQL ${version}:`, error.message);
const continuePublish = await question('Continue with other versions? (y/N): ');
if (continuePublish.toLowerCase() !== 'y') {
rl.close();
process.exit(1);
}
}
}
// Process full package if selected
if (includeFullPackage) {
console.log(`\nπ¦ Publishing full package...`);
const fullPath = path.join(__dirname, '..', 'full');
try {
// Version bump
console.log(` π Bumping version (${bump})...`);
execSync(`pnpm version ${bump}`, { cwd: fullPath, stdio: 'inherit' });
// Commit
console.log(` πΎ Committing version bump...`);
execSync(`git add package.json`, { cwd: fullPath });
execSync(`git commit -m "release: bump @libpg-query/parser version"`, { stdio: 'inherit' });
// Build (if not skipped)
if (shouldBuild) {
console.log(` π¨ Building...`);
execSync('pnpm build', { cwd: fullPath, stdio: 'inherit' });
} else {
console.log(` βοΈ Skipping build step`);
}
// Test (always run)
console.log(` π§ͺ Running tests...`);
execSync('pnpm test', { cwd: fullPath, stdio: 'inherit' });
// Publish with pg17 tag
console.log(` π€ Publishing to npm with pg17 tag...`);
// use npm so staged changes are OK
execSync('npm publish --tag pg17', { cwd: fullPath, stdio: 'inherit' });
console.log(` β
Full package published successfully with pg17 tag!`);
} catch (error) {
console.error(` β Failed to publish full package:`, error.message);
}
}
// Ask about promoting to latest
if (selectedVersions.includes('17') || includeFullPackage) {
console.log('\nπ·οΈ Tag Management');
if (selectedVersions.includes('17')) {
const promoteVersions = await question('Promote libpg-query@pg17 to latest? (y/N): ');
if (promoteVersions.toLowerCase() === 'y') {
try {
execSync('npm dist-tag add libpg-query@pg17 latest', { stdio: 'inherit' });
console.log('β
libpg-query@pg17 promoted to latest');
} catch (error) {
console.error('β Failed to promote tag:', error.message);
}
}
}
if (includeFullPackage) {
const promoteFullPackage = await question('Promote @libpg-query/parser@pg17 to latest? (y/N): ');
if (promoteFullPackage.toLowerCase() === 'y') {
try {
execSync('npm dist-tag add @libpg-query/parser@pg17 latest', { stdio: 'inherit' });
console.log('β
@libpg-query/parser@pg17 promoted to latest');
} catch (error) {
console.error('β Failed to promote tag:', error.message);
}
}
}
}
console.log('\n⨠Publishing complete!');
rl.close();
}
main().catch(error => {
console.error('β Error:', error);
rl.close();
process.exit(1);
});