|
| 1 | +name: 'AwesomeBot Markdown Summary Report' |
| 2 | +description: 'Composes the summary report using JSON results of any AwesomeBot execution' |
| 3 | + |
| 4 | +inputs: |
| 5 | + ab-root: |
| 6 | + description: 'Path where AwesomeBot result files are written.' |
| 7 | + required: true |
| 8 | + files: |
| 9 | + description: 'A delimited string containing the filenames to process.' |
| 10 | + required: true |
| 11 | + separator: |
| 12 | + description: 'Token used to delimit each filename. Default: " ".' |
| 13 | + required: false |
| 14 | + default: ' ' |
| 15 | + append-heading: |
| 16 | + description: 'When should append report heading.' |
| 17 | + required: false |
| 18 | + default: "false" |
| 19 | + write: |
| 20 | + description: 'When should append the report to GITHUB_STEP_SUMMARY file descriptor.' |
| 21 | + required: false |
| 22 | + default: "true" |
| 23 | + |
| 24 | +outputs: |
| 25 | + text: |
| 26 | + description: Generated Markdown text. |
| 27 | + value: ${{ steps.generate.outputs.text }} |
| 28 | + |
| 29 | +runs: |
| 30 | + using: "composite" |
| 31 | + |
| 32 | + steps: |
| 33 | + |
| 34 | + - name: Generate markdown |
| 35 | + id: generate |
| 36 | + # Using PowerShell |
| 37 | + shell: pwsh |
| 38 | + # sec: sanatize inputs using environment variables |
| 39 | + env: |
| 40 | + GITHUB_ACTION_PATH: ${{ github.action_path }} |
| 41 | + GITHUB_WORKSPACE: ${{ github.workspace }} |
| 42 | + # INPUT_<VARIABLE_NAME> is not available in Composite run steps |
| 43 | + # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 |
| 44 | + INPUT_AB_ROOT: ${{ inputs.ab-root }} |
| 45 | + INPUT_FILES: ${{ inputs.files }} |
| 46 | + INPUT_SEPARATOR: ${{ inputs.separator }} |
| 47 | + INPUT_APPEND_HEADING: ${{ inputs.append-heading }} |
| 48 | + run: | |
| 49 | + $text = "" |
| 50 | +
|
| 51 | + # Handle optional heading |
| 52 | + if ("true" -eq $env:INPUT_APPEND_HEADING) { |
| 53 | + $text += "### Report of Checked URLs!" |
| 54 | + $text += "`n`n" |
| 55 | + $text += "<div align=`"right`" markdown=`"1`">`n`n" |
| 56 | + $text += "_Link issues :rocket: powered by [``awesome_bot``](https://github.com/dkhamsing/awesome_bot)_." |
| 57 | + $text += "`n`n</div>" |
| 58 | + } |
| 59 | +
|
| 60 | + # Loop ForEach files |
| 61 | + $env:INPUT_FILES -split $env:INPUT_SEPARATOR | ForEach { |
| 62 | + $file = $_ |
| 63 | + $abr_file = $env:INPUT_AB_ROOT + "/ab-results-" + ($file -replace "[/\\]","-") + "-markdown-table.json" |
| 64 | + $json = Get-Content $abr_file | ConvertFrom-Json |
| 65 | +
|
| 66 | + $text += "`n`n" |
| 67 | + if ("true" -eq $json.error) { |
| 68 | + # Highlighting issues counter |
| 69 | + $SearchExp = '(?<Num>\d+)' |
| 70 | + $ReplaceExp = '**${Num}**' |
| 71 | + $text += "`:page_facing_up: File: ``" + $file + "`` (:warning: " + ($json.title -replace $SearchExp,$ReplaceExp) + ")" |
| 72 | + # removing where ab attribution lives (moved to report heading) |
| 73 | + $text += $json.message -replace "####.*?\n","`n" |
| 74 | + } else { |
| 75 | + $text += ":page_facing_up: File: ``" + $file + "`` (:ok: **No issues**)" |
| 76 | + } |
| 77 | + } |
| 78 | +
|
| 79 | + # HACK to single line strings (https://trstringer.com/github-actions-multiline-strings/) |
| 80 | + $text = $text -replace "`%","%25" |
| 81 | + $text = $text -replace "`n","%0A" |
| 82 | + $text = $text -replace "`r","%25" |
| 83 | + # set output |
| 84 | + echo "::set-output name=text::$text" |
| 85 | +
|
| 86 | +
|
| 87 | + - name: Write output |
| 88 | + if: ${{ fromJson(inputs.write) }} |
| 89 | + shell: bash |
| 90 | + env: |
| 91 | + INPUT_TEXT: ${{ steps.generate.outputs.text }} |
| 92 | + INPUT_WRITE: ${{ inputs.write }} |
| 93 | + run: | |
| 94 | + echo "$INPUT_TEXT" >> $GITHUB_STEP_SUMMARY |
0 commit comments