Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirection push fix #4286

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/actions/redirection-verification/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ inputs:
environment-url:
description: 'Pull Request Environment URL'
required: true
number_retries:
description: 'The number of attempts we should make to contact the target environment URL. 1 second delay between attempt.'
required: false
default: '100'

####
#outputs:
Expand Down
130 changes: 82 additions & 48 deletions .github/actions/redirection-verification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,89 @@ function linkify(path,url) {
* @type {string}
*/
axios.defaults.baseURL = core.getInput('environment-url')
//axios.defaults.baseURL = 'https://httpstat.us/random/200,500-504,500-504,500-504'
const retries = Number(core.getInput('number_retries'))
//const retries = Number('100')
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

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)=>{
const verifyTargetResponse = async(count = 0) => {
try {
const axiosResponse = await axios.get('/');
core.notice('Target URL finally responded with a 200. Proceeding.')
return axiosResponse;
} catch (error) {
if (error || error.status != 200) {
core.info(`At attempt ${count}, target url responded with status ${error.status}, retrying...`)
if (count++ < retries) {
await sleep(1000);
return verifyTargetResponse(count);
} else {
core.setFailed(`Max number of retries (${retries}) reached. Aborting.`)
};
} else {
core.setFailed(`Action failed with error ${error}`)
};
};
};

const verify = async () => {
let targetReady = await verifyTargetResponse();
core.info('Target URL ready. Beginning verification.')
try {
/**
* @todo the piece we're using to identify our contracts (/anchors/) should be a variable
* @todo Can we get the full workspace path to this file?
* @type {*}
*/
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}`)
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.debug(`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}`)
}
}

verify();
Loading