-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
56 lines (50 loc) · 1.92 KB
/
index.ts
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
import * as core from '@actions/core'
import { isFileExist } from './src/isFileExists.js'
import { spawnProcess } from './src/spawnProcess.js'
try {
// vars
const repository = core.getInput('repository')
const branch = core.getInput('branch')
const commitMessage = core.getInput('commit_message')
const pullArgs = core.getInput('pull_args')
const addArgs = core.getInput('add_args')
// log
console.log({
repository,
branch,
commitMessage,
pullArgs,
addArgs,
})
if (!(await isFileExist(repository))) {
throw new Error("repository directory doesn't exist: " + repository)
}
if (branch.trim() === '') {
throw new Error('branch is a required field')
}
await spawnProcess('git', ['config', '--global', 'user.name', '"github-actions[bot]"'], repository)
await spawnProcess('git', ['config', '--global', 'user.email', '"41898282+github-actions[bot]@users.noreply.github.com"'], repository)
await spawnProcess('git', ['add', ...addArgs.split(' ')], repository)
const diff = await spawnProcess('git', ['diff', '--staged', '--name-only'], repository)
if (diff.trim() === '') {
console.log('Working tree is empty. Nothing to commit.')
} else {
await spawnProcess('git', ['fetch', '--depth=1'], repository)
await spawnProcess('git', ['checkout', branch], repository)
await spawnProcess(
'git',
[
'commit',
'-m',
commitMessage,
'--author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"',
'--no-verify',
],
repository
)
await spawnProcess('git', ['pull', ...pullArgs.split(' ')], repository)
console.log(await spawnProcess('git', ['push', '--no-verify'], repository))
}
} catch (error) {
core.setFailed(error.message)
}