Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow the creation of tags without pushing #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
1. `hotfix:patch,pre-feat:preminor`,
2. `bug:patch:Bug Fixes,chore:patch:Chores`

#### Create a tag without pushing it
- **push_tag** _(optional)_ - Push the tag to the remote. If false, tag is created but not pushed. (default: `true`)

#### Debugging

- **dry_run** _(optional)_ - Do not perform tagging, just calculate next version and changelog, then exit
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ inputs:
description: "Do not perform tagging, just calculate next version and changelog, then exit."
required: false
default: "false"
push_tag:
description: "Push the created tag to remote ref. If false, tag is created, but not pushed."
required: false
default: "true"

runs:
using: "node16"
Expand Down
3 changes: 2 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default async function main() {
const customReleaseRules = core.getInput('custom_release_rules');
const shouldFetchAllTags = core.getInput('fetch_all_tags');
const commitSha = core.getInput('commit_sha');
const pushTag = core.getBooleanInput('push_tag');

let mappedReleaseRules;
if (customReleaseRules) {
Expand Down Expand Up @@ -228,5 +229,5 @@ export default async function main() {
return;
}

await createTag(newTag, createAnnotatedTag, commitRef);
await createTag(newTag, createAnnotatedTag, commitRef, pushTag);
}
19 changes: 12 additions & 7 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export async function compareCommits(baseRef: string, headRef: string) {
export async function createTag(
newTag: string,
createAnnotatedTag: boolean,
GITHUB_SHA: string
GITHUB_SHA: string,
pushTag: boolean = true
) {
const octokit = getOctokitSingleton();
let annotatedTag:
Expand All @@ -85,10 +86,14 @@ export async function createTag(
});
}

core.debug(`Pushing new tag to the repo.`);
await octokit.git.createRef({
...context.repo,
ref: `refs/tags/${newTag}`,
sha: annotatedTag ? annotatedTag.data.sha : GITHUB_SHA,
});
if (pushTag) {
core.debug(`Pushing new tag to the repo.`);
await octokit.git.createRef({
...context.repo,
ref: `refs/tags/${newTag}`,
sha: annotatedTag ? annotatedTag.data.sha : GITHUB_SHA,
});
} else {
core.debug(`Tag was not pushed to remote`);
}
}
75 changes: 60 additions & 15 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v0.0.1',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -92,7 +93,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v0.0.1',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -169,7 +171,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v2.0.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -211,7 +214,38 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.3.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});

it('does create a tag, but does not push the tag', async () => {
/*
* Given
*/
setInput('push_tag', 'false');
const commits: any[] = [];
jest
.spyOn(utils, 'getCommits')
.mockImplementation(async (sha) => commits);

const validTags: any[] = [];
jest
.spyOn(utils, 'getValidTags')
.mockImplementation(async () => validTags);
/*
* When
*/
await action();
/*
* Then
*/
expect(mockCreateTag).toHaveBeenCalledWith(
'v0.0.1',
expect.any(Boolean),
expect.any(String),
false
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -257,7 +291,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.2.4',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -297,7 +332,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.3.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -341,7 +377,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v2.0.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -395,7 +432,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v2.2.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -440,7 +478,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.3.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -522,7 +561,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.2.4-prerelease.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -560,7 +600,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.2.4-prerelease.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -600,7 +641,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.3.0-prerelease.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -644,7 +686,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v2.0.0-prerelease.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -701,7 +744,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v2.2.0-prerelease.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down Expand Up @@ -746,7 +790,8 @@ describe('github-tag-action', () => {
expect(mockCreateTag).toHaveBeenCalledWith(
'v1.3.0-prerelease.0',
expect.any(Boolean),
expect.any(String)
expect.any(String),
true
);
expect(mockSetFailed).not.toBeCalled();
});
Expand Down