Skip to content

Commit

Permalink
change filename
Browse files Browse the repository at this point in the history
  • Loading branch information
katiegoines committed Jun 8, 2024
1 parent d85ad47 commit 1c02da7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 71 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/scripts/validate-redirects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
invalidRedirects: () => {
const Ajv = require('ajv');
const redirects = require('../../../redirects.json');
const ajv = new Ajv();

const schema = {
type: 'array',
items: {
type: 'object',
required: ['source', 'target', 'status'],
properties: {
source: {
description: 'The address the user requested.',
type: 'string',
pattern: '^/'
},
target: {
description:
'The address that actually serves the content that the user sees',
type: 'string',
pattern: '^[(https)(/)]'
},
status: {
description:
'Types include a permanent redirect (301), a temporary redirect (302), a rewrite (200), or not found (404).',
type: 'string',
pattern: '^[0-5-]+$'
}
}
}
};

const validate = ajv.compile(schema);

const valid = validate(redirects);
if (!valid) {
const invalidEntry =
JSON.stringify(redirects[validate.errors[0].instancePath.slice(1, -7)]);
const error = validate.errors[0];
const loc = error.schemaPath.slice(error.schemaPath.indexOf('properties') + 11, -8);

const errorMessage = '\n\n' + 'INVALID ENTRY: Please correct the error in the "' + loc +'" property of the following entry: \n' + invalidEntry + '\n\n' + 'ERROR MESSAGE: ' + error.message;
return errorMessage;
}
}
}


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ValidateRedirects
name: Validate Redirects
on:
pull_request:
branches: [main]
Expand All @@ -8,7 +8,7 @@ env:
permissions:
contents: read
jobs:
CheckConsoleErrors:
ValidateRedirects:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -19,22 +19,14 @@ jobs:
node-version: 20.x
- name: Install Dependencies
run: yarn
- name: Run Build
run: yarn build:release
env:
NODE_OPTIONS: --max_old_space_size=4096
- name: Run Server
run: |
python -m http.server 3000 -d ${{ env.BUILD_DIR }} &
sleep 5
- name: Validate redirects
id: redirects
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
result-encoding: string
script: |
const { redirects } = require('./tasks/validate_redirects');
const { invalidRedirects } = require('./.github/workflows/scripts/validate-redirects.js');
return await invalidRedirects();
- name: Fail if console errors have been found
- name: Fail if any invalid redirects have been found
if: ${{ steps.redirects.outputs.result }}
run: exit 1
run: exit 1 && echo ${{ steps.redirects.outputs.result }}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"prepare": "husky install",
"analyze": "ANALYZE=true yarn next-build",
"prebuild": "node src/directory/generateDirectory.mjs && node src/directory/generateFlatDirectory.mjs",
"lint": "next lint",
"validate-redirects": "node tasks/validate-redirects.mjs"
"lint": "next lint"
}
}
4 changes: 2 additions & 2 deletions redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
{
"source": "/lib/ssr/ssr/",
"target": "/gen1/javascript/prev/build-a-backend/server-side-rendering/",
"status": "606"
"status": "301"
},
{
"source": "cli/plugins/",
"target": "/javascript/tools/cli/plugins/",
"status": "301"
"status": "601"
},
{
"source": "/<*>",
Expand Down
54 changes: 0 additions & 54 deletions tasks/validate-redirects.mjs

This file was deleted.

0 comments on commit 1c02da7

Please sign in to comment.