Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci[minor]: Add GitHub action to check broken links #403

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
57 changes: 57 additions & 0 deletions .github/workflows/link_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Check Docs & Links

on:
push:
branches: ["main"]
pull_request:
paths:
- '**.ipynb'
schedule:
- cron: "0 5 * * *"
workflow_dispatch:

env:
POETRY_VERSION: "1.7.1"

jobs:
markdown-link-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check links in Markdown files
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
folder-path: "examples/,docs/"
check-modified-files-only: ${{ github.event_name != 'schedule' }}
file-path: "./README.md"
config-file: "./.markdown-link-check.config.json"

notebook-link-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'yarn'

- name: Install dependencies
run: |
yarn install --frozen-lockfile

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35

- name: Check links in notebooks
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
yarn check-links
4 changes: 4 additions & 0 deletions .markdown-link-check.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"aliveStatusCodes": [200, 206, 402],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do ranges? We prob want all 200's, all 300's, etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my brief chat-gpt research it's not easily doable programatically. I just copied this from the main langgraph one so I assume someone smarter than me had a good reason for selecting these codes but idk

"ignorePatterns": ["*dcbadge.vercel.app*"]
}
2 changes: 1 addition & 1 deletion examples/how-tos/breakpoints.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"\n",
"Below, we do two things:\n",
"\n",
"1) We specify the [breakpoint](https://langchain-ai.github.io/langgraph/concepts/low_level/#breakpoints) using `interruptBefore` the specified step.\n",
"1) We specify the [breakpoint](https://langchain-ai.github.io/langgraph/concepts/low_level/#breakpoints2) using `interruptBefore` the specified step.\n",
"\n",
"2) We set up a [checkpointer](https://langchain-ai.github.io/langgraphjs/concepts/#checkpoints) to save the state of the graph."
]
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"test:exports:docker": "docker compose -f environment_tests/docker-compose.yml up --force-recreate",
"format": "turbo run format",
"format:check": "turbo run format:check",
"release": "node scripts/release_workspace.cjs --workspace"
"release": "node scripts/release_workspace.cjs --workspace",
"check-links": "node scripts/check-links.cjs"
},
"author": "LangChain",
"license": "MIT",
Expand All @@ -41,6 +42,8 @@
"cheminfo-types": "^1.4.0",
"d3": "^7.9.0",
"esm-hook": "^0.1.4",
"linkinator": "^4.0.5",
"markdown-link-check": "^3.10.3",
"readline": "^1.3.0",
"release-it": "^17.6.0",
"semver": "^7.6.3",
Expand All @@ -59,5 +62,8 @@
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"linkinator": "^6.1.1"
}
}
30 changes: 30 additions & 0 deletions scripts/check-links.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { execSync } = require('child_process');

const ignorePatterns = [
'https://(api|web)\\.smith\\.langchain\\.com/.*',
'https://x\\.com/.*'
];

function checkLinks() {
const changedFiles = process.env.CHANGED_FILES ? process.env.CHANGED_FILES.split(' ') : [];
const ipynbFiles = changedFiles.filter(file => file.endsWith('.ipynb'));

console.log('Changed .ipynb files:', ipynbFiles);

if (ipynbFiles.length === 0) {
console.log('No .ipynb files were changed. Skipping link check.');
return;
}

for (const file of ipynbFiles) {
console.log(`Checking links in ${file}`);
try {
execSync(`yarn linkinator ${file} ${ignorePatterns.map(pattern => `--skip "${pattern}"`).join(' ')}`, { stdio: 'inherit' });
} catch (error) {
console.error(`Error checking links in ${file}:`, error);
process.exit(1);
}
}
}

checkLinks();
Loading
Loading