Skip to content

improved link-checker #10

improved link-checker

improved link-checker #10

Workflow file for this run

name: Link Checker
# Trigger the workflow on pull requests to the main or develop branches
on:
pull_request:
branches:
- main
- develop
jobs:
link-check:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository code using the latest version of actions/checkout
- name: Check out code
uses: actions/checkout@v4
# Step 2: Set up Node.js environment using actions/setup-node v4.0.3
- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: '20' # Specify Node.js 20.x
# Step 3: Install dependencies
- name: Install dependencies
run: npm install
# Step 4: Create a temporary .eleventy-port file
- name: Create a temporary .eleventy-port file
run: echo "8080" > .eleventy-port
# Step 5: Build and serve the site on the specified port
- name: Build and serve the site
run: npm run serve-only &
# Step 6: Wait for the server to start
- name: Wait for server to start
run: sleep 10 # Adjust as needed based on server start time
# Step 7: Run the link checker and capture the result
- name: Run link checker
id: link-check # Add ID to reference outputs
run: npm run link-check
# Step 8: Upload broken links report if broken links are found
- name: Upload broken links report
if: failure() # Only upload the report if broken links are detected
uses: actions/upload-artifact@v2
with:
name: broken-links-report
path: broken-links.json
# Step 9: Post a comment on the PR with the broken links details
- name: Post comment with broken links
if: failure() # Only post a comment if broken links are detected
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## :warning: Broken Links Detected
The following broken links were found during the build process:
```json
${{ toJSON(steps.link-check.outputs.brokenLinks) }}
```