Skip to content

Commit

Permalink
feat: create GitHub releases (#311)
Browse files Browse the repository at this point in the history
* 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
uetchy authored and Eunjae Lee committed Oct 13, 2019
1 parent fb25a7e commit f1e4e77
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/shipjs/src/flow/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import runPublish from '../step/release/runPublish';
import runAfterPublish from '../step/release/runAfterPublish';
import createGitTag from '../step/release/createGitTag';
import gitPush from '../step/release/gitPush';
import createGitHubRelease from '../step/release/createGitHubRelease';
import notifyReleaseSuccess from '../step/release/notifyReleaseSuccess';
import finished from '../step/finished';

Expand Down Expand Up @@ -49,6 +50,7 @@ async function release({ help = false, dir = '.', dryRun = false }) {
await runAfterPublish({ config, dir, dryRun });
const { tagName } = createGitTag({ version, config, dir, dryRun });
gitPush({ tagName, config, dir, dryRun });
createGitHubRelease({ version, config, dir, dryRun });
await notifyReleaseSuccess({
config,
appName,
Expand Down
49 changes: 49 additions & 0 deletions packages/shipjs/src/step/release/createGitHubRelease.js
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 });
});

0 comments on commit f1e4e77

Please sign in to comment.