How to create a new site via github action

My use case is people will create a new repo using a git hub template and that should create a Netlify site if one does not exist.

I tried using the actions repo triggered by action button but nothing happens. It logs the container info and ‘Deploying’ and then fails with zero visibility

The example which says it will create one if requires provides a site ID but you obviously DO NOT have one if the site is going to be created?

on: push
name: Publish on Netlify

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master

    - name: Publish
      uses: netlify/actions/build@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
        NETLIFY_BASE: site
        NETLIFY_CMD: npm build
        NETLIFY_DIR: site/_build

As far as I can tell it HAS to be launched manually as if done on a push as per the examples it will clash with the netlify integration using the Netlify GitHub App?

I also thought about calling netlify init from the actions but that is always interactive unfortunately. It could do with and option to say use the git repo

Finally I looked at the code which calls the Netlify API using an undocumented path for github so no clues there for how to use it.

Hi @slim,

I presume that if you don’t have a site id, you would not define it so that it can create the site for you.

With regards to triggering the action, you could have the automatic builds disabled on the site and use the action to determine when a site build is triggered. The on directive should be what determines when the github action runs and you should be able to tweak that to your preference.

Based on the entrypoint.sh here: actions/entrypoint.sh at master · netlify/actions · GitHub, it looks like you would need to link your github account to your netlify site before the action would work. Have you try doing that here: Netlify App?

Let me know if that helps.

1 Like

presume that if you don’t have a site id, you would not define it so that it can create the site for you.

Me too. Docs need fixing :wink:

With regards to triggering the action, you could have the automatic builds disabled on the site and use the action to determine when a site build is triggered. The on directive should be what determines when the github action runs and you should be able to tweak that to your preference.

Sure, I was really pointing out a clash. Docs need updating :slight_smile:

Based on the entrypoint.sh here: actions/entrypoint.sh at master · netlify/actions · GitHub, it looks like you would need to link your github account to your netlify site before the action would work. Have you try doing that here: Netlify App?

Ah, good spot thanks. I’ll check

Hi, there isn’t much documentation for that repo, but feel free to put a PR in here GitHub - netlify/actions if you want.

1 Like