To add GitHub Actions for deployment and deploy content to Netlify on merge to the main branch, we need to create a workflow file in the .github/workflows directory of the repository.
The workflow will trigger on each push to the main branch and perform the deployment to Netlify. We can use the on keyword to define the trigger event, and the jobs section to define the steps and actions to be executed.
Here's an example of a workflow file to achieve this:
name: Deploy to Netlify
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Build and Deploy
uses: nwtgck/actions-netlify@master
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: <Netlify Site ID>
BUILD_COMMAND: npm run build
PUBLISH_DIRECTORY: <build output directory>
Make sure to replace <Netlify Site ID> with your actual Netlify site ID and <build output directory> with the directory where your built files are located.
The workflow uses the actions/checkout action to fetch the latest code from the main branch. Then, it uses the nwtgck/actions-netlify action to build and deploy the project to Netlify.
Note that you need to set up a secret named NETLIFY_AUTH_TOKEN in your GitHub repository settings, which should contain a personal access token with the necessary permissions to deploy to your Netlify site.
After implementing this workflow file, any push to the main branch will trigger the deployment to Netlify.
To add GitHub Actions for deployment and deploy content to Netlify on merge to the main branch, we need to create a workflow file in the
.github/workflows
directory of the repository.The workflow will trigger on each push to the main branch and perform the deployment to Netlify. We can use the
on
keyword to define the trigger event, and thejobs
section to define the steps and actions to be executed.Here's an example of a workflow file to achieve this:
Make sure to replace
<Netlify Site ID>
with your actual Netlify site ID and<build output directory>
with the directory where your built files are located.The workflow uses the
actions/checkout
action to fetch the latest code from the main branch. Then, it uses thenwtgck/actions-netlify
action to build and deploy the project to Netlify.Note that you need to set up a secret named
NETLIFY_AUTH_TOKEN
in your GitHub repository settings, which should contain a personal access token with the necessary permissions to deploy to your Netlify site.After implementing this workflow file, any push to the main branch will trigger the deployment to Netlify.