'Can I use a GitHub Action to patch pull requests before running validating actions?

When a collaborator creates/updates a pull request against my repository's default branch I want two things to happen in a specific order:

  1. Automatic code formatting + commit formatting changes to the PR branch
  2. Run code quality tests and unit tests

If tests complete without errors the default branch's branch protection rules should allow merging.

The problem is that when step 1 completes, the current workflows are now invalid since there is a new commit on the PR branch. Because of this, the results of the tests can not validate the PR, rendering the PR impossible to merge.

Step no. 1 does not trigger another round of Actions since it was committed and pushed by an Action itself and that behavior would just create an endless loop of Actions anyways.

What I want is a way to run step no. 1 automatically before anything else happens so that simple warnings get squashed without developers having to do anything manually.

I am trying to avoid doing this through pre-commit hooks since that would require developers to manually set up their environments the same way.

How can I create the flow I am describing by using GitHub Actions?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source