-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adds new actions, one is for checking all shows, one is for checking only the merged shows * updates all shows validate * adds pnpm setup * adds checkout v4 * adds basic show md validation(#1543) * adds 3 fake md show * adds validate to all prs * removes all shows and just ahs the merging show * fixes path * removes conditions from pullrequest * changes branch to current base branch isntead of the main * changes the way we're accessing changed files * adds fetch to action * adds checks to makes sure all links are working and all files have .md * adds path and tweaks code adds .md to one of the should fail files * tweaks the validation script to only look at new files in shows * further tweaks to get action working * adds setup * adds this back to give access to all branches * deletes 3 failing test shows, should pass now
- Loading branch information
Showing
5 changed files
with
132 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"pull_request": { | ||
"base": { | ||
"ref": "show-ci" | ||
}, | ||
"head": { | ||
"ref": "pr-actions-tester" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Check Links in New Markdown Files | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**/*.md' | ||
|
||
jobs: | ||
check-new-links: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Ensure the entire history is fetched | ||
|
||
- name: Fetch base branch | ||
run: git fetch origin ${GITHUB_BASE_REF}:${GITHUB_BASE_REF} | ||
env: | ||
GITHUB_BASE_REF: ${{ github.base_ref }} | ||
|
||
- name: pnpm-setup | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.18.2 | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Check for broken links in new MD files | ||
run: node ./scripts/merging-show-validation.js | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_BASE_REF: ${{ github.base_ref }} |
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 |
---|---|---|
|
@@ -23,3 +23,4 @@ test-results | |
# core.wasm | ||
|
||
start_script/target | ||
bin |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { exec } from 'child_process'; | ||
import fs from 'fs/promises'; | ||
import { promisify } from 'util'; | ||
// import path from 'path'; | ||
const execAsync = promisify(exec); | ||
|
||
// Function to check URL availability | ||
async function isUrlValid(url) { | ||
try { | ||
const response = await fetch(url, { | ||
headers: { | ||
'User-Agent': | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' | ||
} | ||
}); | ||
// Consider valid if the status code is in the range 200-399, covering success and redirection | ||
return response.status !== 404; | ||
} catch (error) { | ||
console.error(`Error checking URL: ${url}`, error); | ||
return false; // Treat any error as an invalid URL | ||
} | ||
} | ||
|
||
// Function to extract URLs from markdown content | ||
const extractUrls = (content) => { | ||
const urlRegex = /https?:\/\/[^\s\)]+/g; | ||
return content.match(urlRegex) || []; | ||
}; | ||
|
||
// Function to process a single markdown file for broken links | ||
const processFile = async (filePath) => { | ||
const content = await fs.readFile(filePath, 'utf8'); | ||
const urls = extractUrls(content); | ||
const checkPromises = urls.map(isUrlValid); | ||
const results = await Promise.all(checkPromises); | ||
return urls.filter((_, index) => !results[index]); | ||
}; | ||
// Function to get new files added in the PR within ./shows directory | ||
const getNewFilesInShows = async () => { | ||
const baseBranch = process.env.GITHUB_BASE_REF; // Use the base branch of the PR | ||
const { stdout } = await execAsync( | ||
`git diff --diff-filter=A --name-only ${baseBranch} HEAD -- 'shows/'` | ||
); | ||
return stdout.split('\n').filter((line) => line.startsWith('shows/')); | ||
}; | ||
|
||
// Main function modified to check for non-.md files in ./shows | ||
const main = async () => { | ||
const newFiles = await getNewFilesInShows(); | ||
const nonMdFiles = newFiles.filter((file) => !file.endsWith('.md')); | ||
|
||
if (nonMdFiles.length > 0) { | ||
console.error('Error: Non-markdown files found in ./shows:', nonMdFiles); | ||
process.exit(1); // Fail if there are non-markdown files | ||
} | ||
|
||
// Filter out .md files for further processing | ||
const mdFiles = newFiles.filter((file) => file.endsWith('.md')); | ||
|
||
if (mdFiles.length === 0) { | ||
console.log('No new markdown files to check in ./shows.'); | ||
return; | ||
} | ||
|
||
let hasBrokenLinks = false; | ||
for (const file of mdFiles) { | ||
const brokenLinks = await processFile(file); | ||
if (brokenLinks.length > 0) { | ||
hasBrokenLinks = true; | ||
console.log(`Broken links found in ${file}:`); | ||
brokenLinks.forEach((link) => console.log(`- ${link}`)); | ||
} | ||
} | ||
|
||
if (hasBrokenLinks) { | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
await main(); |
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