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

Feature : Added linkChecker workflow #604

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Changes from all 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
83 changes: 83 additions & 0 deletions .github/workflows/links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Link Checker

on:
repository_dispatch:
workflow_dispatch:
schedule:
- cron: '0 0 1 * *' # Run at midnight on the first of every month

jobs:
linkChecker:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Submodule
run: git submodule update --init --recursive

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Dependencies
run: yarn install --frozen-lockfile

- 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
aialok marked this conversation as resolved.
Show resolved Hide resolved
id: lychee
uses: lycheeverse/lychee-action@v1
with:
args: --base http://localhost:3000 --verbose --no-progress --accept 200,204,429,403 './pages/**/*.md' --cache --max-cache-age 1d http://localhost:3000
token: ${{secrets.AUTH_TOKEN}}

- name: Install Octokit
run: yarn add @octokit/[email protected]

# 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: ${{secrets.AUTH_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')
});
}
Loading