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

Cannot find commit when running in github without action #522

Open
IanVS opened this issue Feb 15, 2022 · 5 comments
Open

Cannot find commit when running in github without action #522

IanVS opened this issue Feb 15, 2022 · 5 comments
Labels

Comments

@IanVS
Copy link
Contributor

IanVS commented Feb 15, 2022

I need to use an npm script with a patched version of chromatic-cli to test out turbosnap support for vite, but I'm having trouble running the command without the official github action (which has been working great for us previously). I'm getting this message in my logs:

⚠ Commit turbosn does not exist
We tried to retrieve the commit details but couldn't find it in your Git history.
Check your GITHUB_HEAD_REF environment variable.
Continuing with just the commit hash.
{"shortMessage":"Command failed with exit code 1[28](https://github.com/DefinedNet/webclient/runs/5201850929?check_suite_focus=true#step:7:28): git --no-pager log -n 1 --format=\"%H ## %ct ## %ae ## %an\" turbosnap","command":"git --no-pager log -n 1 --format=\"%H ## %ct ## %ae ## %an\" turbosnap","escapedCommand":"git --no-pager log -n 1 \"--format=\\\"%H\" \"##\" \"%ct\" \"##\" \"%ae\" \"##\" \"%an\\\"\" turbosnap","exitCode":128,"stdout":"","stderr":"fatal: ambiguous argument 'turbosnap': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'","all":"fatal: ambiguous argument 'turbosnap': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'","failed":true,"timedOut":false,"isCanceled":false,"killed":false}
git info: {"commit":{"commit":"32def01[31](https://github.com/DefinedNet/webclient/runs/5201850929?check_suite_focus=true#step:7:31)220874541525167fa113cd09b6a8097","committedAt":1644936177743},"branch":"turbosnap","slug":"DefinedNet/webclient","isTravisPrBuild":false,"fromCI":true,"ciService":"github"}
App firstBuild: '{"committedAt":1619794260000}', lastBuild: '{"commit":"ce144e52ca9d2fb00945c27528b9[33](https://github.com/DefinedNet/webclient/runs/5201850929?check_suite_focus=true#step:7:33)d66bf80313","committedAt":16449[34](https://github.com/DefinedNet/webclient/runs/5201850929?check_suite_focus=true#step:7:34)929090}', pullRequest: 'null'

When I run git --no-pager log -n 1 --format="%H ## %ct ## %ae ## %an" turbosnap manually in my project, I get a good result. Is this a bug in chromatic, perhaps?

@IanVS
Copy link
Contributor Author

IanVS commented Feb 15, 2022

Hmmm, I'm seeing the same error if I try running that command manually in a separate step:

Run git --no-pager log -n 1 --format="%H ## %ct ## %ae ## %an" turbosnap
  git --no-pager log -n 1 --format="%H ## %ct ## %ae ## %an" turbosnap
  shell: /usr/bin/bash -e {0}
fatal: ambiguous argument 'turbosnap': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Error: Process completed with exit code 1[2](https://github.com/DefinedNet/webclient/runs/5202156127?check_suite_focus=true#step:6:2)8.

So, maybe the checkout isn't working quite right or something, even though I'm using fetch-depth: 0...

@IanVS
Copy link
Contributor Author

IanVS commented Feb 15, 2022

Ah, yep it looks like by default the checkout action checks out an ephemeral merge commit:

Checking out the ref
  /usr/bin/git checkout --progress --force refs/remotes/pull/503/merge
  Note: switching to 'refs/remotes/pull/503/merge'.
  
  You are in 'detached HEAD' state. You can look around, make experimental
  changes and commit them, and you can discard any commits you make in this
  state without impacting any branches by switching back to a branch.
  
  If you want to create a new branch to retain commits you create, you may
  do so (now or later) by using -c with the switch command. Example:
  
    git switch -c <new-branch-name>
  
  Or undo this operation with:
  
    git switch -
  
  Turn off this advice by setting config variable advice.detachedHead to false
  
  HEAD is now at 9642098 Merge 370418ff66084726bae4e5066ec8cb5AAAAAAAA into 57d5feb461361317093b79041e7f2a0fBBBBBBBB

If I specify a ref to my branch, it seems to work fine. See actions/checkout#124 (comment) for an example that handles pull requests and pushes.

How does the chromatic github action handle this?

@IanVS
Copy link
Contributor Author

IanVS commented Feb 15, 2022

Instead of bailing out here:

return { commit: GITHUB_SHA, committedAt: Date.now() };
, I wonder if we could instead try getting the information needed from envCi, as a fallback?

@moollaza
Copy link

Any resolution or recommendations here? Dealing with the same issue.

@IanVS
Copy link
Contributor Author

IanVS commented Mar 13, 2024

I don't have any great solutions. I ended up using patch-package to patch chromatic temporarily when I was running into this, but I've since gone back to using the github action.

@codykaup codykaup added the CLI label Nov 1, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants