I am in the process of migrating from the vercel github integration to the vercel CLI + github actions for build and deployment of preview branches.
I am running into an issue where the CI-created deployments do not get the right branch or commit name, and therefore to not get a branch-specific URL.
Here’s what my deployments look like with the integration:
I tried adding --git-branch=${{ github.head_ref }} to my vercel pull command, but that didn’t help either. It feels like there’s some env variable or argument that the vercel github integration is using that I’m missing.
Would appreciate any help or advice on this! Let me know if more context is needed.
Hey! Glad that thread was at least adjacent to things other people want to do!
Looking at my deploys from my github workflows, I do seem to have the branch correctly attached to the deployment:
Though looking through my workflow, I’m not quite sure how Vercel is getting that information. Maybe it grabs it from the git environment somehow during vercel build or vercel publish? How does your workflow check-out the code? I’m using the latest version of actions/checkout to do it. Possibly if you’re manually running git checkout commands, it thinks you’re on a specific commit rather than a whole branch?
Its worth noting that I use Graphite, so most of the updates to my PRs are coming as rebases. I don’t see why that would pose a problem as its all still within the same branch…
What’s the top level on directive look like? If it’s set up to run on individual commits rather than on pushes to branches, I’m wondering if github actions populates the environment differently.
Ah so it’s a pull request, I have the workflow for it but haven’t tested it out. In bitbucket/gitlab I think that the ref gets set to the PR number, assumed it was the same for github but guess it’s just the commit tag unfortunately. I’m not seeing any options in the deploy command documentation for manually setting the branch name. If someone more familiar with vercel command line can chime in and mention what deploy uses to get the source data, could try mocking that to return github.head_ref possibly?
Hm, I didn’t even realize there was a difference in trigger conditions in your example. That seems to be the reason. If there’s not an easy fix (but I hope there is!) I probably can switch my trigger from pull-request to push in order to fix this.
Somehow vercel correctly learned that there was a branch attached to this deployment, but it did not create the branch-specific URL, which is what my goal is. @omn1coreprocessing-g - does your version of this create the branch-specific URL?
Still something missing here about how Vercel does this. Would love to here from them on the right way to accomplish this and get the same behavior as the integration.