Skip to content

Commit

Permalink
Merge pull request #197 from sbsrnt/master
Browse files Browse the repository at this point in the history
feat: add tagSuffix input
  • Loading branch information
phips28 authored Nov 21, 2022
2 parents 8cb7a0b + d465377 commit a8fe0cc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ Prefix that is used for the git tag (optional). Example:
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:**
The tag is not added to the git repository (optional). Example:
```yaml
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inputs:
description: 'Prefix that is used for the git tag'
default: ''
required: false
tag-suffix:
description: 'Suffix that is used for the git tag'
default: ''
required: false
version-type:
description: 'Overrides version type from commit message'
default: ''
Expand Down
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ const pkg = getPackageJson();

const versionType = process.env['INPUT_VERSION-TYPE'];
const tagPrefix = process.env['INPUT_TAG-PREFIX'] || '';
const tagSuffix = process.env['INPUT_TAG-SUFFIX'] || '';
console.log('tagPrefix:', tagPrefix);
console.log('tagSuffix:', tagSuffix);
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}}';
console.log('commit messages:', messages);

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;

Expand Down Expand Up @@ -186,7 +188,7 @@ const pkg = getPackageJson();
console.log('current 1:', current, '/', 'version:', version);
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim().replace(/^v/, '');
console.log('newVersion 1:', newVersion);
newVersion = `${tagPrefix}${newVersion}`;
newVersion = `${tagPrefix}${newVersion}${tagSuffix}`;
if (process.env['INPUT_SKIP-COMMIT'] !== 'true') {
await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]);
}
Expand All @@ -205,8 +207,8 @@ const pkg = getPackageJson();
// https://github.com/phips28/gh-action-bump-version/issues/166#issuecomment-1142640018
newVersion = newVersion.split(/\n/)[1] || newVersion;
console.log('newVersion 2:', newVersion);
newVersion = `${tagPrefix}${newVersion}`;
console.log(`newVersion after merging tagPrefix+newVersion: ${newVersion}`);
newVersion = `${tagPrefix}${newVersion}${tagSuffix}`;
console.log(`newVersion after merging tagPrefix+newVersion+tagSuffix: ${newVersion}`);
// Using sh as command instead of directly echo to be able to use file redirection
await runInWorkspace('sh', ['-c', `echo "newTag=${newVersion}" >> $GITHUB_OUTPUT`]);
try {
Expand Down
43 changes: 43 additions & 0 deletions tests/end-to-end/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,49 @@ suites:
expected:
version: 4.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
yaml:
name: Bump Version (Target Branch)
Expand Down

0 comments on commit a8fe0cc

Please sign in to comment.