From 66c82d66e9d550170b36e681ea23b7dbc0019e13 Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Fri, 11 Oct 2024 20:58:00 +0530 Subject: [PATCH 1/5] add link checker workflow --- .github/workflows/link-checker.yml | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/link-checker.yml diff --git a/.github/workflows/link-checker.yml b/.github/workflows/link-checker.yml new file mode 100644 index 0000000..5a13d8f --- /dev/null +++ b/.github/workflows/link-checker.yml @@ -0,0 +1,90 @@ +name: Link Checker +on: + repository_dispatch: + workflow_dispatch: + schedule: '0 0 1 * *' # Run at midnight on the first of every month +jobs: + linkChecker: + name: Check and report broken links + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Corepack enable + run: corepack enable + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Get Token + uses: actions/create-github-app-token@v1 + id: get_workflow_token + with: + app-id: ${{ vars.APP_ID }} + private-key: ${{ secrets.PRIVATE_KEY }} + + - name: Install Dependencies + run: yarn install --immutable + + - name: Serve App Locally + run: yarn run dev & + + - name: Wait for App to Start + run: sleep 20 + + # This will restore the lychee cache + - name: Restore lychee cache + uses: actions/cache@v4 + with: + path: .lycheecache + key: cache-lychee-${{ github.sha }} + restore-keys: cache-lychee- + + # This will run the link checker on all markdown files in the pages directory + - name: Link Checker + id: lychee + uses: lycheeverse/lychee-action@v1 + with: + args: --base https://json-schema.org --verbose --no-progress --accept 200,204,429,403 './content/**/*.mdx' --cache --max-cache-age 1d https://json-schema.org + token: ${{secrets.GITHUB_TOKEN}} + + - name: Install Octokit + run: yarn add @octokit/core@5.1.0 + + # This will create an issue with the link checker report if it does not exist, otherwise it will update the existing issue. + + - name: Create Issue + if: env.lychee_exit_code != 0 + uses: actions/github-script@v7 + env: + AUTH_TOKEN: ${{ steps.get_workflow_token.outputs.token }} + with: + script: | + const { Octokit } = require("@octokit/core"); + const octokit = new Octokit({ auth: process.env.AUTH_TOKEN }); + const allIssues = await octokit.request('GET /repos/{owner}/{repo}/issues', { + owner: context.repo.owner, + repo: context.repo.repo + }); + + const existingIssue = allIssues.data.find(issue => issue.title === 'Link Checker Report'); + if (existingIssue) { + await octokit.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: existingIssue.number, + body: '## Link Checker Report\n\n' + require('fs').readFileSync('./lychee/out.md', 'utf8') + }); + } else { + await octokit.request('POST /repos/{owner}/{repo}/issues', { + owner: context.repo.owner, + repo: context.repo.repo, + title: 'Link Checker Report', + body: '## Link Checker Report\n\n' + require('fs').readFileSync('./lychee/out.md', 'utf8') + }); + } \ No newline at end of file From 9c5d49a8f08297c858a334bffba43797708b9f03 Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Fri, 11 Oct 2024 21:10:59 +0530 Subject: [PATCH 2/5] fix cron syntax --- .github/workflows/link-checker.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/link-checker.yml b/.github/workflows/link-checker.yml index 5a13d8f..a637851 100644 --- a/.github/workflows/link-checker.yml +++ b/.github/workflows/link-checker.yml @@ -1,8 +1,11 @@ name: Link Checker + on: repository_dispatch: workflow_dispatch: - schedule: '0 0 1 * *' # Run at midnight on the first of every month + schedule: + - cron: '0 0 1 * *' # Run at midnight on the first of every month + jobs: linkChecker: name: Check and report broken links From 4eeaf12fc84ff043cfd9665b9959ded97ad96022 Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Fri, 11 Oct 2024 21:59:45 +0530 Subject: [PATCH 3/5] update packageManager from yarn to pnpm --- .github/workflows/link-checker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/link-checker.yml b/.github/workflows/link-checker.yml index a637851..6bfa8d2 100644 --- a/.github/workflows/link-checker.yml +++ b/.github/workflows/link-checker.yml @@ -32,10 +32,10 @@ jobs: private-key: ${{ secrets.PRIVATE_KEY }} - name: Install Dependencies - run: yarn install --immutable + run: pnpm install --immutable - name: Serve App Locally - run: yarn run dev & + run: pnpm run dev & - name: Wait for App to Start run: sleep 20 @@ -57,7 +57,7 @@ jobs: token: ${{secrets.GITHUB_TOKEN}} - name: Install Octokit - run: yarn add @octokit/core@5.1.0 + run: pnpm add @octokit/core@5.1.0 # This will create an issue with the link checker report if it does not exist, otherwise it will update the existing issue. From a08db71bd49f826431f115b173ef9d37d884a003 Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Fri, 11 Oct 2024 22:12:25 +0530 Subject: [PATCH 4/5] add --frozen-lockfile flag --- .github/workflows/link-checker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/link-checker.yml b/.github/workflows/link-checker.yml index 6bfa8d2..7133f11 100644 --- a/.github/workflows/link-checker.yml +++ b/.github/workflows/link-checker.yml @@ -32,7 +32,7 @@ jobs: private-key: ${{ secrets.PRIVATE_KEY }} - name: Install Dependencies - run: pnpm install --immutable + run: pnpm install --frozen-lockfile - name: Serve App Locally run: pnpm run dev & From 4b66248e1cedd6439ced3d1df61b00b8da740f6d Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Sun, 13 Oct 2024 22:02:30 +0530 Subject: [PATCH 5/5] update url in args in link-checker.yaml --- .github/workflows/link-checker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/link-checker.yml b/.github/workflows/link-checker.yml index 7133f11..2e485a0 100644 --- a/.github/workflows/link-checker.yml +++ b/.github/workflows/link-checker.yml @@ -53,7 +53,7 @@ jobs: id: lychee uses: lycheeverse/lychee-action@v1 with: - args: --base https://json-schema.org --verbose --no-progress --accept 200,204,429,403 './content/**/*.mdx' --cache --max-cache-age 1d https://json-schema.org + args: --base https://tour.json-schema.org --verbose --no-progress --accept 200,204,429,403 './content/**/*.mdx' --cache --max-cache-age 1d https://tour.json-schema.org token: ${{secrets.GITHUB_TOKEN}} - name: Install Octokit