diff --git a/action.yml b/action.yml index 941ec1d..2c1fb50 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,12 @@ inputs: token: description: github token to clone / push with required: false + source: + description: The remote branch's commit_id when using `git push`. + required: false + origin: + description: The origin branch's commit_id when using `git push`. + required: false runs: using: 'node12' main: 'dist/index.js' diff --git a/index.js b/index.js index 64bdac2..0e1a311 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,6 @@ const core = require('@actions/core'); const exec = require('@actions/exec'); const github = require('@actions/github'); -const ARGS = [ - 'run', '--all-files', '--show-diff-on-failure', '--color=always' -]; - function addToken(url, token) { return url.replace(/^https:\/\//, `https://x-access-token:${token}@`) } @@ -17,14 +13,33 @@ async function main() { }); const token = core.getInput('token'); + const source = core.getInput('source'); + const origin = core.getInput('origin'); + + var args = [ + 'run', '--show-diff-on-failure', '--color=always' + ]; + + if (source) { + args.push('--source', source); + } + + if (origin) { + args.push('--origin', origin); + } + + if (!!source && !!origin) { + args.push('--all-files'); + } + const pr = github.context.payload.pull_request; const push = !!token && !!pr; - const ret = await exec.exec('pre-commit', ARGS, {ignoreReturnCode: push}); + const ret = await exec.exec('pre-commit', args, {ignoreReturnCode: push}); if (ret && push) { // actions do not run on pushes made by actions. // need to make absolute sure things are good before pushing // TODO: is there a better way around this limitation? - await exec.exec('pre-commit', ARGS); + await exec.exec('pre-commit', args); const diff = await exec.exec( 'git', ['diff', '--quiet'], {ignoreReturnCode: true}