-
-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting pre-commit GH action to only run for files that have changed #7
Comments
there isn't an option currently but one might be a good idea. I'm currently trying to rehaul this without GA (due to the limitations) and that's a planned feature there a PR here would be appreciated if you want to work on such a thing note that it would have to be an option since there are cases where modifying a file can cause failures in other files (such as with mypy) and often CI is a better guard to run against all files |
got it—thanks so much! won't be able to work on a PR (as I don't know JS), but will definitely check back for updates. thanks again for all of your awesome work. |
Hi guys! I didn't see this issue, but I needed this functionality today and found a way around it. #15 is the modified I made to the action, in conjunction with https://github.com/futuratrepadeira/changed-files. See the relevant part of my - name: Changed Files Exporter
uses: futuratrepadeira/changed-files@v3.0.0
id: changed-files
with:
repo-token: ${{ github.token }}
- name: set FILES
run: |
echo "::set-env name=FILES::${{ steps.changed-files.outputs.files_created }} ${{ steps.changed-files.outputs.files_updated }} ${{ steps.changed-files.outputs.files_deleted }}"
- uses: deepyaman/action@v1.0.2 # My modified `pre-commit/action`
with:
args: --files ${{ env.FILES }}
token: ${{ secrets.GITHUB_TOKEN }} |
would |
The args get passed as expected, but the refs aren't found. I can do Running Run git branch -a0s
remotes/pull/10/merge
Run git branch -a
* (HEAD detached at pull/10/merge)
remotes/pull/10/merge Maybe you'd have to have another checkout step, but I'm not sure... |
I'm no expert on GitHub Actions (first tried it yesterday afternoon), but I'm inclined to say you can't access references/branches that naively. I did a lot of googling for finding the list of files that changed in Actions, but didn't find any straightforward
I wrote #15 because I wanted to be able to specify different args (not just changed files), and I used it to support the use case in this issue with other actions, but I agree that it would be great to make a more convenient way to run on changed files only as it's a documented common use case. |
#15 provides a way to do this |
Hey, thought I'd share another example of using this feature: jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- id: file_changes
uses: trilom/file-changes-action@v1.2.3
with:
output: ' '
- uses: pre-commit/action@v2.0.0
with:
extra_args: --files ${{ steps.file_changes.outputs.files}} |
thanks! but please note that you should now use this due to trilom/file-changes-action#81 - id: file_changes
uses: trilom/file-changes-action@v1.2.4
with:
output: 'space' # no longer ' ' |
If you want it to run for all files changed for the whole pull request (not just most recent commit) you'll want to follow this:
|
This snippet will use the base commit from the target branch (e.g. origin/main) and the latest commit of the PR. jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# requites to grab the history of the PR
fetch-depth: 0
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
with:
extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }} |
Given that https://github.com/trilom/file-changes-action seems unmaintained and is using Node 12 and uses set-output, which GitHub will be deprecating and/or disabling, new steps can be:
Or whatever your On https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ |
Hi Anthony,
Regarding https://pre-commit.com/#usage-in-continuous-integration, if i only want my action to check files which have changed, how would i incorporate the following?
pre-commit run --origin HEAD --source origin/HEAD
thanks,
Ben
The text was updated successfully, but these errors were encountered: