-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a workflow for verify contracted redirections (#4230)
* adds redirection validation workflow and action * removes route to redirectionio app * updates redirect workflow to trigger after Get info on PR workflow completes Updates redirection action to output a table to the workflow's summary if there are any broken redirects adds updated package.json and package-lock.json files --------- Co-authored-by: Chad Carlson <chadwcarlson@users.noreply.github.com>
- Loading branch information
1 parent
1d4b516
commit 020890b
Showing
735 changed files
with
490,343 additions
and
1 deletion.
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,14 @@ | ||
name: redirections contract verification | ||
description: Verifies that the redirections for our contract with console are still valid | ||
inputs: | ||
environment-url: | ||
description: 'Pull Request Environment URL' | ||
required: true | ||
|
||
#### | ||
#outputs: | ||
#### | ||
|
||
runs: | ||
using: 'node20' | ||
main: index.js |
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,89 @@ | ||
const core = require('@actions/core') | ||
const github = require('@actions/github') | ||
const fs = require('fs'); | ||
const yaml = require('js-yaml'); | ||
const axios = require('axios'); | ||
const tableData = [ | ||
[ | ||
{data: 'From', header: true}, | ||
{data: 'To', header: true} | ||
] | ||
] | ||
|
||
function linkify(path,url) { | ||
let link = "" | ||
|
||
/** | ||
* We only want to append the URL if the path doesnt already start with https | ||
*/ | ||
if (!path.startsWith('https:')) { | ||
if(url.endsWith('/')) { | ||
url = url.slice(0,-1); | ||
} | ||
|
||
link = url+path; | ||
|
||
} else { | ||
link = path; | ||
} | ||
|
||
return `<a href="${link}">${path}</a>` | ||
} | ||
|
||
/** | ||
* @todo should we verify that the URL is valid before we set it? | ||
* @type {string} | ||
*/ | ||
axios.defaults.baseURL = core.getInput('environment-url') | ||
|
||
try { | ||
/** | ||
* @todo Can we get the full workspace path to this file? | ||
* @type {*} | ||
*/ | ||
const yamlData = yaml.load(fs.readFileSync('./.platform/routes.yaml', 'utf8')); | ||
/** | ||
* @todo the key (docs.upsun.com) here should be a variable that is set somewhere else | ||
* @type {Record<string, string[]> | _.LodashAt | ((request: string) => (string[] | null)) | string[]} | ||
*/ | ||
const anchors = yamlData['https://docs.upsun.com/'].redirects.paths | ||
|
||
const RedirectKeys = Object.keys(anchors).filter((path)=>{ | ||
/** | ||
* @todo the piece we're using to identify our contracts (/anchors/) should be a variable | ||
*/ | ||
return path.startsWith('/anchors/') | ||
}) | ||
|
||
const validateRedirects = RedirectKeys.map(async (path, index, array) => { | ||
//console.log(`I'm going to test ${path} to see if it goes to ${anchors[path].to}`) | ||
|
||
try { | ||
const response = await axios.head(path); | ||
//core.info(`Response for our check of ${path} is ${response.status}`) | ||
return response | ||
} catch (reqerr) { | ||
//core.warning(`issue encountered with path ${path}!!! Returned status is ${reqerr.status}`) | ||
let row = [{data: linkify(path, axios.defaults.baseURL)},{data: linkify( anchors[path].to, axios.defaults.baseURL) }] | ||
tableData.push(row) | ||
} | ||
}); | ||
|
||
|
||
Promise.all(validateRedirects).then(() => { | ||
if(tableData.length > 1) { | ||
|
||
core.error('There was an error with one or more redirects.') | ||
|
||
core.summary.addTable(tableData) | ||
|
||
core.summary.write() | ||
core.setFailed('There was an error with one or more contracted redirects.') | ||
} else { | ||
core.notice('All contracted redirections are valid.') | ||
} | ||
}); | ||
|
||
} catch (error) { | ||
core.setFailed(`Action failed with error ${error}`) | ||
} |
9 changes: 9 additions & 0 deletions
9
.github/actions/redirection-verification/node_modules/@actions/core/LICENSE.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.