fix: allow running the action on a PR
This commit is contained in:
parent
8dc6c0deb2
commit
c627331682
|
@ -4,6 +4,7 @@ import { analyzeCommits } from '@semantic-release/commit-analyzer';
|
|||
import { generateNotes } from '@semantic-release/release-notes-generator';
|
||||
import {
|
||||
getBranchFromRef,
|
||||
isPr,
|
||||
getCommits,
|
||||
getLatestPrereleaseTag,
|
||||
getLatestTag,
|
||||
|
@ -48,7 +49,8 @@ export default async function main() {
|
|||
const isPreReleaseBranch = preReleaseBranches
|
||||
.split(',')
|
||||
.some((branch) => currentBranch.match(branch));
|
||||
const isPrerelease = !isReleaseBranch && isPreReleaseBranch;
|
||||
const isPullRequest = isPr(GITHUB_REF);
|
||||
const isPrerelease = !isReleaseBranch && !isPullRequest && isPreReleaseBranch;
|
||||
|
||||
const identifier = appendToPreReleaseTag
|
||||
? appendToPreReleaseTag
|
||||
|
@ -128,7 +130,13 @@ export default async function main() {
|
|||
? `pre${bump || defaultBump}`
|
||||
: bump || defaultBump;
|
||||
|
||||
const incrementedVersion = inc(previousVersion, releaseType, identifier);
|
||||
let incrementedVersion: string | null;
|
||||
|
||||
if (isPullRequest) {
|
||||
incrementedVersion = inc(previousVersion, releaseType);
|
||||
} else {
|
||||
incrementedVersion = inc(previousVersion, releaseType, identifier);
|
||||
}
|
||||
|
||||
if (!incrementedVersion) {
|
||||
core.setFailed('Could not increment version.');
|
||||
|
|
|
@ -42,6 +42,10 @@ export function getBranchFromRef(ref: string) {
|
|||
return ref.replace('refs/heads/', '');
|
||||
}
|
||||
|
||||
export function isPr(ref: string) {
|
||||
return ref.includes('refs/pull/');
|
||||
}
|
||||
|
||||
export function getLatestTag(
|
||||
tags: Tags,
|
||||
prefixRegex: RegExp,
|
||||
|
|
|
@ -26,6 +26,23 @@ describe('utils', () => {
|
|||
expect(branch).toEqual('master');
|
||||
});
|
||||
|
||||
it('test if ref is PR', () => {
|
||||
/*
|
||||
* Given
|
||||
*/
|
||||
const remoteRef = 'refs/pull/123/merge';
|
||||
|
||||
/*
|
||||
* When
|
||||
*/
|
||||
const isPullRequest = utils.isPr(remoteRef);
|
||||
|
||||
/*
|
||||
* Then
|
||||
*/
|
||||
expect(isPullRequest).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns valid tags', async () => {
|
||||
/*
|
||||
* Given
|
||||
|
|
Loading…
Reference in New Issue