Merge pull request #11 from PaulHatch/feature/short-flag

Add support for disabling short tags
This commit is contained in:
Paul Hatcherian 2020-12-20 10:12:16 -05:00 committed by GitHub
commit 80758ecbf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 5 deletions

View file

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

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

View file

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

View file

@ -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
@ -447,3 +448,18 @@ test('Current tag is used', () => {
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();
});

View file

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