Merge branch 'master' into feature/commit_sha
This commit is contained in:
commit
438b61463e
|
|
@ -17,7 +17,7 @@ jobs:
|
|||
- uses: actions/checkout@v2
|
||||
- name: Bump version and push tag
|
||||
id: tag_version
|
||||
uses: mathieudutour/github-tag-action@v5.6
|
||||
uses: mathieudutour/github-tag-action@v6.0
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Create a GitHub release
|
||||
|
|
@ -44,7 +44,8 @@ jobs:
|
|||
|
||||
#### Customize the tag
|
||||
|
||||
- **default_bump** _(optional)_ - Which type of bump to use when [none is explicitly provided](#bumping) (default: `patch`). You can also set `false` to avoid generating a new tag when none is explicitly provided.
|
||||
- **default_bump** _(optional)_ - Which type of bump to use when [none is explicitly provided](#bumping) when commiting to a release branch (default: `patch`). You can also set `false` to avoid generating a new tag when none is explicitly provided. Can be `patch, minor or major`.
|
||||
- **default_prerelease_bump** _(optional)_ - Which type of bump to use when [none is explicitly provided](#bumping) when commiting to a prerelease branch (default: `prerelease`). You can also set `false` to avoid generating a new tag when none is explicitly provided. Can be `prerelease, prepatch, preminor or premajor`.
|
||||
- **custom_tag** _(optional)_ - Custom tag name. If specified, it overrides bump settings.
|
||||
- **create_annotated_tag** _(optional)_ - Boolean to create an annotated rather than a lightweight one (default: `false`).
|
||||
- **tag_prefix** _(optional)_ - A prefix to the tag name (default: `v`).
|
||||
|
|
|
|||
|
|
@ -17,9 +17,13 @@ inputs:
|
|||
description: "Required for permission to tag the repo."
|
||||
required: true
|
||||
default_bump:
|
||||
description: "Which type of bump to use when none explicitly provided (default: `patch`)."
|
||||
description: "Which type of bump to use when none explicitly provided when commiting to a release branch (default: `patch`)."
|
||||
required: false
|
||||
default: "patch"
|
||||
default_prerelease_bump:
|
||||
description: "Which type of bump to use when none explicitly provided when commiting to a prerelease branch (default: `prerelease`)."
|
||||
required: false
|
||||
default: "prerelease"
|
||||
tag_prefix:
|
||||
description: "A prefix to the tag name (default: `v`)."
|
||||
required: false
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "github-tag-action",
|
||||
"version": "5.6.0",
|
||||
"version": "6.0.0",
|
||||
"private": true,
|
||||
"description": "A GitHub Action to automatically bump and tag master, on merge, with the latest SemVer formatted version.",
|
||||
"main": "lib/main.js",
|
||||
|
|
@ -21,24 +21,25 @@
|
|||
"author": "Mathieu Dutour",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/core": "^1.6.0",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"@actions/github": "^4.0.0",
|
||||
"@semantic-release/commit-analyzer": "^8.0.1",
|
||||
"@semantic-release/release-notes-generator": "^9.0.1",
|
||||
"conventional-changelog-conventionalcommits": "^4.5.0",
|
||||
"semver": "^7.3.4"
|
||||
"conventional-changelog-conventionalcommits": "^4.6.1",
|
||||
"semver": "^7.3.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/rest": "^18.0.12",
|
||||
"@types/js-yaml": "^3.12.5",
|
||||
"@types/node": "^14.14.19",
|
||||
"@types/semver": "^7.1.0",
|
||||
"jest": "^26.6.3",
|
||||
"jest-circus": "^26.6.3",
|
||||
"js-yaml": "^3.14.0",
|
||||
"prettier": "2.2.1",
|
||||
"ts-jest": "^26.4.4",
|
||||
"typescript": "^4.1.3"
|
||||
"@octokit/rest": "^18.12.0",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/js-yaml": "^4.0.4",
|
||||
"@types/node": "^16.11.7",
|
||||
"@types/semver": "^7.3.9",
|
||||
"jest": "^27.3.1",
|
||||
"jest-circus": "^27.3.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "2.4.1",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ import { Await } from './ts';
|
|||
|
||||
export default async function main() {
|
||||
const defaultBump = core.getInput('default_bump') as ReleaseType | 'false';
|
||||
const defaultPreReleaseBump = core.getInput('default_prerelease_bump') as
|
||||
| ReleaseType
|
||||
| 'false';
|
||||
const tagPrefix = core.getInput('tag_prefix');
|
||||
const customTag = core.getInput('custom_tag');
|
||||
const releaseBranches = core.getInput('release_branches');
|
||||
|
|
@ -126,13 +129,31 @@ export default async function main() {
|
|||
{ commits, logger: { log: console.info.bind(console) } }
|
||||
);
|
||||
|
||||
if (!bump && defaultBump === 'false') {
|
||||
// Determine if we should continue with tag creation based on main vs prerelease branch
|
||||
let shouldContinue = true;
|
||||
if (isPrerelease) {
|
||||
if (!bump && defaultPreReleaseBump === 'false') {
|
||||
shouldContinue = false;
|
||||
}
|
||||
} else {
|
||||
if (!bump && defaultBump === 'false') {
|
||||
shouldContinue = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Default bump is set to false and we did not find an automatic bump
|
||||
if (!shouldContinue) {
|
||||
core.debug(
|
||||
'No commit specifies the version bump. Skipping the tag creation.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// If we don't have an automatic bump for the prerelease, just set our bump as the default
|
||||
if (isPrerelease && !bump) {
|
||||
bump = defaultPreReleaseBump;
|
||||
}
|
||||
|
||||
// If somebody uses custom release rules on a prerelease branch they might create a 'preprepatch' bump.
|
||||
const preReg = /^pre/;
|
||||
if (isPrerelease && preReg.test(bump)) {
|
||||
|
|
@ -140,7 +161,7 @@ export default async function main() {
|
|||
}
|
||||
|
||||
const releaseType: ReleaseType = isPrerelease
|
||||
? `pre${bump || defaultBump}`
|
||||
? `pre${bump}`
|
||||
: bump || defaultBump;
|
||||
core.setOutput('release_type', releaseType);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,17 +17,16 @@ type ChangelogRule = {
|
|||
* https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-angular/writer-opts.js
|
||||
* https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-conventionalcommits/writer-opts.js
|
||||
*/
|
||||
export const defaultChangelogRules: Readonly<
|
||||
Record<string, ChangelogRule>
|
||||
> = Object.freeze({
|
||||
feat: { type: 'feat', section: 'Features' },
|
||||
fix: { type: 'fix', section: 'Bug Fixes' },
|
||||
perf: { type: 'perf', section: 'Performance Improvements' },
|
||||
revert: { type: 'revert', section: 'Reverts' },
|
||||
docs: { type: 'docs', section: 'Documentation' },
|
||||
style: { type: 'style', section: 'Styles' },
|
||||
refactor: { type: 'refactor', section: 'Code Refactoring' },
|
||||
test: { type: 'test', section: 'Tests' },
|
||||
build: { type: 'build', section: 'Build Systems' },
|
||||
ci: { type: 'ci', section: 'Continuous Integration' },
|
||||
});
|
||||
export const defaultChangelogRules: Readonly<Record<string, ChangelogRule>> =
|
||||
Object.freeze({
|
||||
feat: { type: 'feat', section: 'Features' },
|
||||
fix: { type: 'fix', section: 'Bug Fixes' },
|
||||
perf: { type: 'perf', section: 'Performance Improvements' },
|
||||
revert: { type: 'revert', section: 'Reverts' },
|
||||
docs: { type: 'docs', section: 'Documentation' },
|
||||
style: { type: 'style', section: 'Styles' },
|
||||
refactor: { type: 'refactor', section: 'Code Refactoring' },
|
||||
test: { type: 'test', section: 'Tests' },
|
||||
build: { type: 'build', section: 'Build Systems' },
|
||||
ci: { type: 'ci', section: 'Continuous Integration' },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import action from './action';
|
|||
async function run() {
|
||||
try {
|
||||
await action();
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/utils.ts
10
src/utils.ts
|
|
@ -31,7 +31,10 @@ export async function getValidTags(
|
|||
return validTags;
|
||||
}
|
||||
|
||||
export async function getCommits(baseRef: string, headRef: string) {
|
||||
export async function getCommits(
|
||||
baseRef: string,
|
||||
headRef: string
|
||||
): Promise<{ message: string; hash: string | null }[]> {
|
||||
const commits = await compareCommits(baseRef, headRef);
|
||||
|
||||
return commits
|
||||
|
|
@ -111,9 +114,8 @@ export function mapCustomReleaseRules(customReleaseTypes: string) {
|
|||
return true;
|
||||
})
|
||||
.map((customReleaseRule) => {
|
||||
const [type, release, section] = customReleaseRule.split(
|
||||
releaseTypeSeparator
|
||||
);
|
||||
const [type, release, section] =
|
||||
customReleaseRule.split(releaseTypeSeparator);
|
||||
const defaultRule = defaultChangelogRules[type.toLowerCase()];
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -7,12 +7,17 @@ import {
|
|||
setBranch,
|
||||
setCommitSha,
|
||||
setInput,
|
||||
setRepository,
|
||||
} from './helper.test';
|
||||
|
||||
jest.spyOn(core, 'debug').mockImplementation(() => {});
|
||||
jest.spyOn(core, 'info').mockImplementation(() => {});
|
||||
jest.spyOn(console, 'info').mockImplementation(() => {});
|
||||
|
||||
beforeAll(() => {
|
||||
setRepository('https://github.com', 'org/repo');
|
||||
});
|
||||
|
||||
const mockCreateTag = jest
|
||||
.spyOn(github, 'createTag')
|
||||
.mockResolvedValue(undefined);
|
||||
|
|
@ -448,6 +453,80 @@ describe('github-tag-action', () => {
|
|||
setInput('pre_release_branches', 'prerelease');
|
||||
});
|
||||
|
||||
it('does not create tag without commits and default_bump set to false', async () => {
|
||||
/*
|
||||
* Given
|
||||
*/
|
||||
setInput('default_prerelease_bump', 'false');
|
||||
const commits: any[] = [];
|
||||
jest
|
||||
.spyOn(utils, 'getCommits')
|
||||
.mockImplementation(async (sha) => commits);
|
||||
|
||||
const validTags = [
|
||||
{
|
||||
name: 'v1.2.3',
|
||||
commit: { sha: '012345', url: '' },
|
||||
zipball_url: '',
|
||||
tarball_url: 'string',
|
||||
node_id: 'string',
|
||||
},
|
||||
];
|
||||
jest
|
||||
.spyOn(utils, 'getValidTags')
|
||||
.mockImplementation(async () => validTags);
|
||||
|
||||
/*
|
||||
* When
|
||||
*/
|
||||
await action();
|
||||
|
||||
/*
|
||||
* Then
|
||||
*/
|
||||
expect(mockCreateTag).not.toBeCalled();
|
||||
expect(mockSetFailed).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('does create prerelease tag', async () => {
|
||||
/*
|
||||
* Given
|
||||
*/
|
||||
setInput('default_prerelease_bump', 'prerelease');
|
||||
const commits = [{ message: 'this is my first fix', hash: null }];
|
||||
jest
|
||||
.spyOn(utils, 'getCommits')
|
||||
.mockImplementation(async (sha) => commits);
|
||||
|
||||
const validTags = [
|
||||
{
|
||||
name: 'v1.2.3',
|
||||
commit: { sha: '012345', url: '' },
|
||||
zipball_url: '',
|
||||
tarball_url: 'string',
|
||||
node_id: 'string',
|
||||
},
|
||||
];
|
||||
jest
|
||||
.spyOn(utils, 'getValidTags')
|
||||
.mockImplementation(async () => validTags);
|
||||
|
||||
/*
|
||||
* When
|
||||
*/
|
||||
await action();
|
||||
|
||||
/*
|
||||
* Then
|
||||
*/
|
||||
expect(mockCreateTag).toHaveBeenCalledWith(
|
||||
'v1.2.4-prerelease.0',
|
||||
expect.any(Boolean),
|
||||
expect.any(String)
|
||||
);
|
||||
expect(mockSetFailed).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('does create prepatch tag', async () => {
|
||||
/*
|
||||
* Given
|
||||
|
|
|
|||
|
|
@ -2,6 +2,14 @@ import yaml from 'js-yaml';
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export function setRepository(
|
||||
GITHUB_SERVER_URL: string,
|
||||
GITHUB_REPOSITORY: string
|
||||
) {
|
||||
process.env['GITHUB_SERVER_URL'] = GITHUB_SERVER_URL;
|
||||
process.env['GITHUB_REPOSITORY'] = GITHUB_REPOSITORY;
|
||||
}
|
||||
|
||||
export function setBranch(branch: string) {
|
||||
process.env['GITHUB_REF'] = `refs/heads/${branch}`;
|
||||
}
|
||||
|
|
@ -23,7 +31,7 @@ export function loadDefaultInputs() {
|
|||
path.join(process.cwd(), 'action.yml'),
|
||||
'utf-8'
|
||||
);
|
||||
const actionJson = yaml.safeLoad(actionYaml) as {
|
||||
const actionJson = yaml.load(actionYaml) as {
|
||||
inputs: { [key: string]: { default?: string } };
|
||||
};
|
||||
const defaultInputs = Object.keys(actionJson['inputs'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue