Skip to content

Commit 77ba6e8

Browse files
authored
Merge pull request #36 from michmich112/bf/#35
Bug Fix Pull Request trigger
2 parents 33adb5a + 5be496c commit 77ba6e8

File tree

7 files changed

+77
-18
lines changed

7 files changed

+77
-18
lines changed

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Release Action
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- dist/**
9+
- src/**
10+
- node_modules/**
11+
- package-lock.json
12+
- package.json
13+
workflow_dispatch:
14+
15+
jobs:
16+
bump_and_release:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
- name: Setup Node
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: '12'
25+
- name: Bump & Tag
26+
uses: michmich112/version-bumper@master
27+
with:
28+
scheme: org_semantic
29+
version-file: ./package.json
30+
files: "[]"
31+
rules: '[{"trigger": "commit", "bump": "build", "branch": "master", "tag": true},{"trigger": "manual", "bump": "minor", "reset": "build", "branch": "master", "tag": true} ]'
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
34+

dist/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const gh_action_stats_1 = __importDefault(require("gh-action-stats"));
4444
const options_1 = require("./utils/options");
4545
const readline = __importStar(require("readline"));
4646
const gitUtils_1 = require("./utils/gitUtils");
47-
const Git_1 = __importDefault(require("./lib/Git"));
4847
const SUCCESS = 0, FAILURE = 1;
4948
function main() {
5049
return __awaiter(this, void 0, void 0, function* () {
@@ -59,8 +58,6 @@ function main() {
5958
core.info('No bump rules applicable');
6059
return SUCCESS;
6160
}
62-
yield new Git_1.default().checkoutBranch(state.branch);
63-
yield bump(state);
6461
const GIT_OPTIONS = {
6562
userName: 'version-bumper',
6663
userEmail: '[email protected]',
@@ -69,12 +66,16 @@ function main() {
6966
token: core.getInput('github-token'),
7067
branch: state.branch
7168
};
69+
const git = yield (0, gitUtils_1.configureGit)(GIT_OPTIONS);
70+
yield (yield git.fetchRemoteBranch(state.branch)).checkoutBranch(state.branch);
71+
yield bump(state);
7272
yield (0, gitUtils_1.commitAndPush)(GIT_OPTIONS);
7373
return SUCCESS;
7474
}
7575
catch (e) {
7676
core.error(e.message);
77-
return FAILURE;
77+
core.setFailed(`Error: ${e.message}, Validate options file or create an issue if this persists`);
78+
throw e;
7879
}
7980
});
8081
}

dist/lib/Git.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ class Git {
6060
return this;
6161
});
6262
}
63+
/**
64+
* Fetch branch from remote
65+
* @param {string} branch: Branch name to fetch
66+
* @returns {Promise<Git>}
67+
*/
68+
fetchRemoteBranch(branch) {
69+
return __awaiter(this, void 0, void 0, function* () {
70+
yield (0, exec_1.exec)('git', ['fetch', this.remoteName, branch], this.execOptions);
71+
return this;
72+
});
73+
}
6374
/**
6475
* Stage all new modifications
6576
* @returns {Promise<Git>}

dist/utils/gitUtils.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function configureGit(gitOptions, remoteName = 'github', gitInterface) {
5050
listeners: {
5151
stdline: core.debug,
5252
stderr: (data) => {
53-
core.warning(data.toString());
53+
core.debug(data.toString());
5454
},
5555
debug: core.debug,
5656
},
@@ -78,7 +78,7 @@ function commit(commitOptions, gitInterface) {
7878
listeners: {
7979
stdline: core.debug,
8080
stderr: (data) => {
81-
core.error(data.toString());
81+
core.debug(data.toString());
8282
},
8383
debug: core.debug,
8484
},
@@ -102,8 +102,7 @@ exports.commit = commit;
102102
*/
103103
function commitAndPush(options) {
104104
return __awaiter(this, void 0, void 0, function* () {
105-
let git = yield configureGit(options);
106-
yield commit(options, git);
105+
const git = yield commit(options);
107106
yield git.pushBranch(options.branch);
108107
});
109108
}

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getBumperOptions, getBumperState } from "./utils/options";
66
import BumperOptionsFile, { VersionFile } from "./lib/types/OptionsFile.types";
77
import BumperState from "./lib/types/BumperState.type";
88
import * as readline from "readline";
9-
import { commitAndPush } from "./utils/gitUtils";
9+
import { commitAndPush, configureGit } from "./utils/gitUtils";
1010
import { CommitOptions } from "./lib/types/Git.types";
1111
import Git from './lib/Git';
1212

@@ -30,8 +30,6 @@ async function main() {
3030
core.info('No bump rules applicable');
3131
return SUCCESS;
3232
}
33-
await new Git().checkoutBranch(state.branch);
34-
await bump(state);
3533

3634
const GIT_OPTIONS: CommitOptions = {
3735
userName: 'version-bumper',
@@ -42,12 +40,18 @@ async function main() {
4240
branch: state.branch
4341
};
4442

43+
const git = await configureGit(GIT_OPTIONS);
44+
await (await git.fetchRemoteBranch(state.branch)).checkoutBranch(state.branch);
45+
await bump(state);
46+
47+
4548
await commitAndPush(GIT_OPTIONS);
4649

4750
return SUCCESS;
4851
} catch (e: any) {
4952
core.error(e.message);
50-
return FAILURE;
53+
core.setFailed(`Error: ${e.message}, Validate options file or create an issue if this persists`);
54+
throw e;
5155
}
5256
}
5357

src/lib/Git.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ export default class Git {
5050
return this;
5151
}
5252

53+
54+
/**
55+
* Fetch branch from remote
56+
* @param {string} branch: Branch name to fetch
57+
* @returns {Promise<Git>}
58+
*/
59+
async fetchRemoteBranch(branch: string): Promise<Git> {
60+
await exec('git', ['fetch', this.remoteName, branch], this.execOptions);
61+
return this;
62+
}
63+
5364
/**
5465
* Stage all new modifications
5566
* @returns {Promise<Git>}

src/utils/gitUtils.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import Git from '../lib/Git';
1010
* @returns {Promise<Git>}
1111
*/
1212
export async function configureGit(gitOptions: CommitOptions,
13-
remoteName: string = 'github',
14-
gitInterface?: Git): Promise<Git> {
13+
remoteName: string = 'github',
14+
gitInterface?: Git): Promise<Git> {
1515
const { GITHUB_ACTOR, GITHUB_REPOSITORY } = process.env;
1616
const ORIGIN = `https://${GITHUB_ACTOR}:${gitOptions.token}@github.com/${GITHUB_REPOSITORY}.git`;
1717
const EXEC_OPTIONS = {
1818
cwd: process.env.GITHUB_WORKSPACE,
1919
listeners: {
2020
stdline: core.debug,
2121
stderr: (data: Buffer) => {
22-
core.warning(data.toString());
22+
core.debug(data.toString());
2323
},
2424
debug: core.debug,
2525
},
@@ -48,7 +48,7 @@ export async function commit(commitOptions: CommitOptions, gitInterface?: Git):
4848
listeners: {
4949
stdline: core.debug,
5050
stderr: (data: Buffer) => {
51-
core.error(data.toString());
51+
core.debug(data.toString());
5252
},
5353
debug: core.debug,
5454
},
@@ -74,7 +74,6 @@ export async function commit(commitOptions: CommitOptions, gitInterface?: Git):
7474
* @returns {Promise<void>}
7575
*/
7676
export async function commitAndPush(options: CommitOptions): Promise<void> {
77-
let git = await configureGit(options);
78-
await commit(options, git);
77+
const git = await commit(options);
7978
await git.pushBranch(options.branch);
8079
}

0 commit comments

Comments
 (0)