Repository navigation
[CI] Move lychee link checker to nightly workflow - #3158
Conversation
[ghstack-poisoned]
fegin
left a comment
There was a problem hiding this comment.
I think the main issue is that lychee is quite flaky due to external network issues. I'm not sure how much signals lychee can give us for per-PR run if we only run on the modified files, which 99% of the time don't contain links.
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced. Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness. ghstack-source-id: 8cba300 Pull-Request: #3158
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ['3.10'] | ||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Update pip | ||
| run: python -m pip install --upgrade pip | ||
|
|
||
| - name: Install Lychee (Latest Release) | ||
| run: | | ||
| # Query GitHub API for the latest release tag | ||
| LATEST_TAG=$(curl -s https://api.github.com/repos/lycheeverse/lychee/releases/latest | jq -r .tag_name) | ||
| echo "Installing Lychee version: $LATEST_TAG" | ||
|
|
||
| URL="https://github.com/lycheeverse/lychee/releases/download/${LATEST_TAG}/lychee-x86_64-unknown-linux-gnu.tar.gz" | ||
|
|
||
| # Load the archive, extract into temp folder, move the binary, delete the rest | ||
| mkdir -p lychee_install | ||
| curl -sLO "$URL" | ||
| tar -xzf "lychee-x86_64-unknown-linux-gnu.tar.gz" -C lychee_install --strip-components=1 | ||
| sudo mv lychee_install/lychee /usr/local/bin/ | ||
| rm -rf lychee_install "lychee-x86_64-unknown-linux-gnu.tar.gz" | ||
|
|
||
| # Verify installation | ||
| lychee --version | ||
|
|
||
| - name: Install pre-commit | ||
| run: | | ||
| python -m pip install -r requirements-dev.txt | ||
| pre-commit install-hooks | ||
|
|
||
| - name: Check links with Lychee | ||
| run: | | ||
| pre-commit run lychee-link-checker --all-files |
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced. Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness. ghstack-source-id: 8cba300 Pull-Request: #3158
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced. Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness. ghstack-source-id: 8cba300 Pull-Request: #3158
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced. Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness. ghstack-source-id: 8cba300 Pull-Request: #3158
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced. Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness. ghstack-source-id: 8cba300 Pull-Request: #3158
|
@Andrei-Aksionov wdyt? |
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced. Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness. ghstack-source-id: f51a303 Pull-Request: #3158
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced. Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness. ghstack-source-id: f51a303 Pull-Request: #3158
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced. Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness. ghstack-source-id: a0a848b Pull-Request: #3158
|
I update the per-PR lychee to run only the local links. I still keep the full run nightly check. Let me know if you want to delete it. |
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0) (oldest at bottom): * __->__ pytorch#3158 The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move it out of per-PR lint into a dedicated nightly workflow so flakes no longer block PRs but broken links still get surfaced.
|
Oh, I see. To ensure consistent behavior between local environments and CI, and to prevent transient network failures from blocking the workflows, I suggest the following options: 1. Fail only on 404 (Not Found)We can configure Lychee to accept most HTTP error codes except for 2. Implement Lychee CachingLychee supports caching results in a simple CSV-formatted file (
3. Maintain a "Nightly" ActionEven if we decide to fail only on
|
Hey there 👋 As explained in [#3158](#3158 (comment)), this PR refactors the Lychee link-checking logic to eliminate flaky CI failures while significantly improving execution speed. <br> ## 1. Multi-Tier Check Strategy The "Commit-time" experience is now separated from "Infrastructure monitoring" to ensure the development flow is not blocked by external outages. * **Pre-commit (Local & PR CI):** Configured to **fail only on 404**. Codes like `502` (e.g., "GitHub Unicorns") are accepted to prevent transient failures from stalling the workflow. * **Nightly CI:** Performs a strict check (accepting only `200`, `403`, `429`, `503`) with high persistence. It retries for up to **30 minutes**, outlasting most service outages. This run populates the cache with verified statuses that later can be reused in other workflow runs. <br> ## 2. The Cache Lifecycle: Why `key` and `restore-keys` are Necessary To understand the necessity of a dynamic `key` and the `restore-keys` fallback, one must first recognize that **GitHub Actions caches are immutable**. ### The Problem with Static Keys If a static key like `key: lychee-cache` is used without any dynamic parts, the workflow encounters a "Cache Hit" lock: 1. **The First Run:** GitHub creates the `.lycheecache` file and saves it as `lychee-cache`. 2. **Subsequent Runs:** GitHub finds an exact match for `lychee-cache` and downloads it. Because GitHub cannot update an existing cache, any new links or status updates discovered during the run are **discarded**. 3. **The "Stale Cache" Effect:** Over time, the cache becomes frozen in the state of the first run. Fixed links remain marked as "broken," and new links are re-checked every single time, slowing down CI. ### The Solution: Dynamic Keys & Branch Isolation GitHub restricts cache access based on branches: the **Default Branch** (`main`) is accessible by all, while **Feature Branches** can only access their own caches or the default branch's cache. By using a dynamic key (e.g., `cache-lychee-${{ github.sha }}`) combined with `restore-keys`, the process moves through two distinct phases: - **Restore** (start of job) - **Save** (end of job). #### Step-by-Step Lifecycle (3-Commit Example) | Phase | Commit 1: The "Inheritance" | Commit 2: The "Update" | Commit 3: The "Iteration" | | :--- | :--- | :--- | :--- | | **Restore** | Misses `cache-lychee-SHA1`. Falls back to `restore-keys` to pull the latest `main` cache that matches `cache-lychee-` pattern. | Misses `SHA2`. Pulls the most recent match from the branch scope (**SHA1**). | Misses `SHA3`. Pulls the latest available version from the branch (**SHA2**). | | **Action** | Lychee runs, checks only new links, and uses the inherited cache for the rest. | Lychee updates results with any new findings. | Lychee uses the `SHA2` baseline, ensuring zero redundant checks. | | **Save** | GitHub saves a **new** cache entry: `lychee-cache-SHA1`. | GitHub saves a new immutable entry: `lychee-cache-SHA2`. | GitHub saves the final state: `lychee-cache-SHA3`. | > [!NOTE] > This "chaining" effect ensures every commit builds upon the previous one, while keeping PR runs fast and the nightly "source of truth" accessible. <br> ## 3. Optimization: Parallelism & Output Previously, the configuration relied on `require_serial: true` and `verbose: true`. * **The Problem:** `verbose: true` was required to display the "Lychee not found" warning (since the script uses `exit 0`). However, because `pre-commit` spawns a process for every file, this caused the warning to print for every single file checked. `require_serial: true` was used to stop the log spam, but caused a **2x-3x slowdown**. * **The Fix:** An **Atomic Sentinel** is now used via `mkdir /tmp/lychee_lock`. Because `mkdir` is an atomic operation, only the first process successfully creates the directory and prints the warning. All other parallel processes fail to create the directory and remain silent. * **The Result:** `require_serial` and `verbose` are now **false**. The check runs in parallel (fast), and the warning prints exactly once (clean) by redirecting directly to the user's terminal screen via `> /dev/tty`. <br> ## 4. Fix Lychee version to install In **Lychee v0.24.1**, a change in the release archive structure broke dynamic installation scripts that fetched the "Latest" release. * **Change:** The installation now uses a **fixed, verified version** to prevent upstream changes from breaking the CI pipeline. <br> ## 5. GITHUB_TOKEN The `GITHUB_TOKEN` is explicitly passed to the Lychee action and pre-commit steps. This increases the rate limit for GitHub API requests, reducing `403 Forbidden` and `429 Too Many Requests` errors when checking internal repository links. <br> ## Summary Overview | Feature | Local / PR CI | Nightly CI | | :--- | :--- | :--- | | **Failure Condition** | Only `404` | Most non-200 codes | | **Duration/Retries** | Fast (5 retries / 15 secs) | Patient (30 retries / 30 mins) | | **Execution** | Parallel (via Sentinel) | Standard Action | | **Cache Goal** | Consume & Increment | Refresh & Validate |
Stack from ghstack (oldest at bottom):
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move it out of per-PR lint into a dedicated nightly workflow so flakes no longer block PRs but broken links still get surfaced.