-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcreate-commit.ts
More file actions
42 lines (36 loc) · 1.06 KB
/
create-commit.ts
File metadata and controls
42 lines (36 loc) · 1.06 KB
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
import { Toolkit } from 'actions-toolkit'
import readFile from './read-file'
export default async function createCommit(tools: Toolkit, commitMessage?: string) {
const { main } = tools.getPackageJSON<{ main?: string }>()
if (!main) {
throw new Error('Property "main" does not exist in your `package.json`.')
}
tools.log.info('Creating tree')
const tree = await tools.github.git.createTree({
...tools.context.repo,
tree: [
{
path: 'action.yml',
mode: '100644',
type: 'blob',
content: await readFile(tools.workspace, 'action.yml')
},
{
path: main,
mode: '100644',
type: 'blob',
content: await readFile(tools.workspace, main)
}
]
})
tools.log.complete('Tree created')
tools.log.info('Creating commit')
const commit = await tools.github.git.createCommit({
...tools.context.repo,
message: commitMessage || 'Automatic compilation',
tree: tree.data.sha,
parents: [tools.context.sha]
})
tools.log.complete('Commit created')
return commit.data
}