Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Pilot Lvl 1
Message 1 of 3

Autofix workflow on a pull request invalidates previous check state without triggering new checks

Solved! Go to Solution.

I've got a workflow that runs on pull requests, to autofix formatting issues with `prettier`, and then commits + pushes the fixes (if any) back up to the pull-requesting branch.

Essentially:

yarn prettier

git commit -am "Committing autofixes"

ORIGIN=https://${GITHUB_ACTION}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git

echo "Pushing to repo..."
git fetch $ORIGIN ${GITHUB_HEAD_REF}
git merge FETCH_HEAD -m "Merging in remote"
git push $ORIGIN HEAD:${GITHUB_HEAD_REF}

 

This works great, but the resulting "Committing autofixes" commit doesn't appear to trigger any checks. 

Screen Shot 2019-10-04 at 2.07.18 PM.png

I guess this makes sense (to prevent actions that trigger themselves in an infinite loop), but the problem is that the pull request no longer thinks it has any checks -- even if the previous checks had failed.

 

Screen Shot 2019-10-04 at 2.15.01 PM.png

 

I'm "working around" this problem by, after autofixing happens, making an empty commit locally and pushing it up, e.g. git commit --allow-empty -m bump; git push, which triggers the checks again and brings things back to normal.

 

And then the pull-request looks like this:

 

Screen Shot 2019-10-04 at 2.08.51 PM.png

 

Has anyone else run into this before? Is there a better workflow for having an action that commits autofixes back to a pull request?

2 Replies
Pilot Lvl 1
Message 2 of 3

Re: Autofix workflow on a pull request invalidates previous check state without triggering new check

I also tried closing & reopening the pull request after the autofix (which the docs claim will trigger a pull_request workflow), but it didn't :/

Highlighted
Solution
Pilot Lvl 2
Message 3 of 3

Re: Autofix workflow on a pull request invalidates previous check state without triggering new check

Provided GITHUB_TOKEN is not allowed to trigger checks, you need to generate and use own/bot's account/any other token and it will work just fine.

 

If using bot account to do formatting, you probably don't want to waste time on formatting just-formatted code...

on: push
jobs:
 format-source:
  runs-on: ubuntu-latest
  if:      github.actor != 'my_bot_account'

...and works great to prevent infinite loop you mentioned.