Skip to content

Commit

Permalink
Add broken url checker
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Oct 5, 2024
1 parent dcd9b8d commit 9d728d5
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 32 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/brokenurl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Maintenance: Check Broken URLs'
# on:
# schedule:
# - cron: '2 22 * * *' # Runs at 10:02 every day
# push:
# pull_request:
on: ['push', 'pull_request']

jobs:
brokenurl:
if: github.repository == 'SchemaStore/schemastore'
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v4'
- uses: 'actions/setup-node@v4'
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: './package-lock.json'
- run: 'npm clean-install'
# - run: 'node ./cli.js maintenance'
- name: 'Update comment'
uses: 'peter-evans/create-or-update-comment@v4'
permissions:
issues: 'write'
with:
comment-id: 2394972665
body: |
**Edit:** Some additional info
41 changes: 21 additions & 20 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as jsoncParser from 'jsonc-parser'
import ora from 'ora'
import chalk from 'chalk'
import minimist from 'minimist'
import fetch from 'node-fetch'

/**
* Ajv defines types, but they don't work when importing the library with
Expand Down Expand Up @@ -528,10 +529,6 @@ async function taskLint() {
await assertTopLevelRefIsStandalone(schema)
await assertSchemaNoSmartQuotes(schema)

console.info(
`Running ${chalk.bold('SchemaSafe validation')} on file: ${schema.path}`,
)

const errors = schemasafe.lint(schema.json, {
mode: 'strong',
extraFormats: false,
Expand All @@ -546,10 +543,6 @@ async function taskLint() {

// await forEachFile({
// async onSchemaFile(schema) {
// console.info(
// `Running ${chalk.bold('Spectral validation')} on file: ${schema.path}`,
// )
//
// const doc = new spectralCore.Document(
// schema.text,
// Parsers.Json,
Expand Down Expand Up @@ -715,9 +708,6 @@ async function taskCheck() {
}

async function taskCheckStrict() {
const spinner = ora().start()
spinner.start('Testing schema with unofficial draft-07 strict metaschema')

const ajv = await ajvFactory({
draftVersion: 'draft-07',
fullStrictMode: false,
Expand All @@ -729,17 +719,14 @@ async function taskCheckStrict() {
try {
validateFn = ajv.compile(metaSchemaFile.json)
} catch (err) {
spinner.fail()
printErrorAndExit(err, [
`Failed to compile schema file ${metaSchemaFile.path}`,
])
}

await forEachFile({
actionName: 'strict metaschema check',
async onSchemaFile(schemaFile) {
spinner.text = `Running Ajv with unofficial draft-07 strict metaschema on file: ${schemaFile.path}`

async onSchemaFile(schemaFile, { spinner }) {
const validate = validateFn
if (!validate(schemaFile.json)) {
spinner.fail()
Expand All @@ -758,10 +745,6 @@ async function taskCheckStrict() {
}
},
})
spinner.stop()
console.info(
`✔️ Schemas: All unofficial draft-07 strict metaschema validation tests succeeded`,
)

// Print information.
console.info(`===== REPORT =====`)
Expand All @@ -778,7 +761,25 @@ async function taskReport() {
}

async function taskMaintenance() {
await printDowngradableSchemaVersions()
{
console.info(`===== BROKEN SCHEMAS =====`)
forEachCatalogUrl(async (url) => {
if (url.startsWith(UrlSchemaStore)) return

await fetch(url, { method: 'HEAD' })
.then((res) => {
// eslint-disable-line promise/always-return

if (!res.ok) {
console.info(`NOT OK (${res.status}/${res.statusText}): ${url}`)
}
})
.catch((err) => {
console.info(`NOT OK (${err.code}): ${url}`)
})
})
}
// await printDowngradableSchemaVersions()
}

async function assertFileSystemIsValid() {
Expand Down
142 changes: 130 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"globals": "^15.9.0",
"jsonc-parser": "^3.3.1",
"minimist": "^1.2.8",
"node-fetch": "^3.3.2",
"ora": "^8.0.1",
"prettier": "^3.3.3",
"prettier-plugin-sort-json": "^4.0.0",
Expand Down

0 comments on commit 9d728d5

Please sign in to comment.