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

Unclear how the build command and the build directory are inferred #122

Closed
PaulRBerg opened this issue Mar 7, 2022 · 6 comments
Closed

Comments

@PaulRBerg
Copy link

PaulRBerg commented Mar 7, 2022

The README does not clarify what is it that this GitHub Action uses to:

  1. Build the app
  2. Deploy the built app from

I suspect that it's the builds and routes field in the vercel.json file that are doing the magic - but this should be clarified. There are cases in which users have to work around the basic example given in the README, e.g. in my case I am working on a monorepo and I have to create a vercel.json in each app directory (or at least this is what I think I should do).

Side note: it looks like the Vercel docs recommend against using the builds field. functions should be used instead.

Update: I think I figured it out .. is it that by passing a Vercel token and a project id, Vercel automatically knows what commands to run based on the build steps provided in the Vercel interface? If that's true, then what do we need the builds and the routes fields in the vercel.json example given in this README?

@amondnet
Copy link
Owner

amondnet commented Mar 9, 2022

This action allows you to use github actions to build your app that vercel did automatically before. So we have to disable the automatic build function of vercel and set it up manually. Then deploy the static file you build to vercel.

      - name: build
        run: |
          cd example/angular
          npm ci
          npx ng build --prod

{
  "version": 2,
  "public": false,
  "github": {
    "enabled": false
  }
}

routes or rewrites are required for SPA fallback.

{
  "routes": [
    { "src": "/(.*)", "dest": "/index.html" }
  ]
}

or

{
  "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}

@PaulRBerg
Copy link
Author

PaulRBerg commented Mar 9, 2022

So we have to disable the automatic build function of vercel and set it up manually.

Are you sure? My GitHub workflow doesn't have any build step but it still works fine. Vercel just does the build on its own, following the commands I set via the Vercel interface.

"version": 2

Where did you get this version number from? I browsed the Vercel docs but I found no configuration version mentioned.

routes or rewrites are required for SPA fallback

Riiiight so now I get it! Thank you! I need to set them too then. This should definitely be mentioned in the README.

Update: actually, I don't think the rewrites are needed anymore. My Vercel app is built with no rewrites but I can still access the static files from the public folder just fine. I can go to sablier.finance/icon.png and the image is shown in the browser. Conversely, when no resource is found, Vercel automatically redirects to the root.

@amondnet
Copy link
Owner

amondnet commented Mar 10, 2022

Are you sure? My GitHub workflow doesn't have any build step but it still works fine. Vercel just does the build on its own, following the commands I set via the Vercel interface.

First of all, we need to know vercel's build steps. The build commands you set via vercel interface is not actually executed on your computer or github actions runner. It does it on vercel 's build machine(with amazon linux 2).

Actual build time is same(approximately), but the vercel build time is additionally used.
see https://vercel.com/dashboard/usage

Build on vercel build machine

github actions on github actions runner : 5 minutes

  • fetch
  • build(wait for vercel build) : 5 minutes
  • comment

vercel build on vercel build machine : 5 minutes

  • Retrieve list of deployment files.
  • Download deployment files.
  • Analyze source code.
  • Install build runtime.
  • Install dependencies.
  • Execute build commands.
  • Upload build outputs.
  • Deploy build outputs.

You use 5 minutes for github actions and 5 minutes for vercel build.

Build on github actions runner

github actions on github actions runner : 5 minutes

  • fetch
  • build: Execute build commands, 5 minutes
  • deploy(wait for vercel build) : 2 seconds
  • comment

vercel build on vercel build machine : 2 seconds

스크린샷 2022-03-10 오전 10 53 22

  • Retrieve list of deployment files.
  • Download deployment files.
  • Analyze source code.
  • Install build runtime.
  • Install dependencies.
  • Execute build commands.
  • Upload build outputs.
  • Deploy build outputs.

You use 5 minutes for github actions and 2 seconds for vercel build.

It also has some limitations. If your build takes a long time and you do multiple builds, you will see a lot of queues. Hobby plan does only one build at a time.

@PaulRBerg
Copy link
Author

Amazing explanation, thanks so much for your help 🙏

Sorry to bother you with another question - but how can we disable the Vercel build? That is, what do I have to do on Vercel in order for the build to be executed just in GitHub Actions?

@amondnet
Copy link
Owner

@PaulRBerg

Method 1: define the builds property in vercel.json

A Project has several settings that can be found in the dashboard. One of those sections, "Build & Development Settings", is used to change the way a Project is built.

However, the Build & Development Settings are only applied to zero-configuration Deployments.

If a Deployment defines the builds configuration property, the Build & Development Settings are ignored.

{
  "builds": [
    { "src": "{{Source for distribution}}", "use": "@vercel/static" },
  ]
}

Set src to your source location for distribution.

Method 2: skip build step via vercel

https://vercel.com/docs/concepts/deployments/build-step#build-command

Skip Build Step

Some static projects do not require building. An example of this would be a website with only HTML/CSS/JS source files that can be served as-is (For example, you might just have a single index.html file).

In such cases, you should:

Specify "Other" as the framework preset, and
Enable the Override option for the Build Command, and
Leave the Build Command empty.
This will prevent the build from being attempted and serve your content as-is.

  1. Specify "Other" as the framework preset, and
  2. Enable the Override option for the Build Command, and
  3. Leave the Build Command empty.
  4. This will prevent the build from being attempted and serve your content as-is.

@PaulRBerg
Copy link
Author

Thanks so much for your help here. As per #136, it looks like you've also added instructions for how the build command works in the README. Therefore, I'm going to close this issue now.

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