Skip to content

Commit

Permalink
Introduce sha action input
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebettridge authored and peterjgrainger committed Dec 22, 2021
1 parent 9aafd7f commit d1ae555
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ inputs:
branch:
description: 'The branch to create'
default: 'release-candidate'
sha:
description: 'The SHA1 value for the branch reference'
runs:
using: 'node12'
main: 'dist/index.js'
4 changes: 2 additions & 2 deletions src/create-branch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context } from "@actions/github/lib/context";
import { GitHub } from "@actions/github";

export async function createBranch(github: any, context: Context, branch: string) {
export async function createBranch(github: any, context: Context, branch: string, sha?: string) {
const toolkit : GitHub = new github(githubToken());
let branchExists;
// Sometimes branch might come in with refs/heads already
Expand All @@ -19,7 +19,7 @@ export async function createBranch(github: any, context: Context, branch: string
if(error.name === 'HttpError' && error.status === 404) {
await toolkit.git.createRef({
ref: `refs/heads/${branch}`,
sha: context.sha,
sha: sha || context.sha,
...context.repo
})
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { createBranch } from './create-branch';
async function run() {
try {
const branch = core.getInput('branch');
const sha = core.getInput('sha');
core.debug(`Creating branch ${branch}`);
await createBranch(GitHub, context, branch)
await createBranch(GitHub, context, branch, sha)
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit d1ae555

Please sign in to comment.