fix: create-release-script

This commit is contained in:
Andrei O 2022-03-27 15:54:00 +03:00
parent 6e4567d2cf
commit bb966b603c
No known key found for this signature in database
GPG Key ID: B961E5B68389457E
2 changed files with 22 additions and 16 deletions

View File

@ -6,8 +6,8 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"release": "yarn config set version-tag-prefix brave-detection-blocker@v && yarn config set version-git-message 'brave-detection-blocker@v%s' && yarn version --patch && yarn postversion", "release": "yarn config set version-tag-prefix brave-detection-blocker@v && yarn config set version-git-message 'brave-detection-blocker@v%s' && yarn version --patch && yarn postversion",
"postversion": "git push && git push --tags", "postversion": "git push",
"pub": "yarn release && node ./scripts/create-release.js" "pub": "node ./scripts/create-release.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -1,6 +1,7 @@
const archiver = require('archiver'); const archiver = require('archiver');
const fs = require('fs'); const fs = require('fs');
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const path = require('path');
async function ghRelease(changes) { async function ghRelease(changes) {
const package = JSON.parse(fs.readFileSync('package.json')); const package = JSON.parse(fs.readFileSync('package.json'));
@ -20,31 +21,36 @@ async function ghRelease(changes) {
filePipes.forEach((file) => { filePipes.forEach((file) => {
arch = arch.file(file, { name: file }); arch = arch.file(file, { name: file });
}); });
arch.on('error', (err) => reject(err)).pipe(stream); arch.on('error', (err) => reject(err)).pipe(outputZip);
stream.on('close', () => resolve()); outputZip.on('close', () => resolve());
arch.finalize(); arch.finalize();
}); });
const changeLogPath = `releases/${package.version}-changeLog.md`; const changeLogPath = `releases/${package.version}.changelog.md`;
fs.writeFileSync( fs.writeFileSync(
changeLogPath, changeLogPath,
`# ${package.version} \n\n `# ${package.version} \n
${changes.reduce((acc, change) => { ${changes.reduce((acc, change) => {
return acc + `- ${change}\n`; return acc + `- ${change}\n`;
}, '')}`, }, '')}`,
); );
console.log(
await new Promise((resolve) => { await new Promise((resolve) => {
const p = spawn('gh', ['release', `create v${package.version} '${outputPath}' -F ${changeLogPath}`]); const p = spawn('gh', ['release', 'create', `v${package.version}`, `./${outputPath}`, '-F', `./${changeLogPath}`], {
shell: true,
});
// const p = spawn('pwd');
let result = ''; let result = '';
p.stdout.on('data', (data) => (result += data.toString())); p.stdout.on('data', (data) => (result += data.toString()));
p.stderr.on('data', (data) => (result += data.toString())); p.stderr.on('data', (data) => (result += data.toString()));
p.on('close', () => { p.on('close', () => {
resolve(result); resolve(result);
}); });
}); }),
);
} }
(async () => { (async () => {
@ -53,6 +59,6 @@ async function ghRelease(changes) {
return; return;
} }
const changes = process.argv[2].split(','); const changes = process.argv[2].split(',');
// ghRelease(changes) await ghRelease(changes);
console.log('Release created', changes); console.log('Release created', changes);
})(); })();