Skip to content

Commit d1ae555

Browse files
lukebettridgepeterjgrainger
authored andcommitted
Introduce sha action input
1 parent 9aafd7f commit d1ae555

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ inputs:
88
branch:
99
description: 'The branch to create'
1010
default: 'release-candidate'
11+
sha:
12+
description: 'The SHA1 value for the branch reference'
1113
runs:
1214
using: 'node12'
1315
main: 'dist/index.js'

src/create-branch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Context } from "@actions/github/lib/context";
22
import { GitHub } from "@actions/github";
33

4-
export async function createBranch(github: any, context: Context, branch: string) {
4+
export async function createBranch(github: any, context: Context, branch: string, sha?: string) {
55
const toolkit : GitHub = new github(githubToken());
66
let branchExists;
77
// Sometimes branch might come in with refs/heads already
@@ -19,7 +19,7 @@ export async function createBranch(github: any, context: Context, branch: string
1919
if(error.name === 'HttpError' && error.status === 404) {
2020
await toolkit.git.createRef({
2121
ref: `refs/heads/${branch}`,
22-
sha: context.sha,
22+
sha: sha || context.sha,
2323
...context.repo
2424
})
2525
} else {

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { createBranch } from './create-branch';
55
async function run() {
66
try {
77
const branch = core.getInput('branch');
8+
const sha = core.getInput('sha');
89
core.debug(`Creating branch ${branch}`);
9-
await createBranch(GitHub, context, branch)
10+
await createBranch(GitHub, context, branch, sha)
1011
} catch (error) {
1112
core.setFailed(error.message);
1213
}

0 commit comments

Comments
 (0)