Skip to content
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

Checkout action with branch as ref not consistent through workflow #1634

Closed
Martiix opened this issue Mar 1, 2024 · 3 comments · May be fixed by #1858
Closed

Checkout action with branch as ref not consistent through workflow #1634

Martiix opened this issue Mar 1, 2024 · 3 comments · May be fixed by #1858

Comments

@Martiix
Copy link

Martiix commented Mar 1, 2024

I recently moved my github actions workflow to trigger on pull_request which has a different checkout behavior than on push. Then to ensure that the git repo was consistent both on push and on pr, I used the checkout action to check out the current branch.

My main issue with the default checkout on pr was that running git commands doesn't give expected output for instance git branch and git show -s --format=%B.

The issue that now occurs is that a workflow starts running on the main branch with one commit, but during the workflow, something else is merged to that branch and the next job then checks out the latest commit instead of the commit it started running with. I tried checkout out the current commit throughout the workflow instead. In python in the workflow a: return Repo(repo_root_path).active_branch.name works on push events, but in prs, results in: HEAD is a detached symbolic reference as it points to SHA. Also with ref: ${{ github.event.pull_request.head.sha }}, but works with ref: current_branch_name

Is there a way to check out a branch at a given commit consistently through a workflow both on push and on pr, for instance:

- name: Check out code
              uses: actions/checkout@v4
              with:
                  ref: branch/commit

or any other way to check out the same commit throughout a workflow while also having access to the git information?
uaing fetch-depth:0 makes no difference.

@testersen
Copy link

testersen commented Aug 20, 2024

I also have the same problem.

When not specifying a ref, the checkout action will use the ${{ github.ref }} and ${{ github.sha }} properties automatically. But there is currently no way to 'manually' specify both a commit and a ref into the checkout action. relevant code

I will open a pull request for this.

@testersen
Copy link

testersen commented Aug 20, 2024

I didn't actually fully read through your issue. Sorry!

The behavior of the pull request synchronization is that it fetches the pull/<number>/merge ref, which for some can be problematic because the latest commit will be a merge commit. Alternatively it will be possible to pull down the pull/<number>/head branch to only get the contents of that branch.

The problem I had is that I have jobs that can span between minutes, and between the first job run and the last, if a new commit is added to the pull/<number>/head branch, then that new commit will be included in later jobs for a workflow that was meant for a specific commit of a pull request.

Either way - #1858 should solve this issue.

@Martiix
Copy link
Author

Martiix commented Aug 21, 2024

I have both problems, where either can be the solution, thank you very much :)

@Martiix Martiix closed this as completed Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants