🙌 Netlify deployments via GitHub actions
A Github action that deploys a build directory to Netlify. It can be configured to comment on the commit or PR with the deploy URL or deploy with GitHub environments, deploy draft builds, deploy Netlify functions and use custom Netlify configs.
There are 4 required inputs for the action
github-token which is usually ${{ secrets.GITHUB_TOKEN }}netlify-auth-token this is a personal access token created from your Netlify account
netlify-site-id this is the API ID of your Netlify site
API ID fieldbuild-dir this is where your site build outputs to relative to the root of your projects folderSee the action.yml for other action inputs and their descriptions
preview-urlThe url of deployment preview.
preview-nameThe name of deployment name.
Here are some ideas of how to configure this action in different workflows…
name: CI
on: [push]
jobs:
# This job will:
# * deploy a draft every time there is a commit that is not on master branch
# * comment on that commit with the deploy URL
deployCommitDraft:
name: Deploy draft to Netlify
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref != 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v1
# ... your other build steps to produce a build directory
# e.g. `npm run build` for create-react-app
- name: Deploy draft to Netlify
uses: South-Paw/action-netlify-deploy@v1.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }}
build-dir: './build'
draft: true
comment-on-commit: true
# This job will:
# * deploy a production build every time there is a push only on the master branch
# * comment that commit with the deploy URL
publishMasterCommit:
name: Publish to Netlify
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v1
# ... your other build steps to produce a build directory
# e.g. `npm run build` for create-react-app
- name: Deploy production to Netlify
uses: South-Paw/action-netlify-deploy@v1.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }}
build-dir: './build'
comment-on-commit: true
name: CI
on:
push:
pull_request:
types:
- opened
- synchronize
jobs:
# This job will:
# * deploy a draft every time there is a pull request created or synchronized that is not on master branch
# * comment on that pull request with the deploy URL
deployPRDraft:
name: Deploy draft to Netlify
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.ref != 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v1
# ... your other build steps to produce a build directory
# e.g. `npm run build` for create-react-app
- name: Deploy draft to Netlify
uses: South-Paw/action-netlify-deploy@v1.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }}
build-dir: './build'
draft: true
comment-on-pull-request: true
# This job will:
# * deploy a production build every time there is a push on the master branch
# * comment that commit with the deploy URL
publishMasterCommit:
name: Publish to Netlify
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v1
# ... your other build steps to produce a build directory
# e.g. `npm run build` for create-react-app
- name: Deploy production to Netlify
uses: South-Paw/action-netlify-deploy@v1.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }}
build-dir: './build'
comment-on-commit: true
name: CI
on:
pull_request:
types:
- opened
- synchronize
release:
types:
- created
jobs:
# This job will:
# * deploy a draft every time there is a pull request created or synchronized that is not on master branch
# * comment on that pull request with the deploy URL
deployPRDraft:
name: Deploy draft to Netlify
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.ref != 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v1
# ... your other build steps to produce a build directory
# e.g. `npm run build` for create-react-app
- name: Deploy draft to Netlify
uses: South-Paw/action-netlify-deploy@v1.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }}
build-dir: './build'
draft: true
comment-on-pull-request: true
# This job will:
# * deploy a production build every time there is a release created on the master branch
# * comment that commit with the deploy URL
publishOnMasterRelease:
name: Publish release to Netlify
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Checkout repository
uses: actions/checkout@v1
# ... your other build steps to produce a build directory
# e.g. `npm run build` for create-react-app
- name: Deploy production to Netlify
uses: South-Paw/action-netlify-deploy@v1.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
netlify-site-id: ${{ secrets.NETLIFY_SITE_ID }}
build-dir: './build'
If you find any, please report them here so they can be squashed.
Download the repo and then install dependencies with npm.
# build the action to `./dist`
npm run build
# clean the `./dist` dir
npm run clean
# lint project
npm run lint
# run tests
npm run test
Contributions and improvements are always welcome 👍
MIT, see the LICENSE file.
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.