-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
656 additions
and
656 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Prepare PR | ||
description: Prepare Pull Request for the current change | ||
outputs: | ||
release: | ||
description: Does this patch contains a release | ||
version: | ||
description: The new version | ||
runs: | ||
using: 'node12' | ||
main: index.js | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
const fs = require('fs'); | ||
const core = require('@actions/core'); | ||
const convBump = require('conventional-recommended-bump'); | ||
const semver = require('semver'); | ||
const conventionalChangelog = require('conventional-changelog') | ||
|
||
const DRY = !process.env.CI; | ||
|
||
/** | ||
* @returns {Promise<import('conventional-recommended-bump').Callback.Recommendation>} | ||
*/ | ||
async function getBumpSuggestion() { | ||
const result = await new Promise((resolve, reject) => { | ||
convBump({ | ||
whatBump(comments) { | ||
const reasons = comments.filter(c => c.type === 'feat' || c.type === 'fix' || c.type === 'refactor' || c.header.startsWith('BREAKING CHANGE:')); | ||
const feats = comments.filter(c => c.type === 'feat'); | ||
const fixes = comments.filter(c => c.type === 'fix' || c.type === 'refactor'); | ||
const breakings = comments.filter(c => c.header.startsWith('BREAKING CHANGE:')); | ||
if (comments.some(c => c.header.startsWith('BREAKING CHANGE:'))) { | ||
return { level: 0, reasons, feats, fixes, breakings }; // major | ||
} else if (comments.some(c => c.type === 'feat')) { | ||
return { level: 1, reasons, feats, fixes, breakings }; // minor | ||
} else if (comments.some(c => c.type === 'fix' || c.type === 'refactor')) { | ||
return { level: 2, reasons, feats, fixes, breakings }; // patch | ||
} | ||
} | ||
}, function (err, result) { | ||
if (err) reject(err); | ||
else resolve(result); | ||
}); | ||
}); | ||
return result; | ||
} | ||
|
||
/** | ||
* @param {string} newVersion | ||
* @returns {Promise<string>} | ||
*/ | ||
function generateChangelog(newVersion, oldVersion) { | ||
return new Promise((resolve, reject) => { | ||
let content = '' | ||
const context = { version: newVersion } | ||
const changelogStream = conventionalChangelog({ | ||
// tagPrefix: args.tagPrefix | ||
preset: 'conventional-changelog-config-spec', | ||
}, context, { merges: null }) | ||
.on('error', function (err) { | ||
return reject(err) | ||
}) | ||
|
||
changelogStream.on('data', function (buffer) { | ||
content += buffer.toString() | ||
}) | ||
|
||
changelogStream.on('end', function () { | ||
content = content.replace(/## .+/, `## [${newVersion}](https://github.com/voxelum/voxelauncher/compare/v${oldVersion}...v${newVersion})`) | ||
content = `\n${content.trim()}\n`; | ||
return resolve(content) | ||
}) | ||
}) | ||
} | ||
|
||
function writeFile(name, content) { | ||
if (!DRY) { | ||
fs.writeFileSync(name, content); | ||
} else { | ||
console.log(`Write file ${name}`); | ||
} | ||
} | ||
|
||
async function main(output) { | ||
const suggesstion = await getBumpSuggestion(); | ||
const package = JSON.parse(fs.readFileSync(`package.json`).toString()); | ||
const packageLock = JSON.parse(fs.readFileSync(`package-lock.json`).toString()); | ||
|
||
if (suggesstion.releaseType) { | ||
const newVersion = semver.inc(package.version, suggesstion.releaseType); | ||
writeFile('pacakge.json', JSON.stringify(Object.assign(package, { version: newVersion }), null, 4)); | ||
writeFile('pacakge-lock.json', JSON.stringify(Object.assign(packageLock, { version: newVersion }), null, 4)); | ||
const newChangelog = await generateChangelog(newVersion, package.version); | ||
console.log(newChangelog); | ||
|
||
const changelog = fs.readFileSync('CHANGELOG.md').toString(); | ||
const changelogLines = changelog.split('\n') | ||
|
||
const start = changelogLines.findIndex(l => l.startsWith('## ')) - 1; | ||
|
||
console.log(start); | ||
|
||
const result = [...changelogLines.slice(0, start), '', '', ...newChangelog.split('\n'), ...changelogLines.slice(start)].join('\n'); | ||
|
||
writeFile('CHANGELOG.md', result); | ||
|
||
output('release', true); | ||
output('version', newVersion); | ||
} else { | ||
output('release', false); | ||
} | ||
// const changelog = await generateChangelog('0.1'); | ||
// console.log(changelog); | ||
} | ||
|
||
main(core ? core.setOutput : (k, v) => { | ||
console.log(k) | ||
console.log(v) | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"@actions/core": "1.2.4" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Prepare PR | ||
description: Prepare Pull Request for the current change | ||
outputs: | ||
body: | ||
description: The pull request body | ||
title: | ||
description: The pull request title | ||
message: | ||
description: The pull request message | ||
runs: | ||
using: 'node12' | ||
main: index.js | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fs = require('fs'); | ||
const core = require('@actions/core'); | ||
|
||
function prTitle(version) { | ||
return `Prepare Release ${version}` | ||
} | ||
function prBody(b) { | ||
let body = `This PR is auto-generated by | ||
[create-pull-request](https://github.com/peter-evans/create-pull-request) | ||
to prepare new releases for changed packages.\n\n`; | ||
body += b; | ||
return body; | ||
} | ||
function commitMessage(version) { | ||
return `chore(release): version ${version}` | ||
} | ||
|
||
async function main(output) { | ||
const { version } = JSON.parse(fs.readFileSync(`package.json`).toString()); | ||
const changelog = fs.readFileSync('CHANGELOG.md').toString(); | ||
const changelogLines = changelog.split('\n') | ||
|
||
const start = changelogLines.findIndex(l => l.startsWith('## ')); | ||
const end = changelogLines.slice(start + 1).findIndex(l => l.startsWith('## ')) | ||
const body = changelogLines.slice(start, end).join('\n') + '\n'; | ||
|
||
console.log(body); | ||
|
||
output('title', prTitle(version)); | ||
output('body', prBody(body)); | ||
output('message', commitMessage(version)); | ||
output('release', true); | ||
} | ||
|
||
main(core ? core.setOutput : (k, v) => { | ||
console.log(k) | ||
console.log(v) | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"@actions/core": "1.2.4" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Prepare Release | ||
description: Prepare Release for the current change | ||
outputs: | ||
body: | ||
description: The release body | ||
draft: | ||
description: The release is draft | ||
prerelease: | ||
description: The release is prerelease | ||
tag: | ||
description: The release tag | ||
release: | ||
description: The release name | ||
runs: | ||
using: 'node12' | ||
main: index.js | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const fs = require('fs'); | ||
const core = require('@actions/core'); | ||
|
||
async function main(output) { | ||
const { version } = JSON.parse(fs.readFileSync(`package.json`).toString()); | ||
const changelog = fs.readFileSync('CHANGELOG.md').toString(); | ||
const changelogLines = changelog.split('\n') | ||
|
||
const start = changelogLines.findIndex(l => l.startsWith(`## [${version}]`)); | ||
|
||
let body = 'Manual Release'; | ||
if (start !== -1) { | ||
const end = changelogLines.slice(start + 1).findIndex(l => l.startsWith('## ')) | ||
body = changelogLines.slice(start, end).join('\n') + '\n'; | ||
} | ||
|
||
console.log(body); | ||
|
||
output('release', `v${version}`); | ||
output('body', body); | ||
output('tag', `v${version}`); | ||
output('prerelease', true); | ||
output('draft', false); | ||
} | ||
|
||
main(core ? core.setOutput : (k, v) => { | ||
console.log(k) | ||
console.log(v) | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"@actions/core": "1.2.4" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.