lighthouse-action icon indicating copy to clipboard operation
lighthouse-action copied to clipboard

Wait to audit until successful status from deploy steps

Open jamesmosier opened this issue 5 years ago • 6 comments

Thanks for a cool GitHub Action! I was wondering if it was possible to run this after a delay?

Here is the use case I am after...

  1. Merge code into master
  2. CircleCI workflow runs and deploys the code to foo.com (which the GH Action doesn't "know" about)
  3. Run lighthouse-action after 10 minutes against foo.com (10 minutes is arbitrary, basically I just want to wait until the code is live)

Any thoughts would be great! Feel free to close though if out of the scope of this project.

jamesmosier avatar Oct 01 '19 15:10 jamesmosier

Thanks for the kind words!

I ran into the same problem and ended up using this band-aid fix for now:

# deploy steps here
- name: Sleep for 30 seconds
  run: sleep 30
# lighthouse step here

...which you could change to sleep 10m for 10 minutes or whatever's appropriate — I should probably add this to the readme since this is likely race condition is likely present in most use cases. But I'd like to do this the right way and actually get the job status from CircleCI or Netlify or whatever service and start the audit on successful deploy. Adding to the to-do list!

Apologies for the late reply, thanks for your patience! :)

jakejarvis avatar Oct 13 '19 14:10 jakejarvis

I have an idea here. How about you look at the contents of the repository, and compare everything to the online version? You repeatedly do that until the online version matches the repository.

KTibow avatar Oct 20 '19 23:10 KTibow

I ended up using the repository_dispatch event trigger. After CircleCI deploys, I make a curl POST to the GitHub API and then the Lighthouse action is listening for the repository_dispatch event and runs when that POST happens.

https://help.github.com/en/articles/events-that-trigger-workflows#external-events-repository_dispatch

jamesmosier avatar Oct 20 '19 23:10 jamesmosier

Good idea! I'm using GitHub pages though.

KTibow avatar Oct 21 '19 01:10 KTibow

I've not used it yet, but it looks promising.

https://github.com/maddox/actions/tree/master/wait-for-200

mathewmorris avatar Nov 01 '19 15:11 mathewmorris

Here's the approach we took with this action. Worked out really well, since Netlify actions are part of our checks for a PR.

It waits for all checks except the ones we specify (ignoreActions), which means it waits for the deploy preview + header rules + etc from Netlify. Polls every 20 seconds, and that interval is configurable. Then, it just runs this action like normal.

Of note: make sure to include this job's name in the ignoreActions, otherwise it'll wait on itself. It'd be really cool to make this part of the base action.

steps:
  - name: 'Wait for deploy preview to finish'
    uses: 'WyriHaximus/github-action-wait-for-status@master'
    with:
        # We care only about the Netlify checks finishing
        ignoreActions: 'lighthouse audit,triage,notify,tests'
        checkInterval: 20
    env:
        GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
  - name: Audit Netlify deploy preview
    uses: jakejarvis/lighthouse-action@master
    with:
        # This is the deploy preview base URL (where PRs show for deploy previews)
        netlify_site: ${{ env[github.base_ref] }}.netlify.com
  - uses: actions/upload-artifact@master
    with:
        name:
            Lighthouse report (${{github.base_ref}} ${{ github.sha }})
        path: './report'

dgattey avatar Jan 18 '20 02:01 dgattey