Links #263
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Links | |
on: | |
repository_dispatch: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 18 * * *" | |
env: | |
BUILD_PATH: "." | |
jobs: | |
check_links: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "pnpm" | |
cache-dependency-path: ${{ env.BUILD_PATH }}/pnpm-lock.yaml | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
working-directory: ${{ env.BUILD_PATH }} | |
- name: Build with Astro | |
run: pnpm build --site "http://localhost:4321" | |
working-directory: ${{ env.BUILD_PATH }} | |
- name: Start Astro Preview in the background | |
run: | | |
pnpm preview & | |
echo $! > astro-preview.pid | |
working-directory: ${{ env.BUILD_PATH }} | |
- name: Wait for Astro to be ready | |
run: | | |
timeout 15 sh -c 'until curl -s http://localhost:4321 > /dev/null; do sleep 1; done' | |
- name: Link Checker | |
id: lychee | |
uses: lycheeverse/lychee-action@v2 | |
with: | |
fail: false | |
args: --base ${{ env.BUILD_PATH }}/dist --verbose --no-progress --remap 'file:///home/runner/work/r.obin.ch/r.obin.ch/dist http://localhost:4321' './**/*.html' | |
- name: Stop Astro Preview | |
run: kill $(cat astro-preview.pid) | |
- name: Find or Create Issue | |
id: issue_finder | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { data: issues } = await github.rest.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
labels: ['report', 'automated issue'], | |
}); | |
// Find an issue with the title "Link Checker Report" | |
let issue = issues.find(i => i.title === 'Link Checker Report'); | |
if (!issue) { | |
// If no such issue exists, create a new one | |
const { data: newIssue } = await github.rest.issues.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: 'Link Checker Report', | |
body: 'There are no broken links in the site or action did not run successfully.', | |
labels: ['report', 'automated issue'], | |
}); | |
issue = newIssue; | |
console.log(`Created issue #${newIssue.number}`); | |
} else { | |
// If an issue with the title "Link Checker Report" already exists, update its body | |
const { data: updatedIssue } = await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue.number, | |
body: 'There are no broken links in the site or action did not run successfully.', | |
}); | |
issue = updatedIssue; | |
console.log(`Updated issue #${issue.number}`); | |
} | |
// Output the issue number to pass to the next steps | |
core.setOutput('issue_number', issue.number); | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Issue From File | |
if: env.lychee_exit_code != 0 | |
uses: peter-evans/create-issue-from-file@v5 | |
with: | |
title: Link Checker Report | |
issue-number: ${{ steps.issue_finder.outputs.issue_number }} | |
content-filepath: ./lychee/out.md |