/wait-for-netlify-action

A GitHub action that will wait until a Netlify deploy is completed before continuing on

Primary LanguageJavaScript

Wait for Netlify Deployment

Do you have other Github actions (Lighthouse, Cypress, etc) that depend on the Netlify deploy URL? This action will wait until the deploy URL is available before running the next task.

This action uses the Netlify API to always retrieve the correct deployment being built. You will need to generate a Personal Access Token to use and pass it as the NETLIFY_TOKEN environment variable.

Env

NETLIFY_TOKEN

Required. Your Netlify Personal Access Token to use for API access. This should be set as a GitHub secret, see example.

Inputs

site_id

Required The API ID of your site. See Settings > Site Details > General in the Netlify UI

max_timeout

Optional — The amount of time to spend waiting on the Netlify deployment to respond with a success HTTP code after reaching "ready" status. Defaults to 60 seconds.

Outputs

url

The Netlify deploy preview url that was deployed.

deploy_id

The Netlify deployment ID that was deployed.

Example usage

Basic Usage

steps:
  - name: Wait for Netlify Deploy
    uses: probablyup/wait-for-netlify-action@3.2.0
    id: waitForDeployment
    with:
      site_id: 'YOUR_SITE_ID' # See Settings > Site Details > General in the Netlify UI
    env:
      NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
      
# Then use it in a later step like:
# ${{ steps.waitForDeployment.outputs.url }}
Complete example with Cypress
name: Cypress
on: pull_request
jobs:
  integration:
    runs-on: ubuntu-latest

    jobs:
    cypress:
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v2

        - name: Install modules
          run: npm ci

        - name: Wait for Netlify
          uses: probablyup/wait-for-netlify-action@3.2.0
          id: waitForDeployment
          with:
            site_id: '[your site ID here]'
          env:
            NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}

        - name: Run Cypress
          uses: cypress-io/github-action@v2
          with:
            record: true
            config: baseUrl=${{ steps.waitForDeployment.outputs.url }}
          env:
            # pass the Dashboard record key as an environment variable
            CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
            # this is automatically set by GitHub
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Complete example with Lighthouse
name: Lighthouse

on: pull_request

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js 12.x
        uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - name: Install
        run: |
          npm ci
      - name: Build
        run: |
          npm run build
      - name: Waiting for 200 from Netlify
        uses: probablyup/wait-for-netlify-action@3.2.0
        id: waitForNetlifyDeploy
        with:
          site_id: 'YOUR_SITE_ID' # See Settings > Site Details > General in the Netlify UI
        env:
          NETLIFY_TOKEN: ${{ secrets.NETLIFY_TOKEN }}
      - name: Lighthouse CI
        run: |
          npm install -g @lhci/cli@0.3.x
          lhci autorun --upload.target=temporary-public-storage --collect.url=${{ steps.waitForNetlifyDeploy.outputs.url }} || echo "LHCI failed!"
        env:
          LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
This is a heavily-modified fork of [kamranayub/wait-for-netlify-action](https://github.com/kamranayub/wait-for-netlify-action).