mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
checks update
This commit is contained in:
parent
196673877d
commit
6715717ca8
|
@ -279,8 +279,8 @@ const checkName = async (connector) => {
|
|||
}
|
||||
|
||||
async function checkMain () {
|
||||
const errors = []
|
||||
try {
|
||||
const errors = []
|
||||
const warnings = []
|
||||
const connectors = await getConnectorsList()
|
||||
for (let index = 0; index < connectors.length; index++) {
|
||||
|
@ -299,19 +299,19 @@ async function checkMain () {
|
|||
}
|
||||
if (errors.length) {
|
||||
console.log('\x1b[31m%s\x1b[0m', `Total errors: ${errors.length}`)
|
||||
console.log('\x1b[31m%s\x1b[0m', errors.join('\n'))
|
||||
errors.forEach(error => console.log('\x1b[31m%s\x1b[0m', error))
|
||||
} else {
|
||||
console.log('\x1b[32m%s\x1b[0m', 'No Errors Found')
|
||||
}
|
||||
if (warnings.length) {
|
||||
console.log('\x1b[33m%s\x1b[0m', `Total warnings: ${warnings.length}`)
|
||||
console.log('\x1b[33m%s\x1b[0m', warnings.join('\n'))
|
||||
warnings.forEach(warning => console.log('\x1b[33m%s\x1b[0m', warning))
|
||||
} else {
|
||||
console.log('\x1b[32m%s\x1b[0m', 'No Warnings Found')
|
||||
}
|
||||
if (errors.length) return Promise.reject(errors.join('\n'))
|
||||
} catch (error) {
|
||||
console.error('check execution error:', error)
|
||||
}
|
||||
if (errors.length) throw new Error(errors.join('\n'))
|
||||
}
|
||||
module.exports = checkMain;
|
||||
module.exports = checkMain
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
const checkMain = require('./check');
|
||||
const checkMain = require('./check')
|
||||
|
||||
module.exports = [{
|
||||
name: 'Solidity check',
|
||||
callback: checkMain,
|
||||
}];
|
||||
callback: async () => {
|
||||
try {
|
||||
await checkMain()
|
||||
return 'Check passed!'
|
||||
} catch (error) {
|
||||
throw new Error('Check failed!')
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
|
|
@ -6,4 +6,4 @@ const checkMain = require('./check');
|
|||
} catch (error) {
|
||||
process.exit(1)
|
||||
}
|
||||
})()
|
||||
})()
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
const cp = require('child_process');
|
||||
const fetch = require('node-fetch');
|
||||
const cp = require('child_process')
|
||||
const fetch = require('node-fetch')
|
||||
|
||||
const checks = require('./checks');
|
||||
const checks = require('./checks')
|
||||
|
||||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
|
||||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/')
|
||||
|
||||
function getCurrentCommitSha() {
|
||||
function getCurrentCommitSha () {
|
||||
return cp
|
||||
.execSync(`git rev-parse HEAD`)
|
||||
.execSync('git rev-parse HEAD')
|
||||
.toString()
|
||||
.trim();
|
||||
.trim()
|
||||
}
|
||||
// The SHA provied by GITHUB_SHA is the merge (PR) commit.
|
||||
// We need to get the current commit sha ourself.
|
||||
const sha = getCurrentCommitSha();
|
||||
const sha = getCurrentCommitSha()
|
||||
|
||||
async function setStatus(context, state, description) {
|
||||
async function setStatus (context, state, description) {
|
||||
return fetch(`https://api.github.com/repos/${owner}/${repo}/statuses/${sha}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
state,
|
||||
description,
|
||||
context,
|
||||
context
|
||||
}),
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
(async () => {
|
||||
console.log(`Starting status checks for commit ${sha}`);
|
||||
console.log(`Starting status checks for commit ${sha}`)
|
||||
|
||||
// Run in parallel
|
||||
await Promise.all(
|
||||
checks.map(async check => {
|
||||
const { name, callback } = check;
|
||||
const { name, callback } = check
|
||||
|
||||
await setStatus(name, 'pending', 'Running check..');
|
||||
await setStatus(name, 'pending', 'Running check..')
|
||||
|
||||
try {
|
||||
const response = await callback();
|
||||
await setStatus(name, 'success', response);
|
||||
const response = await callback()
|
||||
await setStatus(name, 'success', response)
|
||||
} catch (err) {
|
||||
const message = err ? err.message : 'Something went wrong';
|
||||
await setStatus(name, 'failure', message);
|
||||
const message = err ? err.message : 'Something went wrong'
|
||||
await setStatus(name, 'failure', message)
|
||||
}
|
||||
}),
|
||||
);
|
||||
})
|
||||
)
|
||||
|
||||
console.log('Finished status checks');
|
||||
})();
|
||||
console.log('Finished status checks')
|
||||
})()
|
||||
|
|
Loading…
Reference in New Issue
Block a user