diff --git a/README.md b/README.md index 4460fc6..0dcc663 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,8 @@ Determine the behavior for none existing properties or array elements. | targetBranch | Opens a PR from __branch__ to __targetBranch__ if createPR is set to 'true' | `master` | | repository | The Repository where the YAML file is located and should be updated. You have to checkout this repository too and set the working-directory for this action to the same as the repository. See the example below | ${{github.repository}} | | branch | The updated YAML file will be committed to this branch, branch will be created if not exists | `master` | +| force | Allows force pushes | `false` | +| masterBranchName | Branch name of your master branch | `master` | | masterBranchName | Branch name of your master branch | `master` | | githubAPI | BaseURL for all GitHub REST API requests | https://api.github.com | | token | GitHub API Token which is used to create the PR, have to have right permissions for the selected repository | ${{github.token}} | diff --git a/action.yml b/action.yml index 0c06d37..1299d72 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,10 @@ inputs: required: false description: 'Branch to commit the change, will be created if not exist' default: 'master' + force: + required: false + description: 'Branch to commit the change, will be created if not exist' + default: 'false' masterBranchName: required: false description: 'Branch name of your master' diff --git a/src/action.ts b/src/action.ts index 2bacab4..134dc42 100644 --- a/src/action.ts +++ b/src/action.ts @@ -36,7 +36,7 @@ export async function run(options: Options, actions: Actions): Promise { const octokit = new Octokit({auth: options.token, baseUrl: options.githubAPI}) - await gitProcessing(options.repository, options.branch, options.masterBranchName, files, options.message, octokit, actions, options.committer) + await gitProcessing(options.repository, options.branch, options.force, options.masterBranchName, files, options.message, octokit, actions, options.committer) if (options.createPR) { await createPullRequest( @@ -119,6 +119,7 @@ export function writeTo(content: string, filePath: string, actions: Actions): vo export async function gitProcessing( repository: string, branch: string, + force: boolean, masterBranchName: string, files: ChangedFile[], commitMessage: string, @@ -148,7 +149,7 @@ export async function gitProcessing( actions.debug(JSON.stringify({createdCommit: newCommitSha})) actions.setOutput('commit', newCommitSha) - await updateBranch(octokit, owner, repo, branch, newCommitSha, actions) + await updateBranch(octokit, owner, repo, branch, force, newCommitSha, actions) actions.debug(`Complete`) } diff --git a/src/git-commands.ts b/src/git-commands.ts index 3970135..0cc7b54 100644 --- a/src/git-commands.ts +++ b/src/git-commands.ts @@ -123,6 +123,7 @@ export const updateBranch = async ( owner: string, repo: string, branch: string, + force: boolean, commitSha: string, actions: Actions ): Promise => { @@ -131,7 +132,8 @@ export const updateBranch = async ( owner, repo, ref: `heads/${branch}`, - sha: commitSha + sha: commitSha, + force: force }) } catch (error) { actions.info(`update branch ${branch} failed (${error}), fallback to create branch`) diff --git a/src/options.ts b/src/options.ts index 1d8027b..e480de8 100644 --- a/src/options.ts +++ b/src/options.ts @@ -11,6 +11,7 @@ export interface Options { commitChange: boolean updateFile: boolean branch: string + force: boolean masterBranchName: string message: string title: string @@ -49,6 +50,10 @@ export class GitHubOptions implements Options { return getInput('branch') } + get force(): boolean { + return core.getBooleanInput('force') + } + get commitChange(): boolean { return getBooleanInput('commitChange') }