0

I sucked and do not know how to break line "text" correctly, here is the snipped of workflow file:

raw: >-
            {
              "@type": "MessageCard",
              "@context": "http://schema.org/extensions",
              "title": "Smoke test run on ${{ env.AOS_TEST_ENV }}",
              "text": "Status: **${{ env.RESULTS }}**\n\n---\n\n[GitHub link](${{ env.GITHUB_URL }})\n\n---\n\n[TestRail link](${{ env.TR_RUN_URL }})\n\n---\n\n**Project-version: ${{ env.PROJECT }}**",
              "themeColor": "00FF00"
            }

the linter (yamllint) reporting an error: 156:121 error line too long (195 > 120 characters) (line-length)

i have tried break "line" into two: "line1"+ "line2", "line1 \ line2"

Mar tix
  • 1
  • 2

1 Answers1

0

JSON doesn't support concatenations nor embedded newlines in a string literal. So there is now ay in the current way you have configured the item to solve your YAML ling warning.

My suggestion is to turn off the lint rule for the (pretty short) max line length.

If that's not an option, you'll have to build that JSON blob in a different way, something like this:

    steps:
      - run: |
          $messagecard = [ordered]@{}
          $messagecard["@type"] = "MessageCard"
          $messagecard["@context"] = "http://schema.org/extensions"
          $messagecard["title"] = "Smoke test run on $env:AOS_TEST_ENV"
          $messagecard["text"] = "Status: **$env:RESULTS**
          
          ---
          
          [GitHub link]($env:GITHUB_URL)
          
          ---
          
          [TestRail link]($env:TR_RUN_URL)
          
          ---
          
          **Project-version: $env:PROJECT**"
          $messagecard["themeColor"] = "00FF00"
      
          echo "message-card<<EOF" >> $env:GITHUB_OUTPUT
          echo (convertto-json $messagecard) >> $env:GITHUB_OUTPUT
          echo "EOF" >> $env:GITHUB_OUTPUT
      
        shell: pwsh
        id: set-template
      
      - uses: skitionek/notify-microsoft-teams@v1.0.8
        with: 
          webhook_url: ${{ secrets.MSTEAMS_SMOKE_WEBHOOK }} 
          needs: ${{ toJson(needs) }}
          job: ${{ toJson(job) }}
          steps: ${{ toJson(steps) }}
          raw: ${{ steps.set-template.outputs.message-card }}

By using PowerShell to build the json you prevent a few injection and encoding issues as well. You could do something similar with jq in bash probably.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Thanks, but it didn't help. – Mar tix Aug 04 '23 at 14:49
  • How did it not help? – jessehouwing Aug 04 '23 at 16:24
  • Gihub actions warns an error of parsing JSON..... – Mar tix Aug 07 '23 at 08:19
  • GitHub isn't, it must be the action you're passing the json to. Can you share more context of the action you're using? have you tried moving the contents to a file? – jessehouwing Aug 07 '23 at 10:07
  • But the json standard doesn't support concatenation, so there's no way to keep your json data in the YAML and not cause the line to grow beyond the yaml linter rules you've configured. https://stackoverflow.com/questions/2392766/are-multi-line-strings-allowed-in-json – jessehouwing Aug 07 '23 at 10:40
  • - name: uses: skitionek/notify-microsoft-teams@master with: webhook_url: ${{ secrets.MSTEAMS_SMOKE_WEBHOOK }} needs: job: steps: raw: | { "@type": , "@context":, "title": "title", "text": "Status: **${{ env.RESULTS }}**\n\n---\n\n[GitHub link](${{ env.GITHUB_URL }})\n\n---\n\n[TestRail link](${{ env.TR_RUN_URL }})\n\n---\n\n**Project-version: ${{ env.PROJECT }}**"} – Mar tix Aug 07 '23 at 10:59