Compare commits

...

52 Commits
v5.6 ... master

Author SHA1 Message Date
dependabot[bot] 9d35d648e8
Bump ws from 7.5.5 to 7.5.10 (#216)
Bumps [ws](https://github.com/websockets/ws) from 7.5.5 to 7.5.10.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/7.5.5...7.5.10)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-18 09:28:43 +02:00
dependabot[bot] 17d01dc92c
Bump braces from 3.0.2 to 3.0.3 (#215)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-18 09:28:29 +02:00
mathieudutour f36074fe49
version 6.2 2024-03-11 10:22:39 +01:00
Essau Ramirez f40d7eefd8
match latest tag regex (#171)
* match latest tag regex

* Lint fixes
2024-03-11 09:58:22 +01:00
Yoshikawa Teru 1bf7977a3d
fix: add previous_version to action.yml (#183) 2024-03-11 09:53:34 +01:00
dependabot[bot] 5a16d14432
Bump tough-cookie from 4.0.0 to 4.1.3 (#184)
Bumps [tough-cookie](https://github.com/salesforce/tough-cookie) from 4.0.0 to 4.1.3.
- [Release notes](https://github.com/salesforce/tough-cookie/releases)
- [Changelog](https://github.com/salesforce/tough-cookie/blob/master/CHANGELOG.md)
- [Commits](https://github.com/salesforce/tough-cookie/compare/v4.0.0...v4.1.3)

---
updated-dependencies:
- dependency-name: tough-cookie
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 09:52:34 +01:00
Filipe Veloso 71c3689659
Update README.md (#205)
update gh action checkout  version in example
2024-03-11 09:52:15 +01:00
naresh-gn a079ba461d
Update Node version to 20 (#202)
* Update Node version to 20

* Update Node version to 20

* Update Node version to 20

* Update .github/workflows/test.yml

Co-authored-by: cawfeecake <48775802+cawfeecake@users.noreply.github.com>

---------

Co-authored-by: Naresh Nagarajan <naresh-gn@gmail.com>
Co-authored-by: cawfeecake <48775802+cawfeecake@users.noreply.github.com>
2024-03-11 09:51:45 +01:00
Mathieu Dutour 86301c823d
Revert "Use `${{github.token}}` as default" (#167) 2023-02-06 13:16:45 +01:00
dependabot[bot] 5bd9038fd1
Bump minimatch from 3.0.4 to 3.1.2 (#162)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-22 17:27:02 +01:00
Chris Hilton ac8cb38838
getValidTags() should exclude tags that do not match the prefixRegex (#158) 2023-01-22 17:26:50 +01:00
dependabot[bot] 664437484d
Bump json5 from 2.1.3 to 2.2.3 (#161)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-22 17:25:57 +01:00
kzrnm 87d9c10c43
Use `${{github.token}}` as default (#154)
Co-authored-by: Mathieu Dutour <mathieu@dutour.me>
2023-01-22 17:25:46 +01:00
mathieudutour dbd80d2e9d
version 6.1 2022-10-26 11:00:15 +02:00
James Phillips a1afa112d3
Correctly parse `create_annotated_tag` (#137) 2022-10-26 10:57:31 +02:00
Mathieu Dutour 3f9dffdaa0
Merge pull request #147 from JohnTitor/nodejs16 2022-10-26 10:52:06 +02:00
Mathieu Dutour c4f56e7003
Merge pull request #146 from JohnTitor/actions-core 2022-10-26 10:51:42 +02:00
Yuki Okushi 923acce875
Update `@actions/core` to v1.10.0
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-10-14 11:46:39 +09:00
Yuki Okushi c5ababce46
Update to Node.js 16
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-10-14 11:44:46 +09:00
Mathieu Dutour e923a6115f
Merge pull request #142 from mathieudutour/dependabot/npm_and_yarn/actions/core-1.9.1 2022-08-19 08:49:47 +02:00
dependabot[bot] 8bee2b2289
Bump @actions/core from 1.6.0 to 1.9.1
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.6.0 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-18 19:17:35 +00:00
Mathieu Dutour 92dc56ebab
Merge pull request #124 from mathieudutour/dependabot/npm_and_yarn/node-fetch-2.6.7
Bump node-fetch from 2.6.1 to 2.6.7
2022-04-12 13:58:28 +02:00
dependabot[bot] 15886d3d8c
Bump node-fetch from 2.6.1 to 2.6.7
Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.1 to 2.6.7.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Commits](https://github.com/node-fetch/node-fetch/compare/v2.6.1...v2.6.7)

---
updated-dependencies:
- dependency-name: node-fetch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-12 09:50:07 +00:00
Mathieu Dutour f1a52e6b0e
Merge pull request #123 from mathieudutour/dependabot/npm_and_yarn/minimist-1.2.6
Bump minimist from 1.2.5 to 1.2.6
2022-04-12 11:49:30 +02:00
dependabot[bot] 672968b48d
Bump minimist from 1.2.5 to 1.2.6
Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-11 19:34:53 +00:00
Mathieu Dutour ba54fd76a5
Create FUNDING.yml 2021-11-17 12:21:25 +01:00
Mathieu Dutour 4cf1d6f51d
fix assignment 2021-11-17 12:15:07 +01:00
Mathieu Dutour c0f9097516
Merge pull request #83 from jimrazmus/sanitize-github-ref
fix:issue #81 - sanitize semver in branch name
2021-11-17 12:11:35 +01:00
Mathieu Dutour e4770866d6
Merge pull request #89 from amplifysa/feature/commit_sha
Allow to pass a commit SHA instead using GITHUB_SHA.
2021-11-17 12:11:09 +01:00
Yann Savary aff4bff53d Updated README.md 2021-11-16 19:44:56 +01:00
Yann Savary 1b8ac6a7b8 Fixed code style and documentation 2021-11-16 19:41:49 +01:00
Yann Savary 438b61463e Merge branch 'master' into feature/commit_sha 2021-11-16 19:16:42 +01:00
Mathieu Dutour 917867a4e1
prepare version 6.0 2021-11-16 19:14:05 +01:00
Mathieu Dutour 6f05ce192f
update deps 2021-11-16 19:07:40 +01:00
Mathieu Dutour 74942d5347
Merge pull request #102 from JonErickson/master
Support for incrementing the prerelease number when no automatic bumps are encountered.
2021-11-16 18:44:48 +01:00
Jon Erickson f26971f09b Run prettier 2021-10-29 20:37:48 -07:00
Jon Erickson 8614426b27 Updated action to include default_prerelease_bump to separate out options. 2021-10-29 20:34:06 -07:00
Jon Erickson a5ae58c758 Added more tags to prerelease test 2021-10-29 16:48:10 -07:00
Yann Savary 2fca5fd609 Merge branch 'master' into feature/commit_sha
# Conflicts:
#	src/action.ts
2021-10-28 14:07:53 +02:00
Jon Erickson 204025ad5b Test setting default_bump to prerelease increments prerelease number when no bump encountered 2021-10-18 15:35:24 -07:00
Jon Erickson c52d722673 Make sure we are only changing the bump var if it is a known prerelease commit. 2021-10-18 15:10:53 -07:00
Jon Erickson c791a95a0b Support for incrementing the prerelease number when no automatic bumps are encountered. 2021-10-18 15:06:11 -07:00
Jim Razmus II 8e69e12fa1
fix: replace returns a string
Replace is not an in-place edit AFAIK. Consequently, we need to overwrite the identifier value to get the desired sanitization effect.
2021-09-15 12:01:24 -05:00
Jim Razmus II 3cc0072f45
fix: indentation 2021-09-14 12:38:01 -05:00
Mathieu Dutour 772bd6d2ca
Merge pull request #95 from slidoapp/miluoshi-update-outdated-example-code
Update outdated example in README.md
2021-09-13 18:54:10 +02:00
Mathieu Dutour 27a5f3aa9b
Merge pull request #96 from olink78/master
use GITHUB_SERVER_URL instead of hardcoded url
2021-09-13 18:53:41 +02:00
olilin f05041888b use GITHUB_SERVER_URL instead of hardcoded url 2021-09-13 13:31:15 +02:00
Jim Razmus II caef8f4d8b
fix: consistently sanitize identifier
Guards against branch names including a semver as well as branch names having characters not allowed by the semver specification.

Co-authored-by: folex <0xdxdy@gmail.com>
2021-09-03 11:15:28 -05:00
Miloš Lajtman c5cc34d0bd
Update outdated example in README.md
`actions/create-release` action in the example snippet has been archived and replaced by `ncipollo/release-action` as can be seen in [original action's readme](https://github.com/marketplace/actions/create-release#example) in the marketplace.
Also, since [the last release](https://github.com/ncipollo/release-action/releases/tag/v1.8.8) a `token` input is not required because a github token from `github` context is set as a default input value.
2021-09-01 12:41:33 +02:00
Yann Savary 58d61ff5ab Updated README.md 2021-07-15 16:06:42 +02:00
Yann Savary aca73cf197 Added 'commit_sha' input to use this commit SHA instead GITHUB_SHA. 2021-07-15 15:41:03 +02:00
Jim Razmus II c443da5e30 fix:issue #81 - sanitize semver in branch name
PRs with branch names containing a semver break later valid'ation calls.
2021-05-06 10:49:24 -05:00
13 changed files with 3524 additions and 7352 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: [mathieudutour]

View File

@ -9,7 +9,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: package.json
- run: npm ci
- run: npm run test
- run: npm run check

View File

@ -14,25 +14,24 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v5.6
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ncipollo/release-action@v1
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
```
### 📥 Inputs
- **github_token** _(required)_ - Required for permission to tag the repo. Usually `${{ secrets.GITHUB_TOKEN }}`.
- **commit_sha** _(optional)_ - The commit SHA value to add the tag. If specified, it uses this value instead GITHUB_SHA. It could be useful when a previous step merged a branch into github.ref.
#### Fetch all tags
@ -45,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`).

View File

@ -8,6 +8,8 @@ outputs:
description: "Generated tag without the prefix"
previous_tag:
description: "Previous tag (or `0.0.0`)"
previous_version:
description: "The value of the previous tag (or 0.0.0 if none) without the prefix. Note that if custom_tag is set, this will be undefined."
release_type:
description: "The computed release type (`major`, `minor`, `patch` or `custom` - can be prefixed with `pre`)"
changelog:
@ -17,9 +19,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
@ -40,6 +46,9 @@ inputs:
pre_release_branches:
description: "Comma separated list of branches (bash reg exp accepted) that will generate pre-release tags."
required: false
commit_sha:
description: "The commit SHA value to add the tag. If specified, it uses this value instead GITHUB_SHA. It could be useful when a previous step merged a branch into github.ref."
required: false
create_annotated_tag:
description: "Boolean to create an annotated tag rather than lightweight."
required: false
@ -54,7 +63,7 @@ inputs:
default: "false"
runs:
using: "node12"
using: "node20"
main: "lib/main.js"
branding:
icon: "git-merge"

10554
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "github-tag-action",
"version": "5.6.0",
"version": "6.2.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",
@ -18,27 +18,31 @@
"node",
"setup"
],
"engines": {
"node": ">=20"
},
"author": "Mathieu Dutour",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/core": "^1.10.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": "^20.11.16",
"@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"
}
}

View File

@ -17,15 +17,21 @@ 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');
const preReleaseBranches = core.getInput('pre_release_branches');
const appendToPreReleaseTag = core.getInput('append_to_pre_release_tag');
const createAnnotatedTag = !!core.getInput('create_annotated_tag');
const createAnnotatedTag = /true/i.test(
core.getInput('create_annotated_tag')
);
const dryRun = core.getInput('dry_run');
const customReleaseRules = core.getInput('custom_release_rules');
const shouldFetchAllTags = core.getInput('fetch_all_tags');
const commitSha = core.getInput('commit_sha');
let mappedReleaseRules;
if (customReleaseRules) {
@ -39,8 +45,9 @@ export default async function main() {
return;
}
if (!GITHUB_SHA) {
core.setFailed('Missing GITHUB_SHA.');
const commitRef = commitSha || GITHUB_SHA;
if (!commitRef) {
core.setFailed('Missing commit_sha or GITHUB_SHA.');
return;
}
@ -54,9 +61,11 @@ export default async function main() {
const isPullRequest = isPr(GITHUB_REF);
const isPrerelease = !isReleaseBranch && !isPullRequest && isPreReleaseBranch;
const identifier = appendToPreReleaseTag
? appendToPreReleaseTag
: currentBranch;
// Sanitize identifier according to
// https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions
const identifier = (
appendToPreReleaseTag ? appendToPreReleaseTag : currentBranch
).replace(/[^a-zA-Z0-9-]/g, '-');
const prefixRegex = new RegExp(`^${tagPrefix}`);
@ -76,7 +85,7 @@ export default async function main() {
let newVersion: string;
if (customTag) {
commits = await getCommits(latestTag.commit.sha, GITHUB_SHA);
commits = await getCommits(latestTag.commit.sha, commitRef);
core.setOutput('release_type', 'custom');
newVersion = customTag;
@ -112,7 +121,7 @@ export default async function main() {
core.setOutput('previous_version', previousVersion.version);
core.setOutput('previous_tag', previousTag.name);
commits = await getCommits(previousTag.commit.sha, GITHUB_SHA);
commits = await getCommits(previousTag.commit.sha, commitRef);
let bump = await analyzeCommits(
{
@ -124,13 +133,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)) {
@ -138,7 +165,7 @@ export default async function main() {
}
const releaseType: ReleaseType = isPrerelease
? `pre${bump || defaultBump}`
? `pre${bump}`
: bump || defaultBump;
core.setOutput('release_type', releaseType);
@ -175,7 +202,7 @@ export default async function main() {
commits,
logger: { log: console.info.bind(console) },
options: {
repositoryUrl: `https://github.com/${process.env.GITHUB_REPOSITORY}`,
repositoryUrl: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}`,
},
lastRelease: { gitTag: latestTag.name },
nextRelease: { gitTag: newTag, version: newVersion },
@ -201,5 +228,5 @@ export default async function main() {
return;
}
await createTag(newTag, createAnnotatedTag, GITHUB_SHA);
await createTag(newTag, createAnnotatedTag, commitRef);
}

View File

@ -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' },
});

View File

@ -4,7 +4,7 @@ import action from './action';
async function run() {
try {
await action();
} catch (error) {
} catch (error: any) {
core.setFailed(error.message);
}
}

View File

@ -15,13 +15,17 @@ export async function getValidTags(
const tags = await listTags(shouldFetchAllTags);
const invalidTags = tags.filter(
(tag) => !valid(tag.name.replace(prefixRegex, ''))
(tag) =>
!prefixRegex.test(tag.name) || !valid(tag.name.replace(prefixRegex, ''))
);
invalidTags.forEach((name) => core.debug(`Found Invalid Tag: ${name}.`));
const validTags = tags
.filter((tag) => valid(tag.name.replace(prefixRegex, '')))
.filter(
(tag) =>
prefixRegex.test(tag.name) && valid(tag.name.replace(prefixRegex, ''))
)
.sort((a, b) =>
rcompare(a.name.replace(prefixRegex, ''), b.name.replace(prefixRegex, ''))
);
@ -31,7 +35,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
@ -56,7 +63,11 @@ export function getLatestTag(
tagPrefix: string
) {
return (
tags.find((tag) => !prerelease(tag.name.replace(prefixRegex, ''))) || {
tags.find(
(tag) =>
prefixRegex.test(tag.name) &&
!prerelease(tag.name.replace(prefixRegex, ''))
) || {
name: `${tagPrefix}0.0.0`,
commit: {
sha: 'HEAD',
@ -111,9 +122,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 {

View File

@ -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

View File

@ -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'])

View File

@ -57,7 +57,7 @@ describe('utils', () => {
node_id: 'string',
},
{
name: '1.2.3',
name: 'v1.2.3',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
@ -86,28 +86,28 @@ describe('utils', () => {
*/
const testTags = [
{
name: '1.2.4-prerelease.1',
name: 'v1.2.4-prerelease.1',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: '1.2.4-prerelease.2',
name: 'v1.2.4-prerelease.2',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: '1.2.4-prerelease.0',
name: 'v1.2.4-prerelease.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: '1.2.3',
name: 'v1.2.3',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
@ -128,7 +128,55 @@ describe('utils', () => {
*/
expect(mockListTags).toHaveBeenCalled();
expect(validTags[0]).toEqual({
name: '1.2.4-prerelease.2',
name: 'v1.2.4-prerelease.2',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
});
});
it('returns only prefixed tags', async () => {
/*
* Given
*/
const testTags = [
{
name: 'app2/5.0.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: '7.0.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: 'app1/3.0.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
];
const mockListTags = jest
.spyOn(github, 'listTags')
.mockImplementation(async () => testTags);
/*
* When
*/
const validTags = await getValidTags(/^app1\//, false);
/*
* Then
*/
expect(mockListTags).toHaveBeenCalled();
expect(validTags).toHaveLength(1);
expect(validTags[0]).toEqual({
name: 'app1/3.0.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',