cloudflare / pages-action

MIT License
473 stars 97 forks source link

Comment on PR? #16

Closed NullVoxPopuli closed 1 month ago

NullVoxPopuli commented 2 years ago

The integration with github comments on the PR -- example: https://github.com/NullVoxPopuli/ember-resources/pull/513#issuecomment-1141387382

But the pages actions does not

IanVS commented 1 year ago

Does anyone have a workaround or custom steps they've added to comment the deployment URL back to the PR, until/unless this becomes a built-in feature?

IanVS commented 1 year ago

We ended up using mshick/add-pr-comment@v2, but it sure would be nice if the action did this for us.

sibelius commented 1 year ago

can you share what you did with mshick/add-pr-comment@v2 ?

sibelius commented 1 year ago

we are doing like this

      - name: Publish to Cloudflare Pages
        id: cloudflare-publish
        uses: cloudflare/pages-action@v1
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          projectName: page
          directory: public
          # Optional: Enable this if you want to have GitHub Deployments triggered
          #gitHubToken: ${{ secrets.GITHUB_TOKEN }}
      - uses: mshick/add-pr-comment@v2
        with:
          message: |
            🚀 This branch can be previewed at ${{ steps.cloudflare-publish.outputs.url }}

based on https://github.com/marcus-crane/utf9k/blob/f6a4464e4e4d522fc7cddd7599a7e45a59b86dcd/.github/workflows/deploy.yml#L50

IanVS commented 1 year ago

Ours (created by @jasikpark) is slightly more complicated, but the same idea. It comments right away at the start of the workflow, then updates it when complete. And each push to the PR updates the comment, rather than leaving a new one.

steps:
      - name: Comment deploy start
        if: github.event_name != 'push'
        uses: mshick/add-pr-comment@v2
        with:
          message-id: cloudflare-deploy
          message: |
            ### <span aria-hidden="true">🚧</span> Deploy Preview building...

            |  Name | Link |
            |---------------------------------|------------------------|
            |<span aria-hidden="true">🔨</span> Latest commit | ${{ github.sha }} |
            |<span aria-hidden="true">🔍</span> Latest deploy log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
            ---
      - ... rest of config
      - name: Comment deploy url
        uses: mshick/add-pr-comment@v2
        with:
          message-id: cloudflare-deploy
          message: |
            ### <span aria-hidden="true">✅</span> Deploy Preview ready!

            |  Name | Link |
            |---------------------------------|------------------------|
            |<span aria-hidden="true">🔨</span> Latest commit | ${{ github.sha }} |
            |<span aria-hidden="true">🔍</span> Latest deploy log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
            |<span aria-hidden="true">😎</span> Deploy Preview Url | [${{ steps.cloudflare.outputs.url }}](${{ steps.cloudflare.outputs.url }}) |
            |<span aria-hidden="true">🌳</span> Environment | ${{ steps.cloudflare.outputs.environment }} |
            ---

We'd love to also include the alias, but it seems that is still broken in the pages-action (https://github.com/cloudflare/pages-action/issues/29)

eerison commented 1 year ago

just to point out

you need to add permissions.pull-requests: write in your deploy step

e.g:

  deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      deployments: write
      pull-requests: write

I guess we could add this info about the comment into the README.md, what do you think?

IanVS commented 1 month ago

@nprogers I see you closed this as completed. Does that mean this action is not being deprecated, and additional features are being added? I'm a bit confused as to the status of this tool.