-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.ts
57 lines (47 loc) · 1.51 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
57
import * as core from "@actions/core";
import getInput from "./lib/input";
import { Repo } from "./lib/repo";
import { Ref } from "./lib/ref";
import { getBlobsFromFiles } from "./lib/blob";
import { Tree } from "./lib/tree";
import { Commit } from "./lib/commit";
export default async function run(): Promise<void> {
try {
// Get repo
const repo = new Repo(process.env.GITHUB_REPOSITORY);
await repo.load();
// Get inputs
const files = getInput("files");
const baseDir = getInput("workspace", {
default: process.env.GITHUB_WORKSPACE,
});
const commitMessage = getInput("commit-message");
// Load ref details
const ref = new Ref(
repo,
getInput("ref", { default: repo.defaultBranchRef })
);
await ref.load();
// Expand files to an array of "blobs", which will be created on GitHub via the create blob API
const blobs = getBlobsFromFiles(repo, files, { baseDir });
core.debug(
`Received ${blobs.length} blob${
blobs.length === 1 ? "" : "s"
}: ${blobs.map((blob) => blob.absoluteFilePath).join(", ")}`
);
// Create a tree
const tree: Tree = new Tree(repo, blobs, ref.treeOid);
// Create commit
const commit: Commit = new Commit(repo, tree, commitMessage, [
ref.commitOid,
]);
await commit.save();
// Set commit sha output
core.setOutput("commit-sha", commit.sha);
// Update ref to point at new commit sha
await ref.update(commit.sha);
} catch (e) {
core.setFailed(e);
}
}
run();