-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Detached HEAD State #6
Comments
in Actions v1, i think you only get a tar ball of your git repository, you can't run git operations on it. |
@TingluoHuang, actions v1 definitely checked out the repository to a branch, complete with all git metadata. LaunchDarkly's GH action was built around running git operations on the checked out repo. We are now implementing a workaround for this detached head issue (e.g. reading branch name from @peter-evans, an extremely hacky workaround that could be used short term to get the repo into a non-detached state would be to add this step after the - name: Prepare repository
run: git checkout "${GITHUB_REF:11}" I'm not sure what happens if there have been more commits since the workflow was triggered, it depends on how |
@vlymar can you share some context around how you use the checkout repo in actions v1? are you making a commit and push back to origin? if we want to make actions v2 has the same behavior as actions v1, I guess we need to checkout the branch and reset HEAD to SHA. @chrispat to decide which direction to go. :) |
Our action scans the repository for feature flags and posts the results back to launchdarkly. It's triggered by We were aware of |
To add some context from my use case. I wrote an experimental action that creates a pull request for any changes to the actions workspace. I realise it's not good practice in general to modify a repository during a workflow, but it opens up some interesting possibilities when used carefully. I managed to work around the changes that were made between v1 and v2 Actions:
|
This is actually relevant for us too, thanks for posting! For context, we use |
I'm also in the same boat and would love to be able to checkout without being put into a detached head state. I currently have to resort to sed, which isn't as terse as the bash substring extraction solution by @vlymar. - name: Reattach HEAD
run: git checkout "$(echo ${{ github.ref }} | sed -E 's|refs/[a-zA-Z]+/||')" A true/false option would be nice and would preserve both behaviors. |
I have a fix that almost ready, will finish testing and release to GitHub Actions. |
Meanwhile, here's an action that works around the current detached head state, using a sh one-liner to parse https://github.com/elstudio/actions-js-build/tree/v2/commit It also sets up git to commit with the appropriate username and email address. |
Any updates? |
We are having the same issue since moving to new Actions and using checkout. Our use case is some python scripts that get executed and generate files, then push them back into the repo on the same branch/PR. I tried using the fixes above and the GH event data isn't consistent so I can't reliably get the Branch name from it. ie sometimes "github.ref": "refs/pull/575/merge" as an example. Which doesn't work. In those cases head_ref is populated, however if the ref is like above, head_ref is empty. Either way there is no reliable way to get a branch name it seems. Why can't we just have the checkout action clone the current branch? |
Learnt a different way to set the git remote that allows the default |
Is there a workaround? Running semantic-release in GitHub Actions fails at |
@hashim-sohail I tried the workaround mentioned above using
But semantic-release still does not recognize that it's running on the master branch: https://github.com/gr2m/create-or-update-pull-request-action/runs/240930167#step:7:33. It might be a problem with semantic-release/git though, the checkout seems to have worked:
https://github.com/gr2m/create-or-update-pull-request-action/runs/240930167#step:4:14 |
Yes checkout is working fine, it was an issue with the conflicting version of @semantic-release/git. |
Are there any news on this ? I am trying the workarounds above and I am observing the detached head behavior when running actions on PR. We run as service called chromatic which relies on the branch name to display which builds corresponds to which PR and HEAD is the current output everywhere. |
I could solve the problem adding a |
Hey @stefanzweifel, thanks for the reply. I am new to this so not super familiar with the way you define actions. I currently only have a |
@hashim-sohail for semantic-release, it was a problem with the |
@TingluoHuang What's the status on this? |
@chingc my change get on hold until we change this action to a javascript action which might take some time. |
I was unable to use Gitversion until I backrevved to checkout v1, so this affected me too. |
This is what we did for a workaround: steps:
- uses: actions/checkout@master
- name: reattach HEAD to Head Ref
run: git checkout "$(echo ${{ github.head_ref }} | sed -E 's|refs/[a-zA-Z]+/||')"
if: github.head_ref != ''
- name: reattach HEAD to Ref
run: git checkout "$(echo ${{ github.ref }} | sed -E 's|refs/[a-zA-Z]+/||')"
if: github.head_ref == '' This way we can put ourselves back to the right place after the initial clone action. We've been running this for about a month now with no issues. |
- name: Prepare repository
run: git checkout "${GITHUB_REF:11}" did the trick for us and got https://github.com/narative/gatsby-theme-novela/issues/185 fixed |
@jpvalery Thanks, whats the :11 part for though? |
No freaking clue - just used the suggestion in #6 (comment) and it worked 😄 |
Just wanted to feedback that v2-beta checks out the branch and works fine for me. Thanks! |
Interesting, I've just tried
anyone else? |
Could you show a |
note, prs and tags will still be detached head (they arent branches) |
* ✨ generate a hello world project from cookie cutter template on disk. related to #37 * 💚 make ci pass * 🔥 drop python 2 support and test * 💄 pump up the version * 💚 adapting moban v0.7.0. moremoban/moban#362 * 🔥 remove pypy3 because it is based on python 3.5.3 * 🔥 replace nose with pytest * 💚 pytest requires the package to be installed by default * 🔬 test cookie cutter, hello world project generation. #37 * ✨ auto-genenerate yehua file from cookie cutter json. #37 * ✨ first ever pass on cookiecutter-pypackage. yes, this code now can generate a cookiecutter package from cookiecutter-pypackage offline. steps: 1) git clone cookiecutter-pypackage 2) yh -c cookiecutter-pypackage 3) answer the quesetions 4) you will have what you wanted. #37 * 💚 fix unwanted yaml dependency * ✨ yes we need to use cookiecutter.extension.* * ✨ use moban update in github action * 🔨 problem solved * 🔨 use python 3.7 * 🔨 commit to feature branch * 📚 test moban update * 📚 commit changes * 📚 use default github token * 📚 how could I about this without documentationgit add .github/workflows/moban-update.yml ad-m/github-push-action#38 * 📚 tweek it work? * 📚 fix detached state. actions/checkout#6 * 📚 cannot i simply push * 📚 use auto commit * 📚 use checkout v2 * 📚 use checkout v2 * This is an auto-commit * 📚 test if auto commit would commit nothing or not * 📚 test if auto commit would commit something * 📚 test if auto commit would commit something * This is an auto-commit * ✨ add colon * This is an auto-commit * ✨ need if statement * ✨ need if statement * This is an auto-commit * ✨ generate directly from a git repo. #37 * 🔥 remove unused imports * 🔥 remove useless codes * ✨ first working POC. yh -c cookiecutter-pypackage #37 * 💚 pass all unit tests * 🔥 remove unused imports * 💚 fix coding style * ✨ minor tweak to support git url. python filesytem did the magic! #37 * 💚 test cookiecutter package as git repo * 💚 add gitfs2 as test requirements * This is an auto-commit * 💚 add gitfs2 as test requirements * This is an auto-commit * ✨ seemless integration with cookiecutter. simply replace cookiecutter with yh. the rest will follow. #37 * This is an auto-commit * 🔨 code refactoring * 🔨 code refactoring * This is an auto-commit * 🔥 remove unused imports Co-authored-by: chfw <chfw@users.noreply.github.com>
The work around for this problem is to do the following: steps:
- uses: actions/checkout@v2
- run: git switch -c "pull-request" This creates a new branch called This assumes that you are not going to push! |
What do you think of actually setting |
The detached state (actions/checkout#6) makes semantic-release triggering a release even from a PR
The detached state (actions/checkout#6) makes semantic-release triggering a release even from a PR
no way to make it works simply (i'm not alone actions/checkout#6)
When using this action it leaves the repository in a "detached HEAD" state. Is there a way to checkout the branch that initiated the workflow in an attached, usable state?
The checkout for Actions v1 using the HCL workflows worked differently and didn't leave the repository in a "detached HEAD" state.
The text was updated successfully, but these errors were encountered: