-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automate broken link detection and PR comments
- Integrated GitHub Actions to automatically check for broken links on pull requests. - Updated workflow to use `actions/[email protected]` for Node.js 20.x compatibility. - Added steps to build and serve the Eleventy site on a specified port. - Updated to `peter-evans/create-or-update-comment@v4` for posting PR comments with broken link details. - Updated to `actions/[email protected]` for uploading broken links report (`broken-links.json`) as an artifact if issues are found.
- Loading branch information
1 parent
52fbf8d
commit 4922432
Showing
1 changed file
with
23 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
name: Link Checker | ||
|
||
# Trigger the workflow on pull requests to the main or develop branches | ||
on: | ||
pull_request: | ||
branches: | ||
|
@@ -12,15 +11,15 @@ jobs: | |
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Step 1: Check out the repository code using the latest version of actions/checkout | ||
# Step 1: Check out the repository code | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
|
||
# Step 2: Set up Node.js environment using the latest version | ||
# Step 2: Set up Node.js environment | ||
- name: Set up Node.js | ||
uses: actions/[email protected] | ||
with: | ||
node-version: '20' # Specify Node.js 20.x | ||
node-version: '20' | ||
|
||
# Step 3: Install dependencies | ||
- name: Install dependencies | ||
|
@@ -30,22 +29,37 @@ jobs: | |
- name: Create a temporary .eleventy-port file | ||
run: echo "8080" > .eleventy-port | ||
|
||
# Step 5: Build and serve the site on the specified port | ||
# Step 5: Build and serve the site | ||
- 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 | ||
run: sleep 10 | ||
|
||
# Step 7: Run the link checker | ||
- 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 | ||
# Step 8: Upload broken links report regardless of link check result | ||
- name: Upload broken links report | ||
if: failure() | ||
uses: actions/upload-artifact@v2 | ||
if: always() # This runs regardless of the result of the previous step | ||
uses: actions/upload-artifact@v4.3.6 | ||
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() # This runs only if broken links were found | ||
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) }} | ||
``` |