Skip to content

Commit

Permalink
fix: update PR message with publish command (#467)
Browse files Browse the repository at this point in the history
* fix: update PR message with publish command

* fix: update test snapshot
  • Loading branch information
Eunjae Lee authored Nov 30, 2019
1 parent f079ba5 commit 18cc7e4
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 9 deletions.
13 changes: 13 additions & 0 deletions packages/shipjs-lib/src/lib/config/__tests__/defaultConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
mergeStrategy: defaultMergeStrategy,
shouldRelease,
} = defaultConfig;
const publishCommandInStr = 'npm publish --tag latest';

describe('defaultConfig', () => {
it('should export an object', () => {
Expand Down Expand Up @@ -57,6 +58,7 @@ describe('defaultConfig', () => {
mergeStrategy,
currentVersion,
nextVersion,
publishCommandInStr,
});
expect(message).toMatchInlineSnapshot(`
"## Release Summary
Expand All @@ -68,6 +70,11 @@ describe('defaultConfig', () => {
> Fore more information, please refer to the mergeStrategy section of the [guide](https://github.com/algolia/shipjs/blob/master/GUIDE.md#mergestrategy).
> ![Squash and merge](https://raw.githubusercontent.com/algolia/shipjs/v0.5.2/assets/squash-and-merge.png)
---
This is going to be published by the following command:
\`\`\`
npm publish --tag latest
\`\`\`
---
_This pull request is automatically generated by [Ship.js](https://github.com/algolia/shipjs)_"
`);
Expand All @@ -93,6 +100,7 @@ describe('defaultConfig', () => {
mergeStrategy,
currentVersion,
nextVersion,
publishCommandInStr,
});
expect(message).toMatchInlineSnapshot(`
"## Release Summary
Expand All @@ -103,6 +111,11 @@ describe('defaultConfig', () => {
> Fore more information, please refer to the mergeStrategy section of the [guide](https://github.com/algolia/shipjs/blob/master/GUIDE.md#mergestrategy).
> ![Merge pull request](https://raw.githubusercontent.com/algolia/shipjs/v0.5.2/assets/merge-pull-request.png)
---
This is going to be published by the following command:
\`\`\`
npm publish --tag latest
\`\`\`
---
_This pull request is automatically generated by [Ship.js](https://github.com/algolia/shipjs)_"
`);
Expand Down
6 changes: 6 additions & 0 deletions packages/shipjs-lib/src/lib/config/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
currentVersion,
nextVersion,
releaseType,
publishCommandInStr,
}) => {
const pullRequestTitle = formatPullRequestTitle({
version: nextVersion,
Expand All @@ -56,6 +57,11 @@ export default {
]),
'',
'---',
'This is going to be published by the following command:',
'```',
publishCommandInStr,
'```',
'---',
'_This pull request is automatically generated by [Ship.js](https://github.com/algolia/shipjs)_',
];
return lines.join('\n');
Expand Down
12 changes: 12 additions & 0 deletions packages/shipjs/src/helper/getPublishCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default function getPublishCommand({
isYarn,
publishCommand,
tag,
dir,
}) {
const defaultCommand = isYarn
? `yarn publish --no-git-tag-version --non-interactive --tag ${tag}`
: `npm publish --tag ${tag}`;

return publishCommand({ isYarn, tag, defaultCommand, dir });
}
1 change: 1 addition & 0 deletions packages/shipjs/src/helper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { default as getChangelog } from './getChangelog';
export { default as extractSpecificChangelog } from './extractSpecificChangelog';
export { default as gitPush } from './gitPush';
export { default as runPrettier } from './runPrettier';
export { default as getPublishCommand } from './getPublishCommand';
47 changes: 44 additions & 3 deletions packages/shipjs/src/step/prepare/createPullRequest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { hasRemoteBranch, getRepoInfo } from 'shipjs-lib';
import {
expandPackageList,
hasRemoteBranch,
getRepoInfo,
getReleaseTag,
} from 'shipjs-lib';
import open from 'open';
import Octokit from '@octokit/rest';
import runStep from '../runStep';
import { getDestinationBranchName } from '../../helper';
import { print, run, exitProcess } from '../../util';
import { getDestinationBranchName, getPublishCommand } from '../../helper';
import { print, run, exitProcess, detectYarn } from '../../util';
import { warning } from '../../color';

export default async ({
Expand All @@ -22,8 +27,10 @@ export default async ({
mergeStrategy,
formatPullRequestTitle,
formatPullRequestMessage,
publishCommand,
pullRequestReviewer,
remote,
monorepo,
} = config;
const destinationBranch = getDestinationBranchName({
baseBranch,
Expand All @@ -48,6 +55,13 @@ export default async ({
exitProcess(0);
}
const { url: repoURL, owner, name: repo } = getRepoInfo(remote, dir);
const publishCommandInStr = getPublishCommandInStr({
isYarn: detectYarn(dir),
tag: getReleaseTag(nextVersion),
monorepo,
publishCommand,
dir,
});
const title = formatPullRequestTitle({ version: nextVersion, releaseType });
const message = formatPullRequestMessage({
formatPullRequestTitle,
Expand All @@ -59,6 +73,7 @@ export default async ({
currentVersion,
nextVersion,
releaseType,
publishCommandInStr,
});
run({ command: `git remote prune ${remote}`, dir, dryRun });

Expand Down Expand Up @@ -101,3 +116,29 @@ export default async ({

return { pullRequestUrl: url };
});

function getPublishCommandInStr({
isYarn,
tag,
monorepo,
publishCommand,
dir,
}) {
if (monorepo) {
const { packagesToPublish } = monorepo;
const packageList = expandPackageList(packagesToPublish, dir);
return packageList
.map(
packageDir =>
`- ${packageDir} -> ${getPublishCommand({
isYarn,
publishCommand,
tag,
dir: packageDir,
})}`
)
.join('\n');
} else {
return getPublishCommand({ isYarn, publishCommand, tag, dir });
}
}
5 changes: 5 additions & 0 deletions packages/shipjs/src/step/release/__tests__/runPublish.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { expandPackageList } from 'shipjs-lib';
import { run, print } from '../../../util';
import runPublish from '../runPublish';
import { mockPrint } from '../../../../tests/util';
jest.unmock('../../../helper');
// if `unmock` causes any trouble in the future,
// we might try this: https://github.com/facebook/jest/issues/2649#issuecomment-360467278
// `runPublish` depends on `getPublishCommand` from `helper`
// and we need it unmocked to successfully run the following tests.

describe('runPublish', () => {
it('works with yarn', () => {
Expand Down
11 changes: 5 additions & 6 deletions packages/shipjs/src/step/release/runPublish.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import { expandPackageList } from 'shipjs-lib';
import runStep from '../runStep';
import { run, print } from '../../util';
import { getPublishCommand } from '../../helper';
import { info } from '../../color';

export default ({ isYarn, config, releaseTag: tag, dir, dryRun }) =>
runStep({ title: 'Publishing.' }, () => {
const { publishCommand, monorepo } = config;
const defaultCommand = isYarn
? `yarn publish --no-git-tag-version --non-interactive --tag ${tag}`
: `npm publish --tag ${tag}`;

if (monorepo) {
const { packagesToPublish } = monorepo;
const packageList = expandPackageList(packagesToPublish, dir);
packageList.forEach(packageDir => {
const command = publishCommand({
const command = getPublishCommand({
isYarn,
publishCommand,
tag,
defaultCommand,
dir: packageDir,
});
print(`Running the following at ${info(packageDir)}`);
run({ command, dir: packageDir, dryRun });
});
} else {
const command = publishCommand({ isYarn, tag, defaultCommand, dir });
const command = getPublishCommand({ isYarn, publishCommand, tag, dir });
run({ command, dir, dryRun });
}
});

0 comments on commit 18cc7e4

Please sign in to comment.