feat: add tagSuffix input
This commit is contained in:
parent
8cb7a0b5fa
commit
d465377547
11
README.md
11
README.md
|
@ -110,6 +110,17 @@ Prefix that is used for the git tag (optional). Example:
|
||||||
tag-prefix: 'v'
|
tag-prefix: 'v'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### **tag-suffix:**
|
||||||
|
Suffix that is used for the git tag (optional). Example:
|
||||||
|
```yaml
|
||||||
|
- name: 'Automated Version Bump'
|
||||||
|
uses: 'phips28/gh-action-bump-version@master'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag-suffix: '-beta'
|
||||||
|
```
|
||||||
|
|
||||||
#### **skip-tag:**
|
#### **skip-tag:**
|
||||||
The tag is not added to the git repository (optional). Example:
|
The tag is not added to the git repository (optional). Example:
|
||||||
```yaml
|
```yaml
|
||||||
|
|
|
@ -11,6 +11,10 @@ inputs:
|
||||||
description: 'Prefix that is used for the git tag'
|
description: 'Prefix that is used for the git tag'
|
||||||
default: ''
|
default: ''
|
||||||
required: false
|
required: false
|
||||||
|
tag-suffix:
|
||||||
|
description: 'Suffix that is used for the git tag'
|
||||||
|
default: ''
|
||||||
|
required: false
|
||||||
version-type:
|
version-type:
|
||||||
description: 'Overrides version type from commit message'
|
description: 'Overrides version type from commit message'
|
||||||
default: ''
|
default: ''
|
||||||
|
|
10
index.js
10
index.js
|
@ -32,14 +32,16 @@ const pkg = getPackageJson();
|
||||||
|
|
||||||
const versionType = process.env['INPUT_VERSION-TYPE'];
|
const versionType = process.env['INPUT_VERSION-TYPE'];
|
||||||
const tagPrefix = process.env['INPUT_TAG-PREFIX'] || '';
|
const tagPrefix = process.env['INPUT_TAG-PREFIX'] || '';
|
||||||
|
const tagSuffix = process.env['INPUT_TAG-SUFFIX'] || '';
|
||||||
console.log('tagPrefix:', tagPrefix);
|
console.log('tagPrefix:', tagPrefix);
|
||||||
|
console.log('tagSuffix:', tagSuffix);
|
||||||
const messages = event.commits ? event.commits.map((commit) => commit.message + '\n' + commit.body) : [];
|
const messages = event.commits ? event.commits.map((commit) => commit.message + '\n' + commit.body) : [];
|
||||||
|
|
||||||
const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}';
|
const commitMessage = process.env['INPUT_COMMIT-MESSAGE'] || 'ci: version bump to {{version}}';
|
||||||
console.log('commit messages:', messages);
|
console.log('commit messages:', messages);
|
||||||
|
|
||||||
const bumpPolicy = process.env['INPUT_BUMP-POLICY'] || 'all';
|
const bumpPolicy = process.env['INPUT_BUMP-POLICY'] || 'all';
|
||||||
const commitMessageRegex = new RegExp(commitMessage.replace(/{{version}}/g, `${tagPrefix}\\d+\\.\\d+\\.\\d+`), 'ig');
|
const commitMessageRegex = new RegExp(commitMessage.replace(/{{version}}/g, `${tagPrefix}\\d+\\.\\d+\\.\\d+${tagSuffix}`), 'ig');
|
||||||
|
|
||||||
let isVersionBump = false;
|
let isVersionBump = false;
|
||||||
|
|
||||||
|
@ -186,7 +188,7 @@ const pkg = getPackageJson();
|
||||||
console.log('current 1:', current, '/', 'version:', version);
|
console.log('current 1:', current, '/', 'version:', version);
|
||||||
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim().replace(/^v/, '');
|
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim().replace(/^v/, '');
|
||||||
console.log('newVersion 1:', newVersion);
|
console.log('newVersion 1:', newVersion);
|
||||||
newVersion = `${tagPrefix}${newVersion}`;
|
newVersion = `${tagPrefix}${newVersion}${tagSuffix}`;
|
||||||
if (process.env['INPUT_SKIP-COMMIT'] !== 'true') {
|
if (process.env['INPUT_SKIP-COMMIT'] !== 'true') {
|
||||||
await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]);
|
await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]);
|
||||||
}
|
}
|
||||||
|
@ -205,8 +207,8 @@ const pkg = getPackageJson();
|
||||||
// https://github.com/phips28/gh-action-bump-version/issues/166#issuecomment-1142640018
|
// https://github.com/phips28/gh-action-bump-version/issues/166#issuecomment-1142640018
|
||||||
newVersion = newVersion.split(/\n/)[1] || newVersion;
|
newVersion = newVersion.split(/\n/)[1] || newVersion;
|
||||||
console.log('newVersion 2:', newVersion);
|
console.log('newVersion 2:', newVersion);
|
||||||
newVersion = `${tagPrefix}${newVersion}`;
|
newVersion = `${tagPrefix}${newVersion}${tagSuffix}`;
|
||||||
console.log(`newVersion after merging tagPrefix+newVersion: ${newVersion}`);
|
console.log(`newVersion after merging tagPrefix+newVersion+tagSuffix: ${newVersion}`);
|
||||||
// Using sh as command instead of directly echo to be able to use file redirection
|
// Using sh as command instead of directly echo to be able to use file redirection
|
||||||
await runInWorkspace('sh', ['-c', `echo "newTag=${newVersion}" >> $GITHUB_OUTPUT`]);
|
await runInWorkspace('sh', ['-c', `echo "newTag=${newVersion}" >> $GITHUB_OUTPUT`]);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -131,6 +131,49 @@ suites:
|
||||||
expected:
|
expected:
|
||||||
version: 4.1.2
|
version: 4.1.2
|
||||||
tag: v4.1.2
|
tag: v4.1.2
|
||||||
|
- name: custom-tag-suffix
|
||||||
|
yaml:
|
||||||
|
name: Bump Version (Custom Tag Suffix)
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
jobs:
|
||||||
|
bump-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- id: version-bump
|
||||||
|
uses: ./action
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag-suffix: '-beta'
|
||||||
|
tests:
|
||||||
|
- message: no keywords
|
||||||
|
expected:
|
||||||
|
version: 4.1.2
|
||||||
|
tag: 4.1.2-beta
|
||||||
|
- name: custom-tag-prefix-with-suffix
|
||||||
|
yaml:
|
||||||
|
name: Bump Version (Custom Tag Prefix With Suffix)
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
jobs:
|
||||||
|
bump-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- id: version-bump
|
||||||
|
uses: ./action
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag-prefix: 'v'
|
||||||
|
tag-suffix: '-beta'
|
||||||
|
tests:
|
||||||
|
- message: no keywords
|
||||||
|
expected:
|
||||||
|
version: 4.1.2
|
||||||
|
tag: v4.1.2-beta
|
||||||
- name: target-branch
|
- name: target-branch
|
||||||
yaml:
|
yaml:
|
||||||
name: Bump Version (Target Branch)
|
name: Bump Version (Target Branch)
|
||||||
|
|
Loading…
Reference in New Issue