Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not reliably work when adding a commit to an existing deploy preview #6

Open
BrunnerLivio opened this issue May 1, 2020 · 6 comments

Comments

@BrunnerLivio
Copy link

BrunnerLivio commented May 1, 2020

The following workflow does not reliably work with wait-for-netlify-action:

  1. Create a branch test
  2. Push the branch to origin and create a PR
  3. Deploys the website
  4. Waits for 200 on deploy preview
  5. Proceed with additional scripts (e.g. Lighthouse)
    => As expected

  1. Add a new commit on branch test
  2. Push the commit to origin
  3. Waits for 200 on deploy preview immediately gives an "ok" because the previous deploy is still online
  4. The additional scripts still use the old deploy preview (e.g. Lighthouse)
    => Not as expected

An easy fix to workaround this is sure with a simple sleep:

- name: Sleep
  run: sleep 50

... but that is not really clean since we would need to update the sleep value every time the build step takes more or less time after changes.

@JakePartusch
Copy link
Owner

Yeah @BrunnerLivio — you are completely right, and it's something that I've noticed as well.

We could potentially create a solution for this by using the "commit" preview instead of the PR preview (every build in Netlify has a unique preview url) 🤔

@BrunnerLivio
Copy link
Author

Sounds great! @JakePartusch quite busy at the moment, but I'd love to investigate that as soon as I find some time.

@flameddd
Copy link

flameddd commented Aug 2, 2020

Hi forks

Thanks yours hard work and great jobs

I want to share my workaround. (I have tested several times, it's seems looks fine)

  • use fountainhead/action-wait-for-check to wait netlify deploy check.
  • run wait-for-netlify-action after check done

1. find out your "pull request's netlify's Pages changed checkname

steps

  1. go to one of pull request
  2. go to Checks tab
  3. there is a netlify checks on left list
  4. copy "Pages changed ... " checkname
    • e.x. "Pages changed - modest-spence-711b92"

image
image

2. fill in your checkname (with single quote, bcuz checkName string have space)

steps

  • e.x. checkName: 'Pages changed - modest-spence-711b92'

and

  • if: steps.wait-for-Netlify.outputs.conclusion == 'neutral'

image

finally

  • create pull request, push new commit and test

workflow yaml

name: Successful Deploy Action Example

on: [pull_request]

jobs:
  screenshots:
    runs-on: ubuntu-latest
    steps:
    - name: Wait for Pages changed to neutral
      uses: fountainhead/[email protected]
      id: wait-for-Netlify
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        ref: ${{ github.event.pull_request.head.sha || github.sha }}
        checkName: 'Pages changed - modest-spence-711b92'
    - name: Get Preview URL and generate screenshot after Netlify check done
      if: steps.wait-for-Netlify.outputs.conclusion == 'neutral'
      uses: jakepartusch/wait-for-netlify-action@v1
      id: waitFor200
      with:
        site_name: 'modest-spence-711b92'

About "fountainhead/action-wait-for-check" Action

  • there are four netlify check names when preview deploy
    • Header rules - modest-spence-...
    • Pages changed - modest-spence-...
    • Redirect rules - modest-spence-...
    • Mixed content - modest-spence-...

I chose 'Pages changed' as check target by intuition

  • rest of checks seems do nothing
  • and I don't know why 'Pages changed' check's final conclusion is 'neutral'
    • why is not 'success', like 'Mixed content' check

The things I want to say is

As long as your netlify USE CASE become more COMPLICATE in the future

  • maybe there will be another more appropriate check name can use (e.x. deploy check?)
  • maybe the conclusion become 'success', but NOT 'neutral'

bcuz I am totally newbie in netlify, I just want to mention those things I not sure


I have another newbie question

Before I come here ("jakepartusch/wait-for-netlify-action"). I read a blog post.

In this post said
image
image

like this

# .github/workflows/example_workflow.yml
name: Successful Deploy Action Example
on: deployment_status
jobs:
  build:
    if: github.event.deployment_status.state == 'success'
    runs-on: ubuntu-latest
    steps:
      - name: XYZ
        run: npm run xyz
        env:
          DEPLOY_URL: ${{ github.event.deployment_status.target_url }}

BUT I have tried lots of times. workflow NEVER be triggered by deployment_status (or deploymene)

and

  1. I can not find too much information on
  2. There exists some Github Actions like wait-for-netlify-action (like a webhook)

SO, I guess the blog post is Misleading (maybe only Zeit can work)

FOR NOW, we can NOT trigger [deploymene, deployment_status] workflow via netlify Preview deploy, right ?

thanks for your patient, hard work and great Github Actions !!!

@markokhman
Copy link

@flameddd thank you sooooo much for this workaround, i have spent a couple hours configuring this before I found this thread and configured it same as you did.

I'm wondering if no one have proposed any other pro solution?

@dwjohnston
Copy link

I'd been meaning to create a PR or a work that reliably does a 'wait for netlify deploy on branch preview' but I haven't been getting around to it.

If it's useful, this is the script I'm using that'll poll until it's ready.

https://github.com/dwjohnston/blacksheepcode/blob/master/.github/workflows/scripts/wait-for-netlify-deploy.js

@keyserj
Copy link

keyserj commented Jan 2, 2025

Building off of @flameddd 's solution, I was able to use Netlify's success/failed commit status along with the wait-for-status-check action so that I can also run/not-run the next steps based on the preview's success/failure:

    steps:
      - uses: autotelic/[email protected]
        name: Wait for Preview Deploy
        id: wait-for-status
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          statusName: "netlify/{netlify-site-name-here}/deploy-preview"
        # So that tests don't run if the preview failed
      - name: Fail workflow if Preview Failed
        if: steps.wait-for-status.outputs.state == 'failure'
        run: exit 1
      - name: Begin e2e setup - checkout
        # EDIT: If deploy was cancelled, wait-for-status.state is still considered succeeded, and we don't
        # want to fail the e2e tests in this case, so we need to skip all the following steps.
        # Unfortunately it seems that we need this `if` duplicated on all steps in order to do skip
        # without failing https://github.com/orgs/community/discussions/27174
        if: steps.wait-for-status.outputs.description == 'Deploy Preview ready!'
        uses: actions/checkout@v3
        ...

This also has the benefit of not needing to poll the deployed URL after having polled for the commit status

Notes:


Also it's a bit late, but regarding @flameddd 's question about the deployment_status trigger - there's some context in this Netlify thread https://answers.netlify.com/t/deploy-preview-as-deployment-environments-on-github/93131/1, but basically Netlify would have to use the GitHub Deployment API, and they don't currently do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants