Blog

Broken Builds

7/26/2020

Pushed a bunch of my changes up to GitHub and Netlify and...

Now I've noticed my builds are failing. Turns out the Git submodule inside of itself was a problem! But not an insurmountable one... It exists purely on Netlify because they fetch submodules recursively by default. They haven't always, but they do now and there's no way to configure this. All this means is... I can't use the Netlify CI.

I can't use the Netlify CI, which is a shame because it was tremendously convenient. The CI is the service that performs the website build based on the structure I provide it, so it's a pretty important step. But I've got other options...

Netlify's settings pages suggest I should also be able to deploy via the CLI or API, meaning I just need to... do that instead. API is probably preferable, but I'm not sure yet.

I want the build to happen on GitHub Actions, I think. Since it's already hosted on GitHub, these seems sensible. So then it's just... Build there, and deploy via the Netlify API from there (or CLI as the case may be - whichever works best).

It is, however... fucking late, so I'm gonna head to bed for now. Will take a look at this at some point tomorrow. Should be relatively quick and easy to configure.

Essentially, Netlify is running something like this:

git submodule update --remote --recursive

...which fails because one of my submodules is a submodule containing a submodule of itself containing a submodule of itself containing a submodule of itself, ad infinitum.

Interestingly, running the command locally hasn't resulted in the same error occurring, but I do suspect the --recursive flag is a part of the issue since this issue only started occurring when recursion was introduced.

What I usually run locally and what I suspect would work on Netlify is:

git submodule update --remote

The same command, now without the --recursive flag.

Since we'll be using GitHub Actions, the first thing I need to do is create the .github folder in my root directory and add a workflows/main.yml file.

I've added the following basic configuration to it as a starting point:

name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

At this point, I've already disabled builds on Netlify so there'll be no errors there... but also no builds.

On push to GitHub, the action passes! However, the docs for actions/checkout indicate that the default submodule behaviour is not to fetch them at all. I can configure this by setting either true or recursive. We know we don't want recursive, so I'll make the following change:

    steps:
    - uses: actions/checkout@v2
      with:
        submodules: true

This should now fetch submodules, but only to one level deep and... the build appears to pass!

The next step is to actually build the site and export the content. The following additional config should achieve just that:

    - uses: actions/setup-node@v1
      with:
        node-version: '10.x'

    - run: yarn install

    - name: Build and Export
      run: yarn build && yarn export

Success! A push to GitHub confirms the action should now be fetching repositories and building the project as expected. Which means the last step is to deploy this to Netlify. Handily, some folks have already setup a GitHub action that seems to just that: netlify-actions.

I should only need to add:

    - name: Deploy to Netlify
      uses: nwtgck/actions-netlify@v1.1
      with:
        publish-dir: './dist'
      env:
        NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
        NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}

...and then with a NETLIFY_AUTH_TOKEN and NETLIFY_SITE_ID configured in my repo's secrets, it should deploy. Let's give it a shot!

And it works! I've successfully deployed a "deploy preview" on Netlify that features everything I want it to. The site is up to date... though I now need to figure out how to automate going from deploy preview to published.

Oh, easy-peasy! I just need to set production-deploy to true:

    - name: Deploy to Netlify
      uses: nwtgck/actions-netlify@v1.1
      with:
        publish-dir: './dist'
        production-deploy: true

That should do it!

Edit: I do still need to remember that the only way content from submodules gets updated is if I run git submodule update locally and commit the changes. actions/checkout@v2 doesn't do this. I could write my own commands into the build config, but will leave that for now and take the manual approach.