peter-evans / create-or-update-comment

A GitHub action to create or update an issue or pull request comment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

body-file markdown formatting code block

semihural-tomtom opened this issue · comments

I can add markdown file as an issue comment but how can I format this comment as a code block? Is that possible?

      - name: Run Trivy vulnerability scanner in repo mode
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: ''
          scan-type: 'fs'
          format: 'table'
          exit-code: '0'
          ignore-unfixed: true
          vuln-type: 'os,library'
          severity: 'CRITICAL,HIGH'
          output: 'trivy-result.md'

      - name: Upload Trivy report
        uses: actions/upload-artifact@v3
        with:
          path: trivy-result.md
          name: trivy-result

      - name: Download Trivy report
        uses: actions/download-artifact@v1
        with:
          name: trivy-result

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v2
        with:
          issue-number: ${{ github.event.issue.number }}
          body-file: 'trivy-result.md'

Hi @semihural-tomtom

There's no support for mixing markdown and files. You'll need to add a step to edit the file and wrap it in a code block with backticks.

@peter-evans any example of how can I achieve this?

I asked ChatGPT and this it what it give me. Not tested, but it's a starting point. 😄

- name: Wrap file contents in markdown code block
  run: |
    sed -i -e '1s/^/```\n/' -e '$s/$/\n```/' myfile.txt
  shell: bash

That's worked :D thanks @peter-evans