Skip to content

Commit

Permalink
Add GitHub action to check links regularly. #90
Browse files Browse the repository at this point in the history
  • Loading branch information
SReichelt committed Jan 30, 2021
1 parent cea26d4 commit dea8bc1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 56 deletions.
2 changes: 1 addition & 1 deletion data/libraries/hlm
28 changes: 15 additions & 13 deletions src/scripts/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,20 @@ function checkItem(libraryDefinition: LibraryDefinition, libraryDataProvider: Li
});
}

if (process.argv.length !== 3) {
if (process.argv.length === 3) {
const libraryFileName = process.argv[2];
checkLibrary(libraryFileName)
.then(() => {
console.error(`Found ${errorCount} error(s) and ${warningCount} warning(s).`);
if (unexpectedError) {
process.exitCode = 1;
}
})
.catch((error) => {
console.error(error);
process.exitCode = 1;
});
} else {
console.error('usage: src/scripts/check.sh <libraryFile>');
process.exit(2);
process.exitCode = 2;
}

const libraryFileName = process.argv[2];
checkLibrary(libraryFileName)
.then(() => {
console.error(`Found ${errorCount} error(s) and ${warningCount} warning(s).`);
process.exit(unexpectedError ? 1 : 0);
})
.catch((error) => {
console.error(error);
process.exit(1);
});
28 changes: 19 additions & 9 deletions src/scripts/checkLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ const linkCheck = require('link-check');
let linksFound = 0;
let linksChecking = 0;
let linksChecked = 0;
let errors = 0;

function finished(): void {
console.log(`${linksChecked} links checked.`);
if (errors) {
console.log(`${errors} error(s) found.`);
process.exitCode = 1;
}
}

class LinkExtractor {
constructor(private fileName: string) {}
Expand All @@ -35,13 +44,15 @@ class LinkExtractor {
linkCheck(uri, (err: any, result: any) => {
if (err) {
console.error(`${this.fileName}: ${err}`);
errors++;
} else if (result.status !== 'alive') {
console.error(`${this.fileName}: ${result.status} link: ${result.link}`);
errors++;
}
linksChecking--;
linksChecked++;
if (linksChecked === linksFound) {
console.log(`${linksChecked} links checked.`);
finished();
}
});
} else {
Expand Down Expand Up @@ -80,13 +91,12 @@ function checkLinks(fileName: string): void {
}
}

if (process.argv.length < 3) {
if (process.argv.length >= 3) {
for (const fileName of process.argv.slice(2)) {
checkLinks(fileName);
}
console.log(`${linksFound} links found.`);
} else {
console.error('usage: src/scripts/checkLinks.sh <file1> [<file2>...]');
process.exit(2);
process.exitCode = 2;
}

for (const fileName of process.argv.slice(2)) {
checkLinks(fileName);
}

console.log(`${linksFound} links found.`);
22 changes: 11 additions & 11 deletions src/scripts/generateMetaDeclarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1417,16 +1417,16 @@ function generate(inFileName: string, outFileName: string, referencedMetaModels:
fs.writeFileSync(outFileName, outFileStr, 'utf8');
}

if (process.argv.length < 4) {
if (process.argv.length >= 4) {
const refs: ReferencedMetaModel[] = [];
for (let argIndex = 4; argIndex + 1 < process.argv.length; argIndex++) {
refs.push({
inFileName: process.argv[argIndex],
outFileName: process.argv[argIndex + 1]
});
}
generate(process.argv[2], process.argv[3], refs);
} else {
console.error('usage: src/scripts/generateMetaDeclarations.sh <infile> <outfile> [<refinfile> <refoutfile> [...]]');
process.exit(2);
}

const refs: ReferencedMetaModel[] = [];
for (let argIndex = 4; argIndex + 1 < process.argv.length; argIndex++) {
refs.push({
inFileName: process.argv[argIndex],
outFileName: process.argv[argIndex + 1]
});
process.exitCode = 2;
}
generate(process.argv[2], process.argv[3], refs);
12 changes: 6 additions & 6 deletions src/scripts/tidy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ function tidy(fileName: string): void {
}
}

if (process.argv.length < 3) {
if (process.argv.length >= 3) {
for (const fileName of process.argv.slice(2)) {
tidy(fileName);
}
} else {
console.error('usage: src/scripts/tidy.sh <file1> [<file2>...]');
process.exit(2);
}

for (const fileName of process.argv.slice(2)) {
tidy(fileName);
process.exitCode = 2;
}
16 changes: 8 additions & 8 deletions src/server/generic/static/buildPreload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ function outputPreload(libraryFileName: string, outputDirName: string): CachedPr
return preloadWriter.preloadLibrary(path.basename(libraryFileName, fileExtension));
}

if (process.argv.length !== 4) {
if (process.argv.length === 4) {
outputPreload(process.argv[2], process.argv[3])
.catch((error) => {
console.error(error);
process.exitCode = 1;
});
} else {
console.error('usage: node buildPreload.js <libraryFile> <outputDir>');
process.exit(2);
process.exitCode = 2;
}

outputPreload(process.argv[2], process.argv[3])
.catch((error) => {
console.error(error);
process.exit(1);
});
16 changes: 8 additions & 8 deletions src/server/generic/static/buildStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ function buildStaticPages(libraryFileName: string, logicName: string, htmlTempla
.then(() => libraryDataProvider.close());
}

if (process.argv.length !== 9) {
if (process.argv.length === 9) {
buildStaticPages(process.argv[2], process.argv[3], process.argv[4], process.argv[5], process.argv[6], process.argv[7], process.argv[8])
.catch((error) => {
console.error(error);
process.exitCode = 1;
});
} else {
console.error('usage: node buildStatic.js <libraryFile> <logic> <htmlTemplateFile> <notationTemplateFile> <libraryURL> <gitHubURL> <outputDir>');
process.exit(2);
process.exitCode = 2;
}

buildStaticPages(process.argv[2], process.argv[3], process.argv[4], process.argv[5], process.argv[6], process.argv[7], process.argv[8])
.catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit dea8bc1

Please sign in to comment.