From 73c0e1c02ec815abe3767a263fbea352f4ad19f8 Mon Sep 17 00:00:00 2001 From: Uday Vidyadharan <55924756+uvidyadharan@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:35:19 -0400 Subject: [PATCH] Diff Linkchecker (#301) --- .github/workflows/link-check.yaml | 5 +- .github/workflows/pull-request.yaml | 75 ++++++++++++++++++++++++++--- dependencies | 1 + docs/requirements.txt | 1 - 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/.github/workflows/link-check.yaml b/.github/workflows/link-check.yaml index bde0d5c6..64298e00 100644 --- a/.github/workflows/link-check.yaml +++ b/.github/workflows/link-check.yaml @@ -27,10 +27,7 @@ jobs: - name: Arhive Log if: ${{ failure() }} uses: actions/upload-artifact@v2 - env: - PR_NUMBER: ${{ github.event.number }} - ID: ${{ github.run_attempt }} with: - name: LINKCHECK-${{ env.PR_NUMBER }}-${{ env.ID }} + name: LINKCHECK--1 path: docs/build/linkcheck/output.txt retention-days: 7 diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 1869144f..49f20efc 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -98,17 +98,80 @@ jobs: - name: Python Install Dependencies run: pip install -r docs/requirements.txt + - name: Install additional dependencies + run: | + sudo apt-get update + sudo apt-get install -y jq unzip + + - name: Download previous artifact + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + curl -s -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/$GITHUB_REPOSITORY/actions/artifacts?per_page=100" > artifacts.json + + DOWNLOAD_URL=$(jq -r '.artifacts[] | select(.name | startswith("LINKCHECK--")) | .archive_download_url' artifacts.json | head -n 1) + + if [ -z "$DOWNLOAD_URL" ]; then + echo "No previous LINKCHECK artifact found" + exit 0 + fi + + curl -L \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -o linkcheck.zip "$DOWNLOAD_URL" + + if [ $? -ne 0 ]; then + echo "Failed to download the zip file" + exit 0 + fi + + if unzip -t linkcheck.zip >/dev/null 2>&1; then + unzip -q linkcheck.zip -d linkcheck_contents + echo "Successfully downloaded and unzipped previous LINKCHECK artifact" + else + echo "Downloaded file is not a valid zip. Skipping unzip." + rm linkcheck.zip + mkdir -p linkcheck_contents + fi + - name: link-check - run: make -C docs/ linkcheck SPHINXOPTS="-W --keep-going -n -q" + run: | + make -C docs/ linkcheck SPHINXOPTS="-W --keep-going -n -q" || true + + - name: Compare outputs + run: | + echo "Archived Errors" + cat linkcheck_contents/output.txt + echo "PR Errors" + cat docs/build/linkcheck/output.txt + + if [ -f linkcheck_contents/output.txt ]; then + sort linkcheck_contents/output.txt > old_sorted.txt + sort docs/build/linkcheck/output.txt > new_sorted.txt + new_errors=$(comm -13 old_sorted.txt new_sorted.txt) + if [ -n "$new_errors" ]; then + echo "New errors found:" + echo "$new_errors" + exit 1 + else + echo "No new errors found." + fi + else + echo "No previous output.txt found. Treating all current errors as new." + cat docs/build/linkcheck/output.txt + [ -s docs/build/linkcheck/output.txt ] && exit 1 || exit 0 + fi - name: Archive Log - if: ${{ failure() }} + if: always() uses: actions/upload-artifact@v2 - env: - PR_NUMBER: ${{ github.event.number }} - ID: ${{ github.run_attempt }} with: - name: LINKCHECK + name: LINKCHECK-PR-${{ github.event.number }}-${{ github.run_attempt }} path: docs/build/linkcheck/output.txt retention-days: 7 diff --git a/dependencies b/dependencies index 82dbd8bf..f967d3f3 100644 --- a/dependencies +++ b/dependencies @@ -1,4 +1,5 @@ texlive-xetex latexmk jq +unzip fonts-roboto \ No newline at end of file diff --git a/docs/requirements.txt b/docs/requirements.txt index 54c484bc..24b7fe8f 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -9,5 +9,4 @@ git+https://github.com/FIRST-Tech-Challenge/ftcdocs-helper@main#subdirectory=coo sphinx-sitemap==2.3.0 python-git-info==0.8.3 sphinxcontrib-mermaid==0.9.2 -sphinxext-linkcheckdiff==0.1.0 sphinxext-rediraffe==0.2.7