mirror of
https://github.com/pre-commit/action.git
synced 2025-11-07 10:46:56 +00:00
Merge pull request #15 from deepyaman/patch-1
Support `extra_args` keyword in pre-commit GitHub action
This commit is contained in:
commit
b1bfac3edf
3 changed files with 28 additions and 7 deletions
14
README.md
14
README.md
|
|
@ -41,6 +41,20 @@ This does a few things:
|
||||||
|
|
||||||
Hopefully in the future when `actions` matures the yaml can be simplified.
|
Hopefully in the future when `actions` matures the yaml can be simplified.
|
||||||
|
|
||||||
|
### using this action with custom invocations
|
||||||
|
|
||||||
|
By default, this action runs all the hooks against all the files. `extra_args`
|
||||||
|
lets users specify a single hook id and/or options to pass to `pre-commit run`.
|
||||||
|
|
||||||
|
Here's a sample step configuration that only runs the `flake8` hook against all
|
||||||
|
the files (use the template above except for the `pre-commit` action):
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: pre-commit/action@v1.0.1
|
||||||
|
with:
|
||||||
|
extra_args: flake8 --all-files
|
||||||
|
```
|
||||||
|
|
||||||
### using this action in private repositories
|
### using this action in private repositories
|
||||||
|
|
||||||
this action also provides an additional behaviour when used in private
|
this action also provides an additional behaviour when used in private
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
name: pre-commit
|
name: pre-commit
|
||||||
description: run pre-commit and optionally commit back to the pull request
|
description: run pre-commit and optionally commit back to the pull request
|
||||||
inputs:
|
inputs:
|
||||||
|
extra_args:
|
||||||
|
description: options to pass to pre-commit run
|
||||||
|
required: false
|
||||||
|
default: '--all-files'
|
||||||
token:
|
token:
|
||||||
description: github token to clone / push with
|
description: github token to clone / push with
|
||||||
required: false
|
required: false
|
||||||
|
|
|
||||||
17
index.js
17
index.js
|
|
@ -1,13 +1,10 @@
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
const exec = require('@actions/exec');
|
const exec = require('@actions/exec');
|
||||||
const github = require('@actions/github');
|
const github = require('@actions/github');
|
||||||
|
const tr = require('@actions/exec/lib/toolrunner');
|
||||||
const ARGS = [
|
|
||||||
'run', '--all-files', '--show-diff-on-failure', '--color=always'
|
|
||||||
];
|
|
||||||
|
|
||||||
function addToken(url, token) {
|
function addToken(url, token) {
|
||||||
return url.replace(/^https:\/\//, `https://x-access-token:${token}@`)
|
return url.replace(/^https:\/\//, `https://x-access-token:${token}@`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
@ -16,15 +13,21 @@ async function main() {
|
||||||
await exec.exec('pip', ['freeze', '--local']);
|
await exec.exec('pip', ['freeze', '--local']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const args = [
|
||||||
|
'run',
|
||||||
|
'--show-diff-on-failure',
|
||||||
|
'--color=always',
|
||||||
|
...tr.argStringToArray(core.getInput('extra_args')),
|
||||||
|
];
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
const pr = github.context.payload.pull_request;
|
const pr = github.context.payload.pull_request;
|
||||||
const push = !!token && !!pr;
|
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) {
|
if (ret && push) {
|
||||||
// actions do not run on pushes made by actions.
|
// actions do not run on pushes made by actions.
|
||||||
// need to make absolute sure things are good before pushing
|
// need to make absolute sure things are good before pushing
|
||||||
// TODO: is there a better way around this limitation?
|
// 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(
|
const diff = await exec.exec(
|
||||||
'git', ['diff', '--quiet'], {ignoreReturnCode: true}
|
'git', ['diff', '--quiet'], {ignoreReturnCode: true}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue