Reputation: 320
For my projects PR process I want to add a code format check. I am using a github marketplace linter, Black (https://github.com/marketplace/actions/black-code-formatter) to do this. I have this working from the code example, but it runs for all files in the repo, instead of just the modified files in the PR. Is there any way to change this?
I've run the example from the market place page in my main.workflow
file and it works as expected
I think the issues has to do with the black call, right now it is:
args = ". --check --fast"
and this checks every file. I am not sure how to change this to only check formatting of modified files from the PR.
Upvotes: 2
Views: 3163
Reputation: 76884
I don't think you can do what you want with that particular action. In order to pass an argument to an action, you need to use either a literal or a context expression. However, to find the list of files, you'd need to use a shell pipeline, and it isn't possible to invoke the shell in a context expression.
If you wanted to add Black as a development dependency to your project, you could use the environment variables GITHUB_SHA
and GITHUB_BASE_REF
as described in the documentation and then run something like the following to invoke it:
git diff --name-only "$GITHUB_BASE_REF..$GITHUB_SHA" | xargs black --check --fast
That assumes that the application is named black
and that it can take an arbitrary number of files to check on the command line; you may need to adjust it if that's not the case. That command will exit nonzero if the check fails, and zero if every black
invocation exited successfully.
Upvotes: 4