Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "minor",
"comment": "--no-bump flag implementation",
"packageName": "beachball",
"email": "arabisho@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-08-06T15:39:17.525Z"
}
65 changes: 65 additions & 0 deletions packages/beachball/src/__e2e__/publishE2E.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('publish command (e2e)', () => {
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
});

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

it('can perform a successful npm publish without bump', async () => {
repositoryFactory = new RepositoryFactory();
await repositoryFactory.create();
const repo = await repositoryFactory.cloneRepository();

writeChangeFiles(
{
foo: {
type: 'minor',
comment: 'test',
date: new Date('2019-01-01'),
email: 'test@test.com',
packageName: 'foo',
dependentChangeType: 'patch',
},
},
repo.rootPath
);

git(['push', 'origin', 'master'], { cwd: repo.rootPath });

await publish({
branch: 'origin/master',
command: 'publish',
message: 'apply package updates',
path: repo.rootPath,
publish: true,
bumpDeps: true,
push: true,
registry: registry.getUrl(),
gitTags: true,
tag: 'latest',
token: '',
yes: true,
new: false,
access: 'public',
package: '',
changehint: 'Run "beachball change" to create a change file',
type: null,
fetch: true,
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: false,
});

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

expect(showResult.success).toBeTruthy();

const show = JSON.parse(showResult.stdout);
expect(show.name).toEqual('foo');
expect(show.versions.length).toEqual(1);
expect(show['dist-tags'].latest).toEqual('1.0.0');

git(['checkout', 'master'], { cwd: repo.rootPath });
git(['pull'], { cwd: repo.rootPath });

const gitResults = git(['describe', '--abbrev=0'], { cwd: repo.rootPath });
expect(gitResults.success).toBeFalsy();
});

it('should not perform npm publish on out-of-scope package', async () => {
repositoryFactory = new MonoRepoFactory();
await repositoryFactory.create();
Expand Down Expand Up @@ -152,6 +215,7 @@ describe('publish command (e2e)', () => {
defaultNpmTag: 'latest',
scope: ['!packages/foo'],
retries: 3,
bump: true,
});

const fooNpmResult = npm(['--registry', registry.getUrl(), 'show', 'foo', '--json']);
Expand Down Expand Up @@ -220,6 +284,7 @@ describe('publish command (e2e)', () => {
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
hooks: {
prepublish: (packagePath: string) => {
const packageJsonPath = path.join(packagePath, 'package.json');
Expand Down
2 changes: 2 additions & 0 deletions packages/beachball/src/__e2e__/publishGit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('publish command (git)', () => {
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
});

const newRepo = await repositoryFactory.cloneRepository();
Expand Down Expand Up @@ -123,6 +124,7 @@ describe('publish command (git)', () => {
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
};

const bumpInfo = gatherBumpInfo(options);
Expand Down
5 changes: 5 additions & 0 deletions packages/beachball/src/__e2e__/publishRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('publish command (registry)', () => {
defaultNpmTag: 'latest',
retries: 3,
timeout: 100,
bump: true,
});

await expect(publishPromise).rejects.toThrow();
Expand Down Expand Up @@ -135,6 +136,7 @@ describe('publish command (registry)', () => {
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
});

const showResult = npm(['--registry', registry.getUrl(), 'show', 'foo', '--json']);
Expand Down Expand Up @@ -215,6 +217,7 @@ describe('publish command (registry)', () => {
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
});

const showResult = npm(['--registry', registry.getUrl(), 'show', 'foopkg', '--json']);
Expand Down Expand Up @@ -292,6 +295,7 @@ describe('publish command (registry)', () => {
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
});

const showResultFoo = npm(['--registry', registry.getUrl(), 'show', 'foopkg', '--json']);
Expand Down Expand Up @@ -373,6 +377,7 @@ describe('publish command (registry)', () => {
disallowedChangeTypes: null,
defaultNpmTag: 'latest',
retries: 3,
bump: true,
});

const showResult = npm(['--registry', registry.getUrl(), 'show', 'badname', '--json']);
Expand Down
11 changes: 8 additions & 3 deletions packages/beachball/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export async function publish(options: BeachballOptions) {
target branch: ${branch}
tag: ${tag}

bumps versions: ${options.bump ? 'yes' : 'no'}
publishes to npm registry: ${options.publish ? 'yes' : 'no'}
pushes to remote git repo: ${options.push && options.branch ? 'yes' : 'no'}
pushes to remote git repo: ${options.bump && options.push && options.branch ? 'yes' : 'no'}

`);
if (!options.yes) {
Expand All @@ -44,7 +45,11 @@ export async function publish(options: BeachballOptions) {
// checkout publish branch
const publishBranch = 'publish_' + String(new Date().getTime());
gitFailFast(['checkout', '-b', publishBranch], { cwd });
console.log('Bumping version for npm publish');

if (options.bump) {
console.log('Bumping version for npm publish');
}

const bumpInfo = gatherBumpInfo(options);

if (options.new) {
Expand All @@ -60,7 +65,7 @@ export async function publish(options: BeachballOptions) {
}
// Step 2.
// - reset, fetch latest from origin/master (to ensure less chance of conflict), then bump again + commit
if (branch && options.push) {
if (options.bump && branch && options.push) {
await bumpAndPush(bumpInfo, publishBranch, options);
} else {
console.log('Skipping git push and tagging');
Expand Down
1 change: 1 addition & 0 deletions packages/beachball/src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Options:
for change command: description of the change
--no-push - skip pushing changes back to git remote origin
--no-publish - skip publishing to the npm registry
--no-bump - skip both bumping versions and pushing changes back to git remote origin when publishing;
--help, -?, -h - this very help message
--yes, -y - skips the prompts for publish
--package, -p - manually specify a package to create a change file; creates a change file regardless of diffs
Expand Down
1 change: 1 addition & 0 deletions packages/beachball/src/options/getDefaultOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export function getDefaultOptions() {
scope: null,
retries: 3,
timeout: undefined,
bump: true,
} as BeachballOptions;
}
4 changes: 3 additions & 1 deletion packages/beachball/src/publish/publishToRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export async function publishToRegistry(originalBumpInfo: BumpInfo, options: Bea
const bumpInfo = _.cloneDeep(originalBumpInfo);
const { modifiedPackages, newPackages, packageInfos } = bumpInfo;

await performBump(bumpInfo, options);
if (options.bump) {
await performBump(bumpInfo, options);
}

const succeededPackages = new Set<string>();

Expand Down
1 change: 1 addition & 0 deletions packages/beachball/src/types/BeachballOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface CliOptions {
timeout?: number;
fromRef?: string;
keepChangeFiles?: boolean;
bump: boolean;
}

export interface RepoOptions {
Expand Down