Check for orphaned assets in CI (#24074)
This commit is contained in:
30
.github/workflows/orphaned-assets-check.yml
vendored
Normal file
30
.github/workflows/orphaned-assets-check.yml
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
name: 'Orphaned assets check'
|
||||||
|
|
||||||
|
# **What it does**: Checks that there are no files in ./assets/ that aren't mentioned in any source file.
|
||||||
|
# **Why we have it**: To avoid orphans into the repo.
|
||||||
|
# **Who does it impact**: Docs content.
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
|
||||||
|
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
|
||||||
|
with:
|
||||||
|
node-version: 16.13.x
|
||||||
|
cache: npm
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Check for orphaned assets
|
||||||
|
run: ./script/find-orphaned-assets.mjs --verbose --exit
|
||||||
@@ -20,7 +20,7 @@ const EXCEPTIONS = new Set([
|
|||||||
])
|
])
|
||||||
|
|
||||||
program
|
program
|
||||||
.description('Print all images that are in ./assets/ but not found in any markdown')
|
.description('Print all images that are in ./assets/ but not found in any source files')
|
||||||
.option('-e, --exit', 'Exit script by count of orphans (useful for CI)')
|
.option('-e, --exit', 'Exit script by count of orphans (useful for CI)')
|
||||||
.option('-v, --verbose', 'Verbose outputs')
|
.option('-v, --verbose', 'Verbose outputs')
|
||||||
.option('--json', 'Output in JSON format')
|
.option('--json', 'Output in JSON format')
|
||||||
@@ -83,8 +83,8 @@ async function main(opts) {
|
|||||||
|
|
||||||
verbose && console.log(`${allImages.size.toLocaleString()} images found in total.`)
|
verbose && console.log(`${allImages.size.toLocaleString()} images found in total.`)
|
||||||
|
|
||||||
for (const markdownFile of sourceFiles) {
|
for (const sourceFile of sourceFiles) {
|
||||||
const content = fs.readFileSync(markdownFile, 'utf-8')
|
const content = fs.readFileSync(sourceFile, 'utf-8')
|
||||||
for (const imagePath of allImages) {
|
for (const imagePath of allImages) {
|
||||||
const needle = imagePath.split(path.sep).slice(-2).join('/')
|
const needle = imagePath.split(path.sep).slice(-2).join('/')
|
||||||
if (content.includes(needle) || EXCEPTIONS.has(imagePath)) {
|
if (content.includes(needle) || EXCEPTIONS.has(imagePath)) {
|
||||||
@@ -94,7 +94,7 @@ async function main(opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (verbose && allImages.size) {
|
if (verbose && allImages.size) {
|
||||||
console.log('The following files are not mentioned anywhere in any Markdown file')
|
console.log('The following files are not mentioned anywhere in any source file')
|
||||||
}
|
}
|
||||||
if (json) {
|
if (json) {
|
||||||
console.log(JSON.stringify([...allImages], undefined, 2))
|
console.log(JSON.stringify([...allImages], undefined, 2))
|
||||||
|
|||||||
Reference in New Issue
Block a user