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

Open
Martiix opened this issue Mar 1, 2024 · 0 comments
Open

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

Martiix opened this issue Mar 1, 2024 · 0 comments

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.

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

No branches or pull requests

1 participant