Skip to content

Commit ad160a5

Browse files
authored
--no-bump flag implementation (#376)
* --no-bump flag implementation * Change files
1 parent 00a0101 commit ad160a5

9 files changed

Lines changed: 94 additions & 4 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "minor",
3+
"comment": "--no-bump flag implementation",
4+
"packageName": "beachball",
5+
"email": "arabisho@microsoft.com",
6+
"dependentChangeType": "patch",
7+
"date": "2020-08-06T15:39:17.525Z"
8+
}

packages/beachball/src/__e2e__/publishE2E.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('publish command (e2e)', () => {
7575
disallowedChangeTypes: null,
7676
defaultNpmTag: 'latest',
7777
retries: 3,
78+
bump: true,
7879
});
7980

8081
const showResult = npm(['--registry', registry.getUrl(), 'show', 'foo', '--json']);
@@ -94,6 +95,68 @@ describe('publish command (e2e)', () => {
9495
expect(gitResults.stdout).toBe('foo_v1.1.0');
9596
});
9697

98+
it('can perform a successful npm publish without bump', async () => {
99+
repositoryFactory = new RepositoryFactory();
100+
await repositoryFactory.create();
101+
const repo = await repositoryFactory.cloneRepository();
102+
103+
writeChangeFiles(
104+
{
105+
foo: {
106+
type: 'minor',
107+
comment: 'test',
108+
date: new Date('2019-01-01'),
109+
email: 'test@test.com',
110+
packageName: 'foo',
111+
dependentChangeType: 'patch',
112+
},
113+
},
114+
repo.rootPath
115+
);
116+
117+
git(['push', 'origin', 'master'], { cwd: repo.rootPath });
118+
119+
await publish({
120+
branch: 'origin/master',
121+
command: 'publish',
122+
message: 'apply package updates',
123+
path: repo.rootPath,
124+
publish: true,
125+
bumpDeps: true,
126+
push: true,
127+
registry: registry.getUrl(),
128+
gitTags: true,
129+
tag: 'latest',
130+
token: '',
131+
yes: true,
132+
new: false,
133+
access: 'public',
134+
package: '',
135+
changehint: 'Run "beachball change" to create a change file',
136+
type: null,
137+
fetch: true,
138+
disallowedChangeTypes: null,
139+
defaultNpmTag: 'latest',
140+
retries: 3,
141+
bump: false,
142+
});
143+
144+
const showResult = npm(['--registry', registry.getUrl(), 'show', 'foo', '--json']);
145+
146+
expect(showResult.success).toBeTruthy();
147+
148+
const show = JSON.parse(showResult.stdout);
149+
expect(show.name).toEqual('foo');
150+
expect(show.versions.length).toEqual(1);
151+
expect(show['dist-tags'].latest).toEqual('1.0.0');
152+
153+
git(['checkout', 'master'], { cwd: repo.rootPath });
154+
git(['pull'], { cwd: repo.rootPath });
155+
156+
const gitResults = git(['describe', '--abbrev=0'], { cwd: repo.rootPath });
157+
expect(gitResults.success).toBeFalsy();
158+
});
159+
97160
it('should not perform npm publish on out-of-scope package', async () => {
98161
repositoryFactory = new MonoRepoFactory();
99162
await repositoryFactory.create();
@@ -152,6 +215,7 @@ describe('publish command (e2e)', () => {
152215
defaultNpmTag: 'latest',
153216
scope: ['!packages/foo'],
154217
retries: 3,
218+
bump: true,
155219
});
156220

157221
const fooNpmResult = npm(['--registry', registry.getUrl(), 'show', 'foo', '--json']);
@@ -220,6 +284,7 @@ describe('publish command (e2e)', () => {
220284
disallowedChangeTypes: null,
221285
defaultNpmTag: 'latest',
222286
retries: 3,
287+
bump: true,
223288
hooks: {
224289
prepublish: (packagePath: string) => {
225290
const packageJsonPath = path.join(packagePath, 'package.json');

packages/beachball/src/__e2e__/publishGit.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe('publish command (git)', () => {
6666
disallowedChangeTypes: null,
6767
defaultNpmTag: 'latest',
6868
retries: 3,
69+
bump: true,
6970
});
7071

7172
const newRepo = await repositoryFactory.cloneRepository();
@@ -123,6 +124,7 @@ describe('publish command (git)', () => {
123124
disallowedChangeTypes: null,
124125
defaultNpmTag: 'latest',
125126
retries: 3,
127+
bump: true,
126128
};
127129

128130
const bumpInfo = gatherBumpInfo(options);

packages/beachball/src/__e2e__/publishRegistry.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe('publish command (registry)', () => {
8282
defaultNpmTag: 'latest',
8383
retries: 3,
8484
timeout: 100,
85+
bump: true,
8586
});
8687

8788
await expect(publishPromise).rejects.toThrow();
@@ -135,6 +136,7 @@ describe('publish command (registry)', () => {
135136
disallowedChangeTypes: null,
136137
defaultNpmTag: 'latest',
137138
retries: 3,
139+
bump: true,
138140
});
139141

140142
const showResult = npm(['--registry', registry.getUrl(), 'show', 'foo', '--json']);
@@ -215,6 +217,7 @@ describe('publish command (registry)', () => {
215217
disallowedChangeTypes: null,
216218
defaultNpmTag: 'latest',
217219
retries: 3,
220+
bump: true,
218221
});
219222

220223
const showResult = npm(['--registry', registry.getUrl(), 'show', 'foopkg', '--json']);
@@ -292,6 +295,7 @@ describe('publish command (registry)', () => {
292295
disallowedChangeTypes: null,
293296
defaultNpmTag: 'latest',
294297
retries: 3,
298+
bump: true,
295299
});
296300

297301
const showResultFoo = npm(['--registry', registry.getUrl(), 'show', 'foopkg', '--json']);
@@ -373,6 +377,7 @@ describe('publish command (registry)', () => {
373377
disallowedChangeTypes: null,
374378
defaultNpmTag: 'latest',
375379
retries: 3,
380+
bump: true,
376381
});
377382

378383
const showResult = npm(['--registry', registry.getUrl(), 'show', 'badname', '--json']);

packages/beachball/src/commands/publish.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export async function publish(options: BeachballOptions) {
2727
target branch: ${branch}
2828
tag: ${tag}
2929
30+
bumps versions: ${options.bump ? 'yes' : 'no'}
3031
publishes to npm registry: ${options.publish ? 'yes' : 'no'}
31-
pushes to remote git repo: ${options.push && options.branch ? 'yes' : 'no'}
32+
pushes to remote git repo: ${options.bump && options.push && options.branch ? 'yes' : 'no'}
3233
3334
`);
3435
if (!options.yes) {
@@ -44,7 +45,11 @@ export async function publish(options: BeachballOptions) {
4445
// checkout publish branch
4546
const publishBranch = 'publish_' + String(new Date().getTime());
4647
gitFailFast(['checkout', '-b', publishBranch], { cwd });
47-
console.log('Bumping version for npm publish');
48+
49+
if (options.bump) {
50+
console.log('Bumping version for npm publish');
51+
}
52+
4853
const bumpInfo = gatherBumpInfo(options);
4954

5055
if (options.new) {
@@ -60,7 +65,7 @@ export async function publish(options: BeachballOptions) {
6065
}
6166
// Step 2.
6267
// - reset, fetch latest from origin/master (to ensure less chance of conflict), then bump again + commit
63-
if (branch && options.push) {
68+
if (options.bump && branch && options.push) {
6469
await bumpAndPush(bumpInfo, publishBranch, options);
6570
} else {
6671
console.log('Skipping git push and tagging');

packages/beachball/src/help.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Options:
3232
for change command: description of the change
3333
--no-push - skip pushing changes back to git remote origin
3434
--no-publish - skip publishing to the npm registry
35+
--no-bump - skip both bumping versions and pushing changes back to git remote origin when publishing;
3536
--help, -?, -h - this very help message
3637
--yes, -y - skips the prompts for publish
3738
--package, -p - manually specify a package to create a change file; creates a change file regardless of diffs

packages/beachball/src/options/getDefaultOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ export function getDefaultOptions() {
2424
scope: null,
2525
retries: 3,
2626
timeout: undefined,
27+
bump: true,
2728
} as BeachballOptions;
2829
}

packages/beachball/src/publish/publishToRegistry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export async function publishToRegistry(originalBumpInfo: BumpInfo, options: Bea
1515
const bumpInfo = _.cloneDeep(originalBumpInfo);
1616
const { modifiedPackages, newPackages, packageInfos } = bumpInfo;
1717

18-
await performBump(bumpInfo, options);
18+
if (options.bump) {
19+
await performBump(bumpInfo, options);
20+
}
1921

2022
const succeededPackages = new Set<string>();
2123

packages/beachball/src/types/BeachballOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface CliOptions {
3030
timeout?: number;
3131
fromRef?: string;
3232
keepChangeFiles?: boolean;
33+
bump: boolean;
3334
}
3435

3536
export interface RepoOptions {

0 commit comments

Comments
 (0)