Github action to deploy to Netlify with Comments of Preview and Log URL.
-
Add your Netlify
Personal Access Token
& Web site'sSite ID
to your repository's secrets.https://docs.netlify.com/cli/get-started/#obtain-a-token-in-the-netlify-ui
-
Add one step to your Github's jobs.
※. This action uses
yarn
as default dependency manager. If you want to use another dependency manager, you need to override each input.Following settings will deploy your site to preview mode in Netlify and add a comment to the pull request with the URL of the preview and the log.
jobs: deploy: steps: - name: deploy to preview mode uses: thundermiracle/netlify-deploy@v3 with: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN}} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID}} deploy-dir: "./public" production: false node: 14
※. For production mode, you need to add
production: true
to thewith
section.
input | required | default | description |
---|---|---|---|
NETLIFY_AUTH_TOKEN | ○ | Auth token of your Netlify, usually passed by secrets |
|
NETLIFY_SITE_ID | ○ | Your website id in Netlify, usually passed by secrets |
|
deploy-dir | ./dist | Directory to be uploaded to Netlify | |
production | △ | false | Deploy to production mode flag |
node | 14 | Node version to run deployment | |
build-command | △ | yarn build | |
install-command | △ | yarn --check-files --frozen-lockfile --non-interactive | ※ You should override it if you're not using yarn as your dependency manager |
cache-strategy | △ | yarn | yarn , npm , or pnpm |
extra-cache-path | extra cache paths(eg: .cache in GatsbyJS) |
||
working-directory | Working directory of your project |
-
Automatically cache dependencies of your project.
You can override
cache-strategy
to customize the cache. -
Cache extra paths for specific projects.
You can override
extra-cache-path
to enable extra cache policy(eg:.cache
&public
folders forGatsbyJS
). -
Add comment with Preview URL and Log URL to your pull request automatically.
-
working-directory
is supported.To deploy your project in sub directory easily, just set
working-directory
like./packages/my-package
.
-
For Pull Request, create a
.github/workflows/preview.yml
file with the following content.name: 'Netlify Preview Deploy' on: pull_request: types: ['opened', 'edited', 'synchronize'] jobs: deploy-preview: name: 'Deploy Preview' runs-on: ubuntu-latest steps: - name: deploy to preview mode uses: thundermiracle/netlify-deploy@v3 with: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN}} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID}} deploy-dir: "./public" extra-cache-path: | .cache public
-
For production build, create a
.github/workflows/production.yml
file with the following content.name: 'Netlify Production Deploy' on: push: branches: - main jobs: deploy: name: 'Deploy Production' runs-on: ubuntu-latest steps: - name: deploy to production mode uses: thundermiracle/netlify-deploy@v3 with: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN}} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID}} deploy-dir: "./public" extra-cache-path: | .cache public production: true
-
For Pull Request, create a
.github/workflows/preview.yml
file with the following content.name: 'Netlify Preview Deploy' on: pull_request: types: ['opened', 'edited', 'synchronize'] jobs: deploy-preview: name: 'Deploy Preview' runs-on: ubuntu-latest steps: - name: deploy to preview mode uses: thundermiracle/netlify-deploy@v3 with: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN}} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID}} deploy-dir: "./public" extra-cache-path: | .cache public cache-strategy: npm install-command: npm install --production build-command: npm run build
-
For production build, create a
.github/workflows/production.yml
file with the following content.name: 'Netlify Production Deploy' on: push: branches: - main jobs: deploy: name: 'Deploy Production' runs-on: ubuntu-latest steps: - name: deploy to production mode uses: thundermiracle/netlify-deploy@v3 with: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN}} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID}} deploy-dir: "./public" extra-cache-path: | .cache public production: true cache-strategy: npm install-command: npm install --production build-command: npm run build
This project is licensed under the terms of the MIT license.