Skip to content

Commit 218428f

Browse files
authored
feat: Add staleness check workflow for Platform docs (#3080)
Adds a monthly workflow that checks for stale topics in `sources/platform` and creates an issue with a list of topics that haven't been touched in the last 6 months. - Skips frontmatter-only changes, bulk commits that involve more than 10 `.md`/`.mdx` files, and commits listed in `.staleness-check-ignore`. - Excludes topics with a `last_review` frontmatter field with a date set to or after the cutoff. [Internal doc with explanation](https://app.notion.com/p/apify/Staleness-check-406f39950a22806c90dcd2394e02f03e). How a resulting issue looks like: #3081 Closes #3009
1 parent 6f4b58f commit 218428f

3 files changed

Lines changed: 183 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Docs staleness check
2+
3+
on:
4+
schedule:
5+
- cron: '0 6 1 * *' # Run monthly
6+
workflow_dispatch: # Allow manual triggering
7+
8+
permissions:
9+
contents: read
10+
issues: write
11+
12+
jobs:
13+
staleness-check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
17+
with:
18+
fetch-depth: 0 # The check reads commit history of each page
19+
20+
- name: Use Node.js 24
21+
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
22+
with:
23+
node-version: 24
24+
25+
- name: Find stale pages
26+
run: node scripts/checkStaleness.mjs > staleness-report.md
27+
28+
- name: Open report issue
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
run: |
32+
gh issue create \
33+
--title "Stale platform docs - $(date -u +'%B %Y')" \
34+
--body-file staleness-report.md \
35+
--label t-docs \
36+
--assignee szaganek

‎.staleness-check-ignore‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Commits that shouldn't count as content edits under the staleness check.
2+
# One commit SHA per line, with a comment saying what it was.
3+
#
4+
# Skipped automatically: commits that change more than 10 .md/.mdx files at once,
5+
# frontmatter-only changes, page moves.
6+
7+
8+
# fix malformed external URLs missing platform subdomain (#2880)
9+
0a123c7a
10+
11+
# replace support email with contact link (#2564)
12+
63d8c824
13+
14+
# update MCP CLI repository URL, link label casing (#2556)
15+
35400cc4
16+
17+
# move monetization pages under Actors, update nav links (#2846)
18+
38ab907f

‎scripts/checkStaleness.mjs‎

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Finds platform docs pages whose content hasn't been edited in STALE_AFTER_MONTHS
2+
// and prints a Markdown report.
3+
//
4+
// The script ignores commits that:
5+
// - change more than BULK_FILE_LIMIT .md/.mdx files at once
6+
// - are listed in IGNORE_FILE
7+
// - only change a page's frontmatter, or move a page without changing it
8+
//
9+
// If none of a page's commits count, its newest commit is used instead.
10+
//
11+
// Pages with a `last_review: YYYY-MM-DD` frontmatter field with a date on or
12+
// after the cutoff are skipped.
13+
//
14+
// Requires the full git history (fetch-depth: 0 in GitHub Actions).
15+
16+
import { execFileSync } from 'node:child_process';
17+
import fs from 'node:fs';
18+
19+
const DOCS_DIR = 'sources/platform';
20+
const STALE_AFTER_MONTHS = 6;
21+
const BULK_FILE_LIMIT = 10;
22+
const IGNORE_FILE = '.staleness-check-ignore';
23+
const REPO_URL = 'https://github.com/apify/apify-docs';
24+
25+
const FRONTMATTER = /^---\r?\n[\s\S]*?\r?\n---(\r?\n|$)/;
26+
const LAST_REVIEW = /^last_review:\s*['"]?(\d{4}-\d{2}-\d{2})['"]?\s*$/m;
27+
28+
const isDocFile = (file) => /\.mdx?$/.test(file);
29+
30+
// 'pipe' keeps git's error messages out of the log. Thrown errors still include them.
31+
const git = (...args) => execFileSync('git', args, { encoding: 'utf8', stdio: 'pipe', maxBuffer: 16 * 1024 * 1024 });
32+
33+
function readIgnoredRevs() {
34+
return fs
35+
.readFileSync(IGNORE_FILE, 'utf8')
36+
.split('\n')
37+
.map((line) => line.replace(/#.*/, '').trim())
38+
.filter(Boolean);
39+
}
40+
41+
function findBulkCommits() {
42+
const bulk = new Set();
43+
// git prints each commit as "\0<sha>", followed by the files it changed, one per line
44+
for (const entry of git('log', '--format=%x00%H', '--name-only').split('\0').slice(1)) {
45+
const [sha, ...files] = entry.split('\n').filter(Boolean);
46+
if (files.filter(isDocFile).length > BULK_FILE_LIMIT) bulk.add(sha);
47+
}
48+
return bulk;
49+
}
50+
51+
function pageBodyAt(sha, path) {
52+
try {
53+
return git('show', `${sha}:${path}`).replace(FRONTMATTER, '');
54+
} catch (error) {
55+
// The page was moved away in this commit and later recreated at the same path
56+
if (error.stderr?.includes('does not exist in')) return null;
57+
throw error;
58+
}
59+
}
60+
61+
// A missing or malformed date returns undefined, so the page is checked as usual
62+
function lastReview(file) {
63+
const frontmatter = fs.readFileSync(file, 'utf8').match(FRONTMATTER)?.[0] ?? '';
64+
return frontmatter.match(LAST_REVIEW)?.[1];
65+
}
66+
67+
function lastContentEdit(file) {
68+
// git prints each commit as "\0<sha> <date>", followed by the page's path in that commit.
69+
// The path differs from `file` if the page was renamed later. Any other git error stops the script.
70+
const commits = git('log', '--follow', '--format=%x00%H %cs', '--name-only', '--', file)
71+
.split('\0')
72+
.slice(1)
73+
.map((entry) => {
74+
const [header, path] = entry.split('\n').filter(Boolean);
75+
const [sha, date] = header.split(' ');
76+
return { sha, date, path };
77+
});
78+
// A commit edits content if the page body differs from the page's previous commit
79+
const editsContent = ({ sha, path }, i) => {
80+
const previous = commits[i + 1];
81+
if (!previous) return true;
82+
const body = pageBodyAt(sha, path);
83+
return body === null || body !== pageBodyAt(previous.sha, previous.path);
84+
};
85+
return commits.find((commit, i) => !isSkipped(commit.sha) && editsContent(commit, i)) ?? commits[0];
86+
}
87+
88+
const ignoredRevs = readIgnoredRevs();
89+
const bulkCommits = findBulkCommits();
90+
const isSkipped = (sha) => bulkCommits.has(sha) || ignoredRevs.some((rev) => sha.startsWith(rev));
91+
92+
const cutoff = new Date();
93+
cutoff.setMonth(cutoff.getMonth() - STALE_AFTER_MONTHS);
94+
const cutoffDate = cutoff.toISOString().slice(0, 10);
95+
96+
const stalePages = git('ls-files', DOCS_DIR)
97+
.trim()
98+
.split('\n')
99+
.filter(isDocFile)
100+
.filter((file) => !(lastReview(file) >= cutoffDate))
101+
.map((file) => ({ file, ...lastContentEdit(file) }))
102+
.filter(({ date }) => date < cutoffDate)
103+
.sort((a, b) => a.date.localeCompare(b.date));
104+
105+
const bySection = new Map();
106+
for (const page of stalePages) {
107+
const section = page.file.split('/')[2];
108+
if (!bySection.has(section)) bySection.set(section, []);
109+
bySection.get(section).push(page);
110+
}
111+
112+
const lines = [
113+
`${stalePages.length} pages in \`${DOCS_DIR}\` haven't been edited since ${cutoffDate}.`,
114+
'',
115+
`Frontmatter-only changes, and commits that change more than ${BULK_FILE_LIMIT} \`.md\`/\`.mdx\` files or are listed in \`${IGNORE_FILE}\`, don't count as edits.`,
116+
'',
117+
`If a page is still correct, add \`last_review: YYYY-MM-DD\` to its frontmatter. The check will skip it for ${STALE_AFTER_MONTHS} months from the review date.`,
118+
];
119+
for (const section of [...bySection.keys()].sort()) {
120+
const pages = bySection.get(section);
121+
lines.push('', `## ${section} (${pages.length})`, '');
122+
for (const { file, sha, date } of pages) {
123+
lines.push(
124+
`- [${file.slice(DOCS_DIR.length + 1)}](${REPO_URL}/blob/master/${file}) - [last edited ${date}](${REPO_URL}/commit/${sha})`,
125+
);
126+
}
127+
}
128+
129+
console.log(lines.join('\n'));

0 commit comments

Comments
 (0)