|
| 1 | +# This link checks Microcks website links in Markdown HTML files once per day |
| 2 | +# from: https://github.com/lycheeverse/lychee-action |
| 3 | +# link checker used is 'lychee': https://github.com/lycheeverse/lychee |
| 4 | + |
| 5 | +name: External Link Check Refactor Doc |
| 6 | +on: |
| 7 | + # This event will only trigger a workflow run if the workflow file is on the default branch. |
| 8 | + # ucomment the following line if you want to run the workflow manually |
| 9 | + # workflow_dispatch: |
| 10 | + # Run every day at 00h42 UTC (0:42 AM UTC aka 1:42 AM CEST with daylight saving time) |
| 11 | + schedule: |
| 12 | + - cron: "42 0 * * *" |
| 13 | + |
| 14 | +jobs: |
| 15 | + linkChecker: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + ref: refactor-doc-org |
| 22 | + |
| 23 | + # Setup local cache in order to mitigate issues regarding rate limiting or to reduce stress on external resources |
| 24 | + # Restore the lychee cache if it exists for the current commit |
| 25 | + - name: Restore lychee cache |
| 26 | + id: restore-cache |
| 27 | + uses: actions/cache/restore@v4 |
| 28 | + with: |
| 29 | + path: .lycheecache |
| 30 | + key: cache-lychee-${{ github.sha }} |
| 31 | + restore-keys: cache-lychee- |
| 32 | + |
| 33 | + # We do not need to build the site, so we can remove the Hugo build steps, thanks to the hugo check validation on push |
| 34 | + # However, retaining this comment for documentation purposes, just in case ;) |
| 35 | + |
| 36 | + # Link Checker run with lychee action |
| 37 | + - name: Link Checker |
| 38 | + id: lychee |
| 39 | + uses: lycheeverse/lychee-action@v1 |
| 40 | + with: |
| 41 | + # Check all markdown and html files in repo |
| 42 | + # Exclude all files except those starting with http:// or https:// thanks to the --scheme option |
| 43 | + # Use cache but cache the results for 8 hours |
| 44 | + args: --base public --verbose --no-progress './**/*.md' './**/*.html' --scheme https --scheme http --cache --max-cache-age 8h |
| 45 | + # Use markdown as output format |
| 46 | + format: markdown |
| 47 | + # Use different output file path |
| 48 | + output: ./link-checker/report.md |
| 49 | + # Use a custom GitHub token to "avoid" rate limiting |
| 50 | + token: ${{ secrets.CUSTOM_TOKEN }} |
| 51 | + # Don't fail action on broken links |
| 52 | + fail: false |
| 53 | + |
| 54 | + # Format the date for the issue title and store it in an environment variable |
| 55 | + - name: Format Date |
| 56 | + id: format_date |
| 57 | + run: echo "DATE=$(date +'%A, %e. %b %Y')" >> $GITHUB_ENV |
| 58 | + |
| 59 | + # Create an issue if there are broken links |
| 60 | + - name: Create Issue From File |
| 61 | + if: env.lychee_exit_code != 0 |
| 62 | + id: create_issue |
| 63 | + uses: peter-evans/create-issue-from-file@v5 |
| 64 | + with: |
| 65 | + title: "External Link Check Refactor Doc Report - ${{ env.DATE }}" |
| 66 | + content-filepath: ./link-checker/report.md |
| 67 | + labels: report, automated issue, contribution message, help wanted |
| 68 | + |
| 69 | + # Store the issue number in an environment variable |
| 70 | + - name: Store Issue Number |
| 71 | + if: steps.create_issue.outputs.issue-number |
| 72 | + run: echo "ISSUE_NUMBER=${{ steps.create_issue.outputs.issue-number }}" >> $GITHUB_ENV |
| 73 | + |
| 74 | + # Add a comment to the issue with the contribution message |
| 75 | + - name: Add contribution message as new comment |
| 76 | + if: ${{ env.ISSUE_NUMBER }} is not null |
| 77 | + run: gh issue comment "$NUMBER" --body-file "$BODY" |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + GH_REPO: ${{ github.repository }} |
| 81 | + NUMBER: ${{ env.ISSUE_NUMBER }} |
| 82 | + BODY: ".github/contribution_message.md" |
| 83 | + |
| 84 | + # Save the lychee cache for the next run |
| 85 | + - name: Save lychee cache |
| 86 | + uses: actions/cache/save@v4 |
| 87 | + if: always() |
| 88 | + with: |
| 89 | + path: .lycheecache |
| 90 | + key: ${{ steps.restore-cache.outputs.cache-primary-key }} |
0 commit comments