mirror of
https://github.com/awesome-selfhosted/awesome-selfhosted.git
synced 2025-06-22 23:08:25 +02:00
Add github actions workflows
Signed-off-by: Nathan Rew <nrew225@gmail.com>
This commit is contained in:
parent
100d8538fe
commit
19937e41db
6 changed files with 331 additions and 63 deletions
|
@ -8,6 +8,7 @@ let licenses = new Set();
|
|||
let pr = false;
|
||||
let readme;
|
||||
let diff;
|
||||
let mdOutput = [];
|
||||
|
||||
//Parse the command options and set the pr var
|
||||
function parseArgs(args) {
|
||||
|
@ -42,10 +43,11 @@ function split(text) {
|
|||
|
||||
// All entries should match this pattern. If matches pattern returns true.
|
||||
function findPattern(text) {
|
||||
const patt = /^\s{0,2}-\s\[.*?\]\(.*?\) (`⚠` )?- .{0,249}?\.( \(\[(Demo|Source Code|Clients)\]\([^)\]]*\)(, \[(Source Code|Clients)\]\([^)\]]*\))?(, \[(Source Code|Clients)\]\([^)\]]*\))*\))? \`.*?\` \`.*?\`$/;
|
||||
const patt = /^\s{0,2}-\s\[.*?\]\(.*?\) (`⚠` )?- .{0,249}?\.( \(\[(Demo|Source Code|Clients)\]\([^)\]]*\)(, \[(Source Code|Clients)\]\([^)\]]*\))?(, \[(Source Code|Clients)\]\([^)\]]*\))*\))? \`.*?\` \`.*?\`$/m;
|
||||
if (patt.test(text) === true) {
|
||||
return true;
|
||||
}
|
||||
console.log("Failed: "+text)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -61,9 +63,9 @@ function testMainLink(text) {
|
|||
const testA1 = /(- \W?\w*\W{0,2}.*?\)?)( .*$)/;
|
||||
if (!testA.test(text)) {
|
||||
let a1 = testA1.exec(text)[2];
|
||||
return chalk.red(text.replace(a1, ''))
|
||||
return [chalk.red(text.replace(a1, '')), '🢂' + text.replace(a1, '') + '🢀']
|
||||
}
|
||||
return chalk.green(testA.exec(text)[1])
|
||||
return [chalk.green(testA.exec(text)[1]), testA.exec(text)[1]]
|
||||
}
|
||||
|
||||
//Test '`⚠` - Short description, less than 250 characters.'
|
||||
|
@ -74,23 +76,23 @@ function testDescription(text) {
|
|||
if (!testB.test(text)) {
|
||||
let b1 = testA1.exec(text)[1];
|
||||
let b2 = testB2.exec(text)[1];
|
||||
return chalk.red(text.replace(b1, '').replace(b2, ''))
|
||||
return [chalk.red(text.replace(b1, '').replace(b2, '')), '🢂' + text.replace(b1, '').replace(b2, '') + '🢀' ]
|
||||
}
|
||||
return chalk.green(testB.exec(text)[1])
|
||||
return [chalk.green(testB.exec(text)[1]), testB.exec(text)[1]]
|
||||
}
|
||||
|
||||
//If present, tests '([Demo](http://url.to/demo), [Source Code](http://url.of/source/code), [Clients](https://url.to/list/of/related/clients-or-apps))'
|
||||
function testSrcDemCli(text) {
|
||||
let testC = text.search(/\.\ \(|\.\ \[|\ \(\[[sSdDcC]/); // /\(\[|\)\,|\)\)/);
|
||||
let testD = /(?<=\w. )(\(\[(Demo|Source Code|Clients)\]\([^)\]]*\)(, \[(Source Code|Clients)\]\([^)\]]*\))?(, \[(Source Code|Clients)\]\([^)\]]*\))*\))(?= \`?)/;
|
||||
let testD = /(?<=\w. )(\(\[(Demo|Source Code|Clients)\]\([^)\]]*\)(, \[(Source Code|Clients)\]\([^)\]]*\))?(, \[(Source Code|Clients)\]\([^)\]]*\))*\) )(?=\`?)/;
|
||||
const testD1 = /(^- \W[a-zA-Z0-9-_ .]*\W{0,2}http[^\[]*)(?<= )/;
|
||||
const testD2 = /(\`.*\` \`.*\`$)/;
|
||||
const testD2 = /\ ?(\`.*\` \`.*\`$)/;
|
||||
if ((testC > -1) && (!testD.test(text))) {
|
||||
let d1 = testD1.exec(text)[1];
|
||||
let d2 = testD2.exec(text)[1];
|
||||
return chalk.red(text.replace(d1, '').replace(d2, ''))
|
||||
return [chalk.red(text.replace(d1, '').replace(d2, '')), '🢂' + text.replace(d1, '').replace(d2, '') + '🢀']
|
||||
} else if (testC > -1) {
|
||||
return chalk.green(testD.exec(text)[1])
|
||||
return [chalk.green(testD.exec(text)[1]), testD.exec(text)[1]]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -102,19 +104,18 @@ function testLangLic(text) {
|
|||
const testE1 = /(^[^`]*)/;
|
||||
if (!testE) {
|
||||
let e1 = testE1.exec(text)[1];
|
||||
return chalk.red(text.replace(e1, ''))
|
||||
return [chalk.red(text.replace(e1, '')), '🢂' + text.replace(e1, '') + '🢀']
|
||||
}
|
||||
return chalk.green(testD2.exec(text)[1])
|
||||
return [chalk.green(testD2.exec(text)[1]), + testD2.exec(text)[1]]
|
||||
}
|
||||
|
||||
//Runs all the syntax tests...
|
||||
function findError(text) {
|
||||
let res
|
||||
res = testMainLink(text)
|
||||
res += testDescription(text)
|
||||
res += testSrcDemCli(text)
|
||||
res += testLangLic(text)
|
||||
return res + `\n`
|
||||
resMainLink = testMainLink(text)
|
||||
resDesc= testDescription(text)
|
||||
resSrcDemCli= testSrcDemCli(text)
|
||||
resLangLic= testLangLic(text)
|
||||
return [resMainLink[0] + resDesc[0] + resSrcDemCli[0] + resLangLic[0] + `\n`, '```' + resMainLink[1] + resDesc[1] + resSrcDemCli[1] + resLangLic[1] + '```']
|
||||
}
|
||||
|
||||
//Check if license is in the list of licenses.
|
||||
|
@ -122,7 +123,7 @@ function testLicense(md) {
|
|||
let pass = true;
|
||||
let lFailed = []
|
||||
let lPassed = []
|
||||
const regex = /.*\`(.*)\` .*$/;
|
||||
const regex = /.*?\`([a-zA-Z0-9\-\./]*)\`.+$/;
|
||||
try {
|
||||
for (l of regex.exec(md)[1].split("/")) {
|
||||
if (!licenses.has(l)) {
|
||||
|
@ -136,11 +137,6 @@ function testLicense(md) {
|
|||
console.log(chalk.yellow("Error in License syntax, license not checked against list."))
|
||||
return [false, "", ""]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return [pass, lFailed, lPassed]
|
||||
}
|
||||
|
||||
|
@ -195,14 +191,15 @@ function entryErrorCheck() {
|
|||
e.pass = true
|
||||
e.name = parseName(e.raw)
|
||||
if (!findPattern(e.raw)) {
|
||||
e.highlight = findError(e.raw);
|
||||
errorRes = findError(e.raw);
|
||||
e.highlight = errorRes[0];
|
||||
e.pass = false;
|
||||
console.log(e.highlight)
|
||||
}
|
||||
e.licenseTest = testLicense(e.raw);
|
||||
if (!e.licenseTest) {
|
||||
e.pass = false;
|
||||
console.log(chalk.red(`${e.name}'s license is not on License list.`))
|
||||
console.log(chalk.red(`${e.name}'s license is not on the License list.`))
|
||||
}
|
||||
if (e.pass) {
|
||||
totalPass++
|
||||
|
@ -210,6 +207,7 @@ function entryErrorCheck() {
|
|||
totalFail++
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log(chalk.cyan("Testing entire README.md\n"))
|
||||
total = entries.length
|
||||
|
@ -217,7 +215,9 @@ function entryErrorCheck() {
|
|||
e.pass = true
|
||||
e.name = parseName(e.raw)
|
||||
if (!findPattern(e.raw)) {
|
||||
e.highlight = findError(e.raw);
|
||||
errorRes = findError(e.raw);
|
||||
e.highlight = errorRes[0];
|
||||
mdOutput.push("* [ ] Line: " + e.line + ": " + e.name + "\n" + errorRes[1]);
|
||||
e.pass = false;
|
||||
console.log(`${chalk.yellow(e.line + ": ")}${e.highlight}`);
|
||||
syntax = e.highlight;
|
||||
|
@ -226,6 +226,7 @@ function entryErrorCheck() {
|
|||
if (!e.licenseTest[0]) {
|
||||
e.pass = false;
|
||||
console.log(chalk.yellow(e.line + ": ") + `${e.name}'s license ${chalk.red(`'${e.licenseTest[1]}'`)} is not on the License list.\n`)
|
||||
mdOutput.push("* [ ] Line: " + e.line + "\n" + e.name + "'s license is not on the License list.")
|
||||
}
|
||||
if (e.pass) {
|
||||
totalPass++
|
||||
|
@ -238,6 +239,10 @@ function entryErrorCheck() {
|
|||
console.log(chalk.blue(`\n-----------------------------\n`))
|
||||
console.log(chalk.red(`${totalFail} Failed, `) + chalk.green(`${totalPass} Passed, `) + chalk.blue(`of ${total}`))
|
||||
console.log(chalk.blue(`\n-----------------------------\n`))
|
||||
fs.writeFileSync('syntax_check.md', `--------------------\n### Syntax Checks\n#### ${totalFail} Failed, ${totalPass} Passed, of ${total}.\n`)
|
||||
mdOutput.forEach(element => {
|
||||
fs.appendFileSync('syntax_check.md', `${element}\n`)
|
||||
});
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(chalk.blue(`\n-----------------------------\n`))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue