# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. name: Link Checker on: pull_request: permissions: contents: read jobs: link-check: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 persist-credentials: false - name: Identify Changed Files id: changed-files shell: bash run: | git fetch origin main CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT origin/main...HEAD -- '*.md') if [ -z "$CHANGED_FILES" ]; then echo "No markdown files changed. Skipping checks." echo "HAS_CHANGES=false" >> "$GITHUB_OUTPUT" else echo "--- Changed Files to Scan ---" echo "$CHANGED_FILES" echo "-----------------------------" FILES_QUOTED=$(echo "$CHANGED_FILES" | sed 's/^/"/;s/$/"/' | tr '\n' ' ') # Use EOF to write multiline or long strings to GITHUB_OUTPUT echo "HAS_CHANGES=true" >> "$GITHUB_OUTPUT" echo "CHECK_FILES<> "$GITHUB_OUTPUT" echo "$FILES_QUOTED" >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" fi - name: Restore lychee cache if: steps.changed-files.outputs.HAS_CHANGES == 'true' uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: .lycheecache key: cache-lychee-${{ github.sha }} restore-keys: cache-lychee- - name: Link Checker id: lychee-check if: steps.changed-files.outputs.HAS_CHANGES == 'true' uses: lycheeverse/lychee-action@8646ba30535128ac92d33dfc9133794bfdd9b411 # v2 continue-on-error: true with: args: > --quiet --no-progress --cache --max-cache-age 1d --exclude '^neo4j\+.*' --exclude '^bolt://.*' --max-retries 10 ${{ steps.changed-files.outputs.CHECK_FILES }} output: lychee-report.md format: markdown fail: true jobSummary: false debug: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Prepare Report if: steps.changed-files.outputs.HAS_CHANGES == 'true' && steps.lychee-check.outcome == 'failure' run: | echo "## Link Resolution Note" > full-report.md echo "Local links and directory changes work differently on GitHub than on the docsite. You must ensure fixes pass the **GitHub check** and also work with **\`hugo server\`**." >> full-report.md echo "See [Link Checking and Fixing with Lychee](https://github.com/googleapis/mcp-toolbox/blob/main/DEVELOPER.md#link-checking-and-fixing-with-lychee) for more details." >> full-report.md echo "" >> full-report.md sed -E '/(Redirect|Redirects per input)/d' lychee-report.md >> full-report.md - name: Display Failure Report # Run this ONLY if the link checker failed if: steps.lychee-check.outcome == 'failure' run: | # We can now simply output the prepared file to the job summary cat full-report.md >> $GITHUB_STEP_SUMMARY # Fail the job exit 1