Merge pull request #139 from emagnier/skip-commit
Added option to skip commit after a bump
This commit is contained in:
commit
a5a557d91d
10
README.md
10
README.md
|
@ -54,6 +54,16 @@ Remove the 'actions/setup-node@v1' step from your action.yml file
|
|||
skip-tag: 'true'
|
||||
```
|
||||
|
||||
**skip-commit:** No commit is made after the version is bumped (optional). Example:
|
||||
```yaml
|
||||
- name: 'Automated Version Bump'
|
||||
uses: 'phips28/gh-action-bump-version@master'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
skip-commit: 'true'
|
||||
```
|
||||
|
||||
**default:** Set a default version bump to use (optional - defaults to patch). Example:
|
||||
```yaml
|
||||
- name: 'Automated Version Bump'
|
||||
|
|
|
@ -30,6 +30,10 @@ inputs:
|
|||
description: 'Avoid to add a TAG to the version update commit'
|
||||
default: 'false'
|
||||
required: false
|
||||
skip-commit:
|
||||
description: 'Avoid to add a commit after the version is bumped'
|
||||
default: 'false'
|
||||
required: false
|
||||
PACKAGEJSON_DIR:
|
||||
description: 'Custom dir to the package'
|
||||
default: ''
|
||||
|
|
8
index.js
8
index.js
|
@ -146,7 +146,9 @@ const workspace = process.env.GITHUB_WORKSPACE;
|
|||
console.log('current:', current, '/', 'version:', version);
|
||||
let newVersion = execSync(`npm version --git-tag-version=false ${version}`).toString().trim().replace(/^v/, '');
|
||||
newVersion = `${tagPrefix}${newVersion}`;
|
||||
await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]);
|
||||
if (process.env['INPUT_SKIP-COMMIT'] !== 'true') {
|
||||
await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]);
|
||||
}
|
||||
|
||||
// now go to the actual branch to perform the same versioning
|
||||
if (isPullRequest) {
|
||||
|
@ -161,7 +163,9 @@ const workspace = process.env.GITHUB_WORKSPACE;
|
|||
console.log(`::set-output name=newTag::${newVersion}`);
|
||||
try {
|
||||
// to support "actions/checkout@v1"
|
||||
await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]);
|
||||
if (process.env['INPUT_SKIP-COMMIT'] !== 'true') {
|
||||
await runInWorkspace('git', ['commit', '-a', '-m', commitMessage.replace(/{{version}}/g, newVersion)]);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
'git commit failed because you are using "actions/checkout@v2"; ' +
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"version": "9.0.7",
|
||||
"name": "gh-action-bump-version",
|
||||
"version": "9.0.10",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.1",
|
||||
|
|
|
@ -155,6 +155,27 @@ suites:
|
|||
expected:
|
||||
version: 4.1.3
|
||||
branch: other-branch
|
||||
- name: skip-commit
|
||||
yaml:
|
||||
name: Bump Version (Skip Commit)
|
||||
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:
|
||||
skip-commit: true
|
||||
tests:
|
||||
- message: no keywords
|
||||
expected:
|
||||
version: 4.1.4
|
||||
message: 'ci: version bump to 4.1.3'
|
||||
|
||||
actionFiles:
|
||||
- index.js
|
||||
|
|
|
@ -99,7 +99,12 @@ async function getMostRecentWorkflowRunDate() {
|
|||
return date;
|
||||
}
|
||||
|
||||
function generateExpectationText({ version: expectedVersion, tag: expectedTag, branch: expectedBranch }) {
|
||||
function generateExpectationText({
|
||||
version: expectedVersion,
|
||||
tag: expectedTag,
|
||||
branch: expectedBranch,
|
||||
message: expectedMessage,
|
||||
}) {
|
||||
const results = [`- **Version:** ${expectedVersion}`];
|
||||
if (expectedTag) {
|
||||
results.push(`- **Tag:** ${expectedTag}`);
|
||||
|
@ -107,10 +112,18 @@ function generateExpectationText({ version: expectedVersion, tag: expectedTag, b
|
|||
if (expectedBranch) {
|
||||
results.push(`- **Branch:** ${expectedBranch}`);
|
||||
}
|
||||
if (expectedMessage) {
|
||||
results.push(`- **Message:** ${expectedMessage}`);
|
||||
}
|
||||
return results.join('\n');
|
||||
}
|
||||
|
||||
async function assertExpectation({ version: expectedVersion, tag: expectedTag, branch: expectedBranch }) {
|
||||
async function assertExpectation({
|
||||
version: expectedVersion,
|
||||
tag: expectedTag,
|
||||
branch: expectedBranch,
|
||||
message: expectedMessage,
|
||||
}) {
|
||||
if (expectedTag === undefined) {
|
||||
expectedTag = expectedVersion;
|
||||
}
|
||||
|
@ -119,9 +132,17 @@ async function assertExpectation({ version: expectedVersion, tag: expectedTag, b
|
|||
await git('checkout', expectedBranch);
|
||||
}
|
||||
await git('pull');
|
||||
const [packageVersion, latestTag] = await Promise.all([getPackageJsonVersion(), getLatestTag()]);
|
||||
const [packageVersion, latestTag, latestMessage] = await Promise.all([
|
||||
getPackageJsonVersion(),
|
||||
getLatestTag(),
|
||||
getLatestCommitMessage(),
|
||||
]);
|
||||
if (!expectedMessage) {
|
||||
expectedMessage = latestMessage;
|
||||
}
|
||||
expect(packageVersion).toBe(expectedVersion);
|
||||
expect(latestTag).toBe(expectedTag);
|
||||
expect(latestMessage).toBe(expectedMessage);
|
||||
if (expectedBranch) {
|
||||
await git('checkout', 'main');
|
||||
}
|
||||
|
@ -138,3 +159,8 @@ async function getLatestTag() {
|
|||
const result = await git({ suppressOutput: true }, 'describe', '--tags', '--abbrev=0');
|
||||
return result.stdout;
|
||||
}
|
||||
|
||||
async function getLatestCommitMessage() {
|
||||
const result = await git({ suppressOutput: true }, 'show', '--no-patch', '--format=%s');
|
||||
return result.stdout;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue