diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9d9b6f4..2a83386 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,7 @@ name: Test on: + pull_request: push: branches: - '**' diff --git a/src/steps/success.test.ts b/src/steps/success.test.ts index abe2278..e56158e 100644 --- a/src/steps/success.test.ts +++ b/src/steps/success.test.ts @@ -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 = @@ -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:test-credentials@example.com/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(); + }); }); diff --git a/src/steps/success.ts b/src/steps/success.ts index 46aafda..093f27e 100644 --- a/src/steps/success.ts +++ b/src/steps/success.ts @@ -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;