EndBug / add-and-commit

:octocat: Automatically commit changes made in your workflow run directly to your repo
MIT License
1.12k stars 115 forks source link

Status Check war reseted after Commit #586

Closed ernestoguimaraes closed 8 months ago

ernestoguimaraes commented 9 months ago

I have some Workflows that show up on Status Check during my CI. This is the Flow:

Push to my Branch - Triggers an Snapshot on:
push: branches-ignore:

Opening a PR to Main. Triggers another workflow: on: pull_request: branches: [main] types: [opened, reopened, synchronize]

The problems happens when I open the PR. I´m able to see all jobs from SNAPSHOT and the workflow that is running at the moment. During these steps, I need to make a change in one file and upload it back to the Branch, creating a Tag as information

When the workflow starts the EndBug/add-and-commit@v9 action. It commits my code as expected and does not trigger any workflow again (the Push triggers) and this is what I expect

However, when I come back to PR, I noticed that all my Status Check resets. No more Log information about it.

I tried to commit the application repo with a GitHub App token and the same behavior happened.

Have you seen this?

EndBug commented 9 months ago

This is intended behavior on GitHub's part: PR status checks always refer to the latest commit, so if you don't re-trigger CI on the automated commit it won't display any status checks

That's because otherwise an action could break your code and the status checks would still be successful

You need to either commit using a PAT, or re-trigger some the status checks you need either manually or via a workflow dispatch call to the API

ernestoguimaraes commented 9 months ago

Hey @EndBug ! thank you.

But one question:; I was testing with my friend yesterday. in the same scenario, If I ask him to Update the Branch, the status is not reset. The reset problem happens using GITHUB_TOKEN and now a GitHub App Token. The PAT is an option, however, using in a enterprise scenario, I will reach the PAT Threshold very fast.

EndBug commented 9 months ago

Maybe if you update the branch using the GitHub UI they just keep the previous result, since they "trust" the operation. I don't know exactly what the criteria is though 🙌🏻

I would suggest you allow your "test" workflows, the ones you require the status checks to be run for, to be run via workflow dispatches, then add a step using some action to send the dispatch via the GitHub API There are a few actions on the marketplace you can use for that, this is one of them: https://github.com/marketplace/actions/workflow-dispatch

ernestoguimaraes commented 9 months ago

I was making some tests here and noticed something. Before my workflow starts, my PR is attached to a commti Hash. As a need to make a Branch commit, It´s creating a new Hash. Is there a way to make a commit and preserve the original Hash? I believe it´s Fast-Foward, right?

EndBug commented 9 months ago

I don't think it's possible, because the SHA of each commit is generated by git internals by hashing different info about the commit, including the SHA of the parent. That makes it impossible to insert a commit in the history without modifying every commit down the line. Even with fast-forward merges or rebases, the SHA of every subsequent commit is re-calcultated.

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.