action-netlify-deploy icon indicating copy to clipboard operation
action-netlify-deploy copied to clipboard

Status check

Open tpluscode opened this issue 4 years ago • 7 comments

It would be nice to have a status check created on a PR. While I see that the netlify CLI does not return the preview URL in a way easy to retrieve, I would propose to use the --alias option

With a stable URL such as https://${branchName}.foo-bar-baz.netlify.app it would then be possible to use GitHub API to create the status check

tpluscode avatar Dec 24 '20 16:12 tpluscode

Hey @tpluscode !

Thanks for your comment!

If i understand correctly you would like to use this action on a PR to create previews? If that's the case I would strongly advice to use Netlify's GitHub integration directly, they handle PR previews out of the box!

jsmrcaga avatar Dec 25 '20 22:12 jsmrcaga

Yes, makes total sense. The thing is that in this particular repo I'm not in fact using Netlify for deployment but I found your action so that I can have previews without changing much.

What about the --alias option only?

tpluscode avatar Dec 29 '20 10:12 tpluscode

Hey @tpluscode , can we close this issue since your PRs were merged ?

jsmrcaga avatar Feb 02 '21 07:02 jsmrcaga

Maybe. The PR check could be created using a separate action. Probably does not belong here anyway.

I was only thinking to maybe output the deployed URL. Do you know if netlify deploy returns anything about the deployment?

tpluscode avatar Feb 02 '21 10:02 tpluscode

Hum you're right, we could check the exit code and create a GitHub action's output, which could then be picked oup by something like https://github.com/marketplace/actions/status-update

jsmrcaga avatar Feb 03 '21 07:02 jsmrcaga

Following an arduous trial and error process, I landed this workflow which combines your action with a status check.

I will create a PR with example usage.

An action input would allow changing the last line so that manually constructing the preview would be unnecessary. Maybe not worth the effort, especially if Netlify does not give away that information?

tpluscode avatar Feb 04 '21 18:02 tpluscode

I'm not sure what last line you are referring to, but i believe that Netlify's integration is webhook based, so they can create th status checks with the URL from their server.

Their CLI is open source as well, I'm guessig there is a way to fetch the deployed url and expose it from there https://github.com/netlify/cli/tree/master/src/commands

jsmrcaga avatar Feb 05 '21 07:02 jsmrcaga

Hey, I just noticed that the latest version has outputs and I tried to use them for the status check. For some reason that did not work

Does this look correct?

      - name: Publish preview
+       id: netlify
        uses: jsmrcaga/[email protected]
        if: env.NETLIFY_AUTH_TOKEN
        with:
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
          NETLIFY_DEPLOY_MESSAGE: Preview ${{ env.BRANCH_NAME }}
          build_directory: dist
          deploy_alias: ${{ env.BRANCH_NAME }}
          NETLIFY_DEPLOY_TO_PROD: false

      - name: Status check
        uses: Sibz/[email protected]
        if: env.NETLIFY_AUTH_TOKEN
        with:
          authToken: ${{ secrets.GITHUB_TOKEN }}
          context: Netlify Site
          state: success
-         target_url: https://${{ env.BRANCH_NAME }}--shacl-playground.netlify.app
+         target_url: ${{ steps.netlify.outputs.NETLIFY_PREVIEW_URL }}

tpluscode avatar Mar 02 '23 12:03 tpluscode

Oh, env. NETLIFY_PREVIEW_URL works. Is that right. Has the use of outputs changed with the change of how they are set in upstream steps?

tpluscode avatar Mar 02 '23 13:03 tpluscode