mshick / add-pr-comment

uses: mshick/add-pr-comment@v2
MIT License
196 stars 54 forks source link

[Question] Conditional message depends on steps #112

Closed cpfarher closed 8 months ago

cpfarher commented 10 months ago

Do we have a way to write a condition message depending on the success of the steps on a job? I want to write a comment with: 'foo' if step1 succeeds, and 'bar' if step2 succeeds. Also, If both succeed it should appear 'foo' and 'bar'

mshick commented 8 months ago

Sure, though I think this is more a question about GitHub Actions than this action specifically. Maybe the only gotcha specifically related to this action is that you'd need to set unique message-ids for each of your message. You'd need to do the same any time you want to print messages, since the default behavior is to update the existing message.

Feel free to re-open if I've missed something. Hope this helps!

You might do the following:

jobs:
  something:
    runs-on: ubuntu-latest
    steps:
      - name: Step1
        run: |
          echo "hi"

      - name: Message1
         if: success()
         uses: mshick/add-pr-comment@v2
         with:
          message-id: message1
          message: |
            foo

      - name: Step2
        run: |
          echo "hello"

      - name: Message2
         if: success()
         uses: mshick/add-pr-comment@v2
         with:
          message-id: message2
          message: |
            bar