Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
320 stars 53 forks source link

Limit Github Action Comment When Deploying Preview Environment #1135

Open listiani13 opened 1 year ago

listiani13 commented 1 year ago

Is your feature request related to a problem? Please describe. Currently we're using Azure/static-web-apps-deploy@v1 to deploy preview environment on PR. However, we noticed that each time Azure re-deploying, it will add new comment which kinda clouded the PR image

Describe the solution you'd like Could we only make the bot comment once & update the link in there (and it's not like the URL will ever change I assume? Since it's relying on pull request number)

Describe alternatives you've considered Haven't had any alternatives currently

AnthonyPhan commented 1 year ago

Agreed, this feature will help clean up pull requests which go though multiple changes.

thomasgauvin commented 1 year ago

Thanks for the feedback to you both! This feature is currently intended, as any changes to the PR are intended to be within the PR thread so that new comments are made aware of the changes. If this ask gets traction, we may investigate considering this change.

seanyusa commented 1 year ago

Is there a way to disable these comments entirely? We are using multiple Static Web Apps for a single repo so it gets a little messy with multiple comments for every deployed commit.

nitelite commented 1 year ago

Please provide an option to avoid spamming our PRs with these comments.

We have pull requests with 8 normal comments and over 30 comments with the same preview URL over and over. Since we deploy two version of our app for each PR it becomes twice as bad as "normal". Becomes very hard to follow the actual conversation when we keep getting the same preview URLs spammed over and over, for every change pushed to the branch. I tried to make a Github action that would clean up duplicate comments, but unforunately this also leaves a "comment was deleted" line in the history, so didn't quite do as much as I hoped.

smokedlinq commented 11 months ago

In the meantime, I used this before the deploy step...

      - run: |
          gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments `
            | ConvertFrom-Json `
            | Where-Object body -like 'Azure Static Web Apps: Your stage site is ready! Visit it here: *' `
            | ForEach-Object {
                gh api repos/${{ github.repository }}/issues/comments/$($_.id) -X DELETE
              }
        shell: pwsh
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
coliff commented 10 months ago

Microsoft - please make improvements to this 🙏 - for inspiration pls take a look at how great Netlify's UX is:

(Thanks for that tip @smokedlinq - I just needed to add continue-on-error: true to that step as it wasn't working after merging so it didn't get deployed. works well now!)

nitelite commented 9 months ago

I have used the new permission requirement for workflows to kind workaround this. If you don't grant the deployment job the write permissions for pull requests, it seems to be able to do everything it should, except post the comment. Since all PR URLs are predictable based on the PR number, you can use the following action, which adds a "sticky" comment (never adds more than one, and updates that one) to add a second job that is dependant on the deployment job that actually posts a custom comment with the link in it. "needs" and "permissions" are the key in the sample below.

https://github.com/marketplace/actions/add-pr-comment

I ended up with something along the lines of this:

jobs:
   build_and_deploy_job:
      if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
      runs-on: ubuntu-latest
      name: Build and Deploy Job
      steps:
         - uses: actions/checkout@v4
         - name: Build And Deploy
           id: builddeploy
           uses: Azure/static-web-apps-deploy@v1
           with:
              azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API }}
              repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
              action: "upload"
              app_location: "/"
              api_location: ""
              output_location: "dist"

   add_staging_comment:
      if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
      needs: build_and_deploy_job
      runs-on: ubuntu-latest
      permissions:
         pull-requests: write
      name: Add Staging URL to PR comments
      steps:
         - uses: mshick/add-pr-comment@v2
           if: always()
           with:
              message-id: env-name-url
              message: Staging env available at https://xxx-yyy-zzz-${{ github.event.number }}.region.1.azurestaticapps.net
              message-failure: Staging environment not updated, because build failed.
aberonni commented 2 months ago

Is there a place where one could contribute a PR to the code that runs this workflow? I couldn't find it, but I'd be happy to contribute something that could address this problem if I knew where to do that.

elwinschmitz commented 1 month ago

@aberonni: Is there a place where one could contribute a PR to the code that runs this workflow? I couldn't find it, but I'd be happy to contribute something that could address this problem if I knew where to do that.

This is the GitHub Action that runs: https://github.com/Azure/static-web-apps-deploy But it uses a Docker-image that's not open-source... 😿