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

Pages render check only runs on changed files #913

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions .github/workflows/api-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
name: API checks
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0,2,4" # Every Sunday, Tuesday, and Thursday at midnight UTC

pull_request:
paths:
- "docs/api/qiskit/**/*"
Expand All @@ -26,7 +23,7 @@ on:
- "scripts/lib/links/ignores.ts"

jobs:
link-checker:
api-checks:
runs-on: ubuntu-latest
if: github.repository_owner == 'Qiskit'
steps:
Expand All @@ -37,35 +34,11 @@ jobs:
node-version: 18
- name: Install Node.js dependencies
run: npm ci
- name: Check links
- name: Check internal links
run: >
npm run check:links --
--qiskit-release-notes
--current-apis
--dev-apis
--historical-apis
--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
14 changes: 12 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: npm run check:metadata
- name: Spellcheck
run: npm run check:spelling
- name: Link checker
- name: Internal link checker
run: npm run check:links
- name: Formatting
run: npm run check:fmt
Expand All @@ -39,9 +39,19 @@ jobs:
- name: Infrastructure tests
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
if: steps.changed-docs-files.outputs.any_changed == 'true'
run: |
./start &
sleep 20
- 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
Copy link
Member

Choose a reason for hiding this comment

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

Nice solution

npm run check-pages-render -- --from-file changed.txt
63 changes: 63 additions & 0 deletions .github/workflows/weekly-checks.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

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-apis`
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved

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-apis --qiskit-release-notes --current-apis --dev-apis --historical-apis --translations`. Warning that this is exponentially slower.
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved

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
translations.
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.

## Format TypeScript files

Expand Down
47 changes: 38 additions & 9 deletions scripts/commands/checkPagesRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.

import fs from "fs/promises";

import { globby } from "globby";
import yargs from "yargs/yargs";
import { hideBin } from "yargs/helpers";
Expand All @@ -20,6 +22,8 @@ const PORT = 3000;

interface Arguments {
[x: string]: unknown;
fromFile?: string;
nonApi: boolean;
currentApis: boolean;
devApis: boolean;
historicalApis: boolean;
Expand All @@ -30,6 +34,17 @@ interface Arguments {
const readArgs = (): Arguments => {
return yargs(hideBin(process.argv))
.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", {
type: "boolean",
default: false,
Expand Down Expand Up @@ -137,22 +152,36 @@ async function validateDockerRunning(): Promise<void> {
}

async function determineFilePaths(args: Arguments): Promise<string[]> {
const globs = ["docs/**/*.{ipynb,md,mdx}"];
if (!args.currentApis) {
globs.push("!docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/*");
const globs = [];
if (args.fromFile) {
const content = await fs.readFile(args.fromFile, "utf-8");
globs.push(...content.split("\n").filter((entry) => entry));
}

if (args.nonApi) {
globs.push(
"docs/support.mdx",
"docs/{build,run,start,transpile,verify}/*.{ipynb,md,mdx}",
"docs/api/migration-guides/**/*.{ipynb,md,mdx}",
);
}
if (args.currentApis) {
globs.push(
"docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/*.{ipynb,md,mdx}",
);
}
if (!args.historicalApis) {
if (args.historicalApis) {
globs.push(
"!docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/[0-9]*/*",
"docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/[0-9]*/*.{ipynb,md,mdx}",
);
}
if (!args.devApis) {
if (args.devApis) {
globs.push(
"!docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/dev/*",
"docs/api/{qiskit,qiskit-ibm-provider,qiskit-ibm-runtime}/dev/*.{ipynb,md,mdx}",
);
}
if (!args.qiskitReleaseNotes) {
globs.push("!docs/api/qiskit/release-notes/*");
if (args.qiskitReleaseNotes) {
globs.push("docs/api/qiskit/release-notes/*.{ipynb,md,mdx}");
}
if (args.translations) {
globs.push("translations/**/*.{ipynb,md,mdx}");
Expand Down
Loading