Skip to content

Commit

Permalink
Merge pull request #6 from EricCrosson/fix-do-not-publish-major-tags-…
Browse files Browse the repository at this point in the history
…for-prereleases

fix: do not publish major tags for prereleases
  • Loading branch information
doteric authored Feb 14, 2023
2 parents 538b1ac + 22b563a commit cf75779
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Test

on:
pull_request:
push:
branches:
- '**'
Expand Down
26 changes: 26 additions & 0 deletions src/steps/success.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jest.mock('node:child_process', () => ({
execSync: jest.fn(),
}));

afterEach(() => {
jest.clearAllMocks();
});

describe('success', () => {
it('should execute proper commands for basic major tag', () => {
const repoUrlMock =
Expand Down Expand Up @@ -85,4 +89,26 @@ describe('success', () => {
'customTags setting does not contain strings in array! customTags: true,false'
);
});

it('should not create tags for prereleases', () => {
const repoUrlMock =
'https://test-user:[email protected]/my-test-repo.git';
const contextMock = {
options: {
repositoryUrl: repoUrlMock,
},
nextRelease: {
version: '2.1.3-beta.1',
},
branch: {
prerelease: 'beta',
},
logger: { info: jest.fn(), error: jest.fn() },
} as unknown as Context;
success(
{ customTags: ['v${major}-test', 'v${major}.${minor}'] },
contextMock
);
expect(execSync).not.toBeCalled();
});
});
11 changes: 9 additions & 2 deletions src/steps/success.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import type { Context } from 'semantic-release';
import type { BranchObject, Context } from 'semantic-release';
import { execSync } from 'node:child_process';

import prepareTags from './prepareTags';
import type { PluginConfigType } from './types';

const isPrerelease = (branchObject: BranchObject) =>
branchObject && !!branchObject.prerelease;

const success = (pluginConfig: PluginConfigType, context: Context) => {
const { options, nextRelease, logger } = context;
const { options, nextRelease, logger, branch } = context;
if (isPrerelease(branch)) {
logger.info(`Not publishing any tags on a prerelease!`);
return;
}
if (!options) {
logger.error(`Missing options from context!`);
return;
Expand Down

0 comments on commit cf75779

Please sign in to comment.