generated from chrisjcox79/bump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (49 loc) · 1.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const core = require('@actions/core');
const { exec } = require('@actions/exec');
const github = require('@actions/github');
const { Toolkit } = require('actions-toolkit');
const STRATEGIES = [
'#patch',
'#minor',
'#major'
];
Toolkit.run(async tools => {
{
try {
// get context
const { pusher: { email, name }, head_commit: { message } } = github.context.payload;
// get input credentials
const inputUser = core.getInput('user');
const inputEmail = core.getInput('email');
const inputBranch = core.getInput('branch');
const unrelated = core.getInput('unrelated');
const userName = inputUser || name;
const userEmail = inputEmail || email;
const defaultStrategy = STRATEGIES.filter(strat => message.includes(strat))[0] || STRATEGIES[0];
const strategy = defaultStrategy.replace('#', '');
const commitMessage = message.replace(defaultStrategy, '');
tools.log(`Latest commit message: ${commitMessage}`);
tools.log(`Running with ${userName} ${userEmail} and bumping strategy ${strategy}`);
tools.log(`Branch is ${inputBranch}`);
// git login and pull
const pullArgs = ['pull', 'origin', inputBranch, '--tags'];
if (unrelated) {
pullArgs.push('--allow-unrelated-histories');
}
await exec('git', ['config', '--local', 'user.name', userName]);
await exec('git', ['config', '--local', 'user.email', userEmail]);
await exec('git', pullArgs);
// version by strategy
await exec('npm', ['version', strategy, '--no-commit-hooks', '-m', `${commitMessage} %s`]);
const version = tools.getPackageJSON().version;
core.info(`version is ${version}`);
// push new version and tag
await exec('git', ['push', 'origin', `HEAD:${inputBranch}`, '--tags'])
// set output version
core.setOutput('version', version);
}
catch (error) {
core.setFailed(error.message);
}
}
});