-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: return stdout when command success * feat: create github release * fix: change title * feat: extract changelog from existing one * fix: avoid linux style path separator * fix: restore printCommand * fix: do not generate chanelog if there no CHANGELOG found * fix: treat version as release title * fix: dependency * fix: create release even if not using changelog * fix: update usage of `run` function * chore: remove blank lines
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 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
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,49 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import tempWrite from 'temp-write'; | ||
|
||
import runStep from '../runStep'; | ||
|
||
function getChangelog(version, rootDir) { | ||
const changelogMatcher = new RegExp( | ||
`#+?[\\s\\[]*?(${version})(.|\n)+?(?=#+?[\\s\\[]*?\\d\\.\\d|$)` | ||
); | ||
const changelogPath = path.resolve(rootDir, 'CHANGELOG.md'); | ||
try { | ||
const changelogFile = fs.readFileSync(changelogPath, 'utf-8').toString(); | ||
const changelogMatch = changelogFile.match(changelogMatcher); | ||
if (changelogMatch !== null) { | ||
// because first line of a log file must be title of the release | ||
return `${version}\n\n${changelogMatch[0]}`; | ||
} | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return null; | ||
} | ||
throw err; | ||
} | ||
return null; | ||
} | ||
|
||
export default ({ version, config, dir, dryRun }) => | ||
runStep({ title: 'Creating a release on GitHub repository' }, ({ run }) => { | ||
const { getTagName } = config; | ||
const tagName = getTagName({ version }); | ||
|
||
// extract matching changelog | ||
const changelog = config.updateChangelog | ||
? getChangelog(version, dir) | ||
: null; | ||
const exportedPath = tempWrite.sync(changelog || tagName); | ||
|
||
// create GitHub release | ||
const releaseCommand = [ | ||
'hub', | ||
'release', | ||
'create', | ||
`-F ${exportedPath}`, | ||
tagName, | ||
].join(' '); | ||
|
||
run({ command: releaseCommand, dir, dryRun }); | ||
}); |