Pages render check only runs on changed files (#913)

Closes https://github.com/Qiskit/documentation/issues/886. As explained
there, it's safe to only run this check on changed files because whether
a page renders is independent from all the other pages.

We use a weekly cron job, though, to check all pages. That reduces our
risk from things like the docs preview Docker image changing on us and
resulting in some pages now failing to render.

--

This PR also stops checking external links in API docs builds and
instead moves the check to the new weekly cron job. Relates to
https://github.com/Qiskit/documentation/issues/876.

Per https://github.com/Qiskit/documentation/pull/372, it's annoying to
check external links in CI because it can be flaky
(https://github.com/Qiskit/documentation/issues/823).
This commit is contained in:
Eric Arellano 2024-02-28 07:42:34 -05:00 committed by GitHub
parent fac0c0115d
commit 2c82c0dc6a
5 changed files with 118 additions and 44 deletions

View File

@ -13,9 +13,6 @@
name: API checks name: API checks
on: on:
workflow_dispatch: workflow_dispatch:
schedule:
- cron: "0 0 * * 0,2,4" # Every Sunday, Tuesday, and Thursday at midnight UTC
pull_request: pull_request:
paths: paths:
- "docs/api/qiskit/**/*" - "docs/api/qiskit/**/*"
@ -26,7 +23,7 @@ on:
- "scripts/lib/links/ignores.ts" - "scripts/lib/links/ignores.ts"
jobs: jobs:
link-checker: api-checks:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.repository_owner == 'Qiskit' if: github.repository_owner == 'Qiskit'
steps: steps:
@ -37,7 +34,7 @@ jobs:
node-version: 18 node-version: 18
- name: Install Node.js dependencies - name: Install Node.js dependencies
run: npm ci run: npm ci
- name: Check links - name: Check internal links
run: > run: >
npm run check:links -- npm run check:links --
--qiskit-release-notes --qiskit-release-notes
@ -45,27 +42,3 @@ jobs:
--dev-apis --dev-apis
--historical-apis --historical-apis
--skip-broken-historical --skip-broken-historical
--external
pages-render:
runs-on: ubuntu-latest
if: github.repository_owner == 'Qiskit'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Node.js dependencies
run: npm ci
- name: Start local Docker preview
run: |
./start &
sleep 20
- name: Check API pages render
run: >
npm run check-pages-render --
--qiskit-release-notes
--current-apis
--dev-apis
--historical-apis

View File

@ -30,7 +30,7 @@ jobs:
run: npm run check:metadata run: npm run check:metadata
- name: Spellcheck - name: Spellcheck
run: npm run check:spelling run: npm run check:spelling
- name: Link checker - name: Internal link checker
run: npm run check:links run: npm run check:links
- name: Formatting - name: Formatting
run: npm run check:fmt run: npm run check:fmt
@ -39,9 +39,19 @@ jobs:
- name: Infrastructure tests - name: Infrastructure tests
run: npm test run: npm test
- name: Get all changed docs files
id: changed-docs-files
uses: tj-actions/changed-files@af2816c65436325c50621100d67f6e853cd1b0f1
with:
files: docs/**/*.{md,mdx,ipynb}
separator: "\n"
- name: Start local Docker preview - name: Start local Docker preview
if: steps.changed-docs-files.outputs.any_changed == 'true'
run: | run: |
./start & ./start &
sleep 20 sleep 20
- name: Check that pages render - name: Check that pages render
run: npm run check-pages-render if: steps.changed-docs-files.outputs.any_changed == 'true'
run: |
echo "${{ steps.changed-docs-files.outputs.all_changed_files }}" > changed.txt
npm run check-pages-render -- --from-file changed.txt

63
.github/workflows/weekly-checks.yml vendored Normal file
View File

@ -0,0 +1,63 @@
# This code is a Qiskit project.
#
# (C) Copyright IBM 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
name: Weekly checks
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # Every Sunday at midnight UTC
jobs:
pages-render:
runs-on: ubuntu-latest
if: github.repository_owner == 'Qiskit'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Node.js dependencies
run: npm ci
- name: Start local Docker preview
run: |
./start &
sleep 20
- name: Check all pages render
run: >
npm run check-pages-render --
--non-api
--qiskit-release-notes
--current-apis
--dev-apis
--historical-apis
external-link-checker:
runs-on: ubuntu-latest
if: github.repository_owner == 'Qiskit'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Node.js dependencies
run: npm ci
- name: Check external links
run: >
npm run check:links --
--qiskit-release-notes
--current-apis
--dev-apis
--historical-apis
--skip-broken-historical
--external

View File

@ -260,12 +260,11 @@ It's possible to write broken pages that crash when loaded. This is usually due
To check that all the non-API docs render: To check that all the non-API docs render:
1. Start up the local preview with `./start` by following the instructions at [Preview the docs locally](#preview-the-docs-locally) 1. Start up the local preview with `./start` by following the instructions at [Preview the docs locally](#preview-the-docs-locally)
2. In a new tab, `npm run check-pages-render` 2. In a new tab, `npm run check-pages-render -- --non-api`
You can also check that API docs and translations render by using any of these arguments: `npm run check-pages-render -- --qiskit-release-notes --current-apis --dev-apis --historical-apis --translations`. Warning that this is exponentially slower. You can also check that API docs and translations render by using any of these arguments: `npm run check-pages-render -- --non-api --qiskit-release-notes --current-apis --dev-apis --historical-apis --translations`. Warning that this is exponentially slower.
CI will check on every PR that non-API docs correctly render. We also run a nightly cron job to check the API docs and CI will check on every PR that any changed files render correctly. We also run a weekly cron job to check that every page renders correctly.
translations.
## Format TypeScript files ## Format TypeScript files

View File

@ -10,6 +10,8 @@
// copyright notice, and modified files need to carry a notice indicating // copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals. // that they have been altered from the originals.
import fs from "fs/promises";
import { globby } from "globby"; import { globby } from "globby";
import yargs from "yargs/yargs"; import yargs from "yargs/yargs";
import { hideBin } from "yargs/helpers"; import { hideBin } from "yargs/helpers";
@ -20,6 +22,8 @@ const PORT = 3000;
interface Arguments { interface Arguments {
[x: string]: unknown; [x: string]: unknown;
fromFile?: string;
nonApi: boolean;
currentApis: boolean; currentApis: boolean;
devApis: boolean; devApis: boolean;
historicalApis: boolean; historicalApis: boolean;
@ -30,6 +34,17 @@ interface Arguments {
const readArgs = (): Arguments => { const readArgs = (): Arguments => {
return yargs(hideBin(process.argv)) return yargs(hideBin(process.argv))
.version(false) .version(false)
.option("from-file", {
type: "string",
normalize: true,
description:
"Read the file path for file paths and globs to check, like `docs/start/index.md`. Entries should be separated by a newline and should be valid file types (.md, .mdx, .ipynb).",
})
.option("non-api", {
type: "boolean",
default: false,
description: "Check all the non-API docs, like start/.",
})
.option("current-apis", { .option("current-apis", {
type: "boolean", type: "boolean",
default: false, default: false,
@ -137,22 +152,36 @@ async function validateDockerRunning(): Promise<void> {
} }
async function determineFilePaths(args: Arguments): Promise<string[]> { async function determineFilePaths(args: Arguments): Promise<string[]> {
const globs = ["docs/**/*.{ipynb,md,mdx}"]; const globs = [];
if (!args.currentApis) { if (args.fromFile) {
globs.push("!docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/*"); const content = await fs.readFile(args.fromFile, "utf-8");
globs.push(...content.split("\n").filter((entry) => entry));
} }
if (!args.historicalApis) {
if (args.nonApi) {
globs.push( globs.push(
"!docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/[0-9]*/*", "docs/support.mdx",
"docs/{build,run,start,transpile,verify}/*.{ipynb,md,mdx}",
"docs/api/migration-guides/**/*.{ipynb,md,mdx}",
); );
} }
if (!args.devApis) { if (args.currentApis) {
globs.push( globs.push(
"!docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/dev/*", "docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/*.{ipynb,md,mdx}",
); );
} }
if (!args.qiskitReleaseNotes) { if (args.historicalApis) {
globs.push("!docs/api/qiskit/release-notes/*"); globs.push(
"docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/[0-9]*/*.{ipynb,md,mdx}",
);
}
if (args.devApis) {
globs.push(
"docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/dev/*.{ipynb,md,mdx}",
);
}
if (args.qiskitReleaseNotes) {
globs.push("docs/api/qiskit/release-notes/*.{ipynb,md,mdx}");
} }
if (args.translations) { if (args.translations) {
globs.push("translations/**/*.{ipynb,md,mdx}"); globs.push("translations/**/*.{ipynb,md,mdx}");