mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 13:08:17 +00:00
Merge pull request #11 from PaulHatch/feature/short-flag
Add support for disabling short tags
This commit is contained in:
commit
80758ecbf6
5 changed files with 34 additions and 5 deletions
|
|
@ -30,6 +30,10 @@ inputs:
|
|||
namespace:
|
||||
description: "Use to create a named sub-version. This value will be appended to tags created for this version."
|
||||
required: false
|
||||
short_tags:
|
||||
description: "If false, only full versions, i.e. 'v1.0.0', will be supported as tags. If true, tags will support truncated minor and patch versions such as 'v1' (default)."
|
||||
required: true
|
||||
default: "true"
|
||||
outputs:
|
||||
major:
|
||||
description: "Current major number"
|
||||
|
|
|
|||
6
dist/index.js
vendored
6
dist/index.js
vendored
|
|
@ -1025,6 +1025,7 @@ const eol = '\n';
|
|||
|
||||
const tagPrefix = core.getInput('tag_prefix') || '';
|
||||
const namespace = core.getInput('namespace') || '';
|
||||
const shortTags = core.getInput('short_tags') === 'true';
|
||||
|
||||
const cmd = async (command, ...args) => {
|
||||
let output = '', errors = '';
|
||||
|
|
@ -1061,7 +1062,7 @@ const setOutput = (major, minor, patch, increment, changed, branch, namespace) =
|
|||
}
|
||||
|
||||
let tag;
|
||||
if (major === 0 || patch !== 0) {
|
||||
if (!shortTags || major === 0 || patch !== 0) {
|
||||
// Always tag pre-release/major version 0 as full version
|
||||
tag = `${tagPrefix}${major}.${minor}.${patch}`;
|
||||
} else if (minor !== 0) {
|
||||
|
|
@ -1122,7 +1123,8 @@ async function run() {
|
|||
const minorPattern = core.getInput('minor_pattern', { required: true });
|
||||
const changePath = core.getInput('change_path') || '';
|
||||
|
||||
const releasePattern = namespace === '' ? `${tagPrefix}*[0-9.]` : `${tagPrefix}*[0-9.]-${namespace}`;
|
||||
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
|
||||
let major = 0, minor = 0, patch = 0, increment = 0;
|
||||
let changed = true;
|
||||
|
||||
|
|
|
|||
6
index.js
6
index.js
|
|
@ -4,6 +4,7 @@ const eol = '\n';
|
|||
|
||||
const tagPrefix = core.getInput('tag_prefix') || '';
|
||||
const namespace = core.getInput('namespace') || '';
|
||||
const shortTags = core.getInput('short_tags') === 'true';
|
||||
|
||||
const cmd = async (command, ...args) => {
|
||||
let output = '', errors = '';
|
||||
|
|
@ -40,7 +41,7 @@ const setOutput = (major, minor, patch, increment, changed, branch, namespace) =
|
|||
}
|
||||
|
||||
let tag;
|
||||
if (major === 0 || patch !== 0) {
|
||||
if (!shortTags || major === 0 || patch !== 0) {
|
||||
// Always tag pre-release/major version 0 as full version
|
||||
tag = `${tagPrefix}${major}.${minor}.${patch}`;
|
||||
} else if (minor !== 0) {
|
||||
|
|
@ -101,7 +102,8 @@ async function run() {
|
|||
const minorPattern = core.getInput('minor_pattern', { required: true });
|
||||
const changePath = core.getInput('change_path') || '';
|
||||
|
||||
const releasePattern = namespace === '' ? `${tagPrefix}*[0-9.]` : `${tagPrefix}*[0-9.]-${namespace}`;
|
||||
const versionPattern = shortTags ? '*[0-9.]' : '[0-9]+\\.[0-9]+\\.[0-9]+'
|
||||
const releasePattern = namespace === '' ? `${tagPrefix}${versionPattern}` : `${tagPrefix}${versionPattern}-${namespace}`;
|
||||
let major = 0, minor = 0, patch = 0, increment = 0;
|
||||
let changed = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ const defaultInputs = {
|
|||
tag_prefix: "v",
|
||||
major_pattern: "(MAJOR)",
|
||||
minor_pattern: "(MINOR)",
|
||||
format: "${major}.${minor}.${patch}"
|
||||
format: "${major}.${minor}.${patch}",
|
||||
short_tags: true
|
||||
};
|
||||
|
||||
// Creates a randomly named git repository and returns a function to execute commands in it
|
||||
|
|
@ -445,5 +446,20 @@ test('Current tag is used', () => {
|
|||
|
||||
expect(result).toMatch('Version is 7.6.5+0');
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
|
||||
test('Short tag can be switched off', () => {
|
||||
const repo = createTestRepo({ tag_prefix: '', short_tags: 'false' }); // 0.0.0
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
repo.makeCommit('Second Commit');
|
||||
repo.makeCommit('Third Commit');
|
||||
repo.exec('git tag 7');
|
||||
|
||||
const result = repo.runAction();
|
||||
|
||||
expect(result).toMatch('Version is 0.0.1+2');
|
||||
|
||||
repo.clean();
|
||||
});
|
||||
|
|
@ -66,6 +66,8 @@ it will be given the new version if the build were to be retriggered, for exampl
|
|||
```yaml
|
||||
- uses: paulhatch/semantic-version@v3.1.2
|
||||
with:
|
||||
# The prefix to use to identify tags
|
||||
branch: "master"
|
||||
# The prefix to use to identify tags
|
||||
tag_prefix: "v"
|
||||
# A string which, if present in a git commit, indicates that a change represents a
|
||||
|
|
@ -80,6 +82,9 @@ it will be given the new version if the build were to be retriggered, for exampl
|
|||
change_path: "src/my-service"
|
||||
# Named version, will be used as suffix for name version tag
|
||||
namespace: project-b
|
||||
# Indicate whether short tags like 'v1' should be supported. If false only full
|
||||
# tags like 'v1.0.0' will be recognized.
|
||||
short_tags: true
|
||||
```
|
||||
|
||||
## Using Multiple Versions in the Same Repository
|
||||
|
|
|
|||
Loading…
Reference in a new issue