Created
April 15, 2020 12:53
-
-
Save thomasmichaelwallace/1f40cbf6f686c67b34eafa052a69d17f to your computer and use it in GitHub Desktop.
Use lerna to backfill GitHub release notes from a change log.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-console */ | |
const createRelease = require('@lerna/version/lib/create-release.js'); // eslint-disable-line import/no-extraneous-dependencies | |
const fs = require('fs'); | |
function parseEntry(entry) { | |
const lines = entry.split('\n'); | |
const header = lines.shift(); | |
const [version] = header.split(']'); | |
const tag = `v${version}`; | |
const title = `# [${header}`; | |
lines.unshift(title); | |
const body = lines.join('\n').trim(); | |
return { tag, body }; | |
} | |
function getReleases() { | |
const log = fs.readFileSync('./CHANGELOG.md').toString(); | |
const entries = log.split(/#+ \[/); | |
entries.shift(); // dump header | |
entries.shift(); // dump already released version | |
const releases = entries.map((e) => parseEntry(e)); | |
return releases; | |
} | |
async function push(release) { | |
const { tag, body } = release; | |
const type = 'github'; | |
const git = { | |
gitRemote: 'origin', | |
// execOpts: ?, | |
}; | |
const details = { | |
tags: [tag], | |
releaseNotes: [{ name: 'fixed', notes: body }], | |
}; | |
try { | |
// console.log(body); | |
await createRelease(type, details, git); | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
async function pushAll(releases, offset = 0) { | |
const release = releases[offset]; | |
if (!release) { | |
console.log('complete'); | |
return releases.length; | |
} | |
console.log(`[${offset + 1}/${releases.length}] releasing ${release.tag}...`); | |
await push(release); | |
return pushAll(releases, offset + 1); | |
} | |
console.log('backfilling release notes'); | |
const releases = getReleases(); | |
pushAll(releases, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment