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

Branch name being assigned refs/heads instead of just the branch name #137

Open
Jonashr opened this issue Mar 22, 2022 · 2 comments
Open
Assignees

Comments

@Jonashr
Copy link

Jonashr commented Mar 22, 2022

Hi, I have been having problems with branch names on deployments.

Let's say I am on the branch hello-world. Git project name is project and teamname is myteam and I am deploying to vercel using this github-action.

This will cause three domains to deploy on vercel:
project-git-1234uniqueid-myteam.vercel.app
project-git-hello-world-myteam.vercel.app
project-git-refs-headshello-world-myteam.vercel.app

Under Branch in Vercel the branch name is now specified as refs/heads/hello-world

if I Disable Vercel for GitHub by setting the flag to true:

{ "github": { "enabled": true } }

The branch is now set to hello-world without the refs/heads part and only the unique url and the branch url domain is set.

github-actions

For reference this is how my vercel-action part looks like for me;

  - name: Deploy to Vercel
    uses: amondnet/vercel-action@v20
    with:
      vercel-token: ${{ secrets.VERCEL_TOKEN }}
      vercel-org-id: ${{ secrets.ORG_ID }}
      vercel-project-id: ${{ secrets.PROJECT_ID }}
      alias-domains: project-git-{{ BRANCH }}-myteam.vercel.app
      scope: ${{ secrets.ORG_ID }}

Did I make any mistake or is there maybe a way to fix this ? This is causing problems with authentication as it relies on branch url not having the refs/heads part.

@amondnet amondnet self-assigned this Apr 7, 2022
@amondnet
Copy link
Owner

amondnet commented Apr 7, 2022

if I Disable Vercel for GitHub by setting the flag to true:
{ "github": { "enabled": true } }

-> { "github": { "enabled": false } }
https://github.com/amondnet/vercel-action#disable-vercel-for-github
https://github.com/amondnet/vercel-action#skip-vercels-build-step

Because vercel built your code, not github actions. Vercel deploys a static file so it can't take more than 1 minute.
스크린샷 2022-03-10 오전 10 53 22

#122 (comment)

@Jonashr
Copy link
Author

Jonashr commented Apr 8, 2022

if I Disable Vercel for GitHub by setting the flag to true:
{ "github": { "enabled": true } }

-> { "github": { "enabled": false } } https://github.com/amondnet/vercel-action#disable-vercel-for-github https://github.com/amondnet/vercel-action#skip-vercels-build-step

Because vercel built your code, not github actions. Vercel deploys a static file so it can't take more than 1 minute. 스크린샷 2022-03-10 오전 10 53 22

#122 (comment)

I think maybe my wording wasn't the best, so let me try explaining it in a different way.

Vercel - Without Github actions

This is how deployments look like without using Github actions. One unique URL is generated, and a branch url. Notice that the branch name on vercel here is fix/cm-section-title

So we end up with two domains if we do not use Github actions at all:

  1. project-git-1234someuniqueid-myteam.vercel.app
  2. project-git-fix-cm-section-title-myteam.vercel.app

However if we were to use this vercel-action and use the alias-domains property
alias-domains: project-{{ BRANCH }}-myteam.vercel.app

We end up with the two domains above and a third domain:
project-git-refs-headsfix-cm-section-title-myteam.vercel.app

In addition the Branch name is no longer fix/cm-section-title, it is now refs/heads/fix/cm-section-title

So using alias-domains causes the branch refs/heads/ being prefixed to the Vercel branch name. This in turn causes problems cause we do the build step, not on GitHub Actions but on Vercel..for reasons explained below

Does this make any sense ?

As you mentioned, yes we are doing the build step on Vercel and not on Github Actions. Which does seem counter intuitive, but it is not by choice.

We initially tried building using Github actions, but the build step fails cause we need access to the Vercel System Variables in the build step during build time, which I don't think we have access to if we use GitHub Actions. Sure, you can add them as secrets, but for dynamic variables it is a different situation.

We are using the next-auth library for authentication and it needs to know about the AUTH0_BASE_URL during the build step. This variable depends on you guessed it... Vercel system variables. Here is an example what it looks like:

Branch URLs (For Develop)
AUTH0_BASE_URL=${VERCEL_GIT_REPO_SLUG}-git-${VERCEL_GIT_COMMIT_REF}-${VERCEL_GIT_REPO_OWNER}

Production URL
AUTH0_BASE_URL=${VERCEL_URL}

Here is a concrete example of an Environment File example from next-auth0

If we can access all these system variables in Github actions, great. Then we can do the build on GitHub Actions and skip the vercel step and maybe that fixes it. But I am not sure.

Sorry, this explanation might just confuse you even more.

But in short:

  1. alias-domains' { BRANCH } property seems to refer to refs/heads/branch-name, and not just branch-name . This causes branch-name to be renamed refs/heads/branch-name in Vercel and an extra third domain to be assigned.
  2. We do the build step on Vercel instead of on Github-actions cause the next-auth0 library relies on Vercel system variables during build. We cannot use these as Github secrets as they are sometimes dynamic and not just static like VERCEL_ID.

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

2 participants