check-urls.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. name: Check URLs from changed files
  2. on:
  3. push:
  4. pull_request:
  5. permissions:
  6. # needed for checkout code
  7. contents: read
  8. # This allows a subsequently queued workflow run to interrupt/wait for previous runs
  9. concurrency:
  10. group: '${{ github.workflow }} @ ${{ github.run_id }}'
  11. cancel-in-progress: false # true = interrupt, false = wait
  12. jobs:
  13. # NOTE: tj-actions/changed-files.
  14. # For push events you need to include fetch-depth: 0 | 2 depending on your use case.
  15. # 0: retrieve all history for all branches and tags
  16. # 1: retrieve only current commit (by default)
  17. # 2: retrieve until the preceding commit
  18. get-changed-files:
  19. name: Get changed files
  20. runs-on: ubuntu-latest
  21. outputs:
  22. fetch-depth: ${{ steps.set-params.outputs.fetch-depth }}
  23. files: ${{ steps.set-files.outputs.files }}
  24. files-len: ${{ steps.set-files.outputs.files-len }}
  25. matrix: ${{ steps.set-matrix.outputs.matrix }}
  26. steps:
  27. - name: Determine workflow params
  28. id: set-params
  29. run: |
  30. echo "fetch_depth=0" >> $GITHUB_OUTPUT
  31. if [ "${{ github.event_name }}" == "pull_request" ]; then
  32. echo "fetch_depth=0" >> $GITHUB_OUTPUT
  33. fi
  34. - name: Checkout
  35. uses: actions/checkout@v4
  36. with:
  37. fetch-depth: ${{ steps.set-params.outputs.fetch-depth }}
  38. - name: Get changed files
  39. id: changed-files
  40. uses: tj-actions/changed-files@v45.0.4
  41. with:
  42. separator: " "
  43. json: true
  44. - id: set-files
  45. run: |
  46. echo "${{ steps.changed-files.outputs.all_changed_files }}" \
  47. | jq --raw-output '. | join(" ")' \
  48. | sed -e 's/^/files=/' \
  49. >> $GITHUB_OUTPUT
  50. echo "${{ steps.changed-files.outputs.all_changed_files }}" \
  51. | jq --raw-output '. | length' \
  52. | sed -e 's/^/files-len=/' \
  53. >> $GITHUB_OUTPUT
  54. - id: set-matrix
  55. run: |
  56. echo "{\"file\":${{ steps.changed-files.outputs.all_changed_files }}}" \
  57. | sed -e 's/^/matrix=/' \
  58. >> $GITHUB_OUTPUT
  59. check-urls:
  60. name: Check @ ${{ matrix.file }}
  61. if: ${{ fromJSON(needs.get-changed-files.outputs.files-len) > 0 }}
  62. needs: [get-changed-files]
  63. runs-on: ubuntu-latest
  64. strategy:
  65. matrix: ${{ fromJSON(needs.get-changed-files.outputs.matrix) }}
  66. max-parallel: 10
  67. fail-fast: false
  68. steps:
  69. - name: Checkout
  70. uses: actions/checkout@v4
  71. with:
  72. fetch-depth: ${{ needs.get-changed-files.outputs.fetch-depth }}
  73. - name: Setup Ruby v2.6
  74. uses: ruby/setup-ruby@v1
  75. with:
  76. ruby-version: 2.6
  77. - name: Install awesome_bot
  78. run: |
  79. gem install awesome_bot
  80. - name: Set output
  81. id: set-output
  82. # FILENAME takes the complete file path and strips everything before the final '/'
  83. # FILEPATH replaces all '/' with '-' in the file path since '/' is not allowed in upload artifact name
  84. # Due to a bug in actions/download-artifact, we need to rename README.md to BASE_README.md
  85. run: |
  86. echo "FILENAME=$(echo ${{ matrix.file }} | grep -oE '[a-zA-Z0-9_-]+(\.yml|\.md)')" >> "$GITHUB_OUTPUT"
  87. file_path="${{ matrix.file }}"
  88. file_path="${file_path//\//-}"
  89. if [[ "$file_path" == "README.md" ]]; then
  90. file_path="BASE_README.md"
  91. fi
  92. echo "FILEPATH=${file_path}" >> "$GITHUB_OUTPUT"
  93. - name: "Check URLs of file: ${{ matrix.file }}"
  94. run: |
  95. awesome_bot "${{ matrix.file }}" --allow-redirect --allow-dupe --allow-ssl || true;
  96. - uses: actions/upload-artifact@v4
  97. with:
  98. name: ${{ steps.set-output.outputs.FILEPATH }}
  99. path: ${{ github.workspace }}/ab-results-*.json
  100. reporter:
  101. name: GitHub report
  102. needs: [get-changed-files, check-urls]
  103. runs-on: ubuntu-latest
  104. steps:
  105. - name: Checkout # for having the sources of the local action
  106. uses: actions/checkout@v4
  107. # download and unzip the ab-results-*.json generated by job-matrix: check-urls
  108. - name: Download artifacts
  109. uses: actions/download-artifact@v4
  110. - name: Generate Summary Report
  111. uses: ./.github/actions/awesomebot-gh-summary-action
  112. with:
  113. ab-root: ${{ github.workspace }}
  114. files: ${{ needs.get-changed-files.outputs.files }}
  115. separator: " "
  116. append-heading: ${{ true }}