From 5ca83a4c039aada0cfd413574fde043aed6e2b04 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 11 Apr 2021 01:58:51 +0200 Subject: [PATCH] Experimenting with GH actions --- .github/workflows/pull_request_check.yml | 13 ++++++++++- package.json | 4 ++-- scripts/generateLayerOverview.ts | 28 ++++++++++++------------ scripts/generateLicenseInfo.ts | 27 +++++++++++------------ 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/.github/workflows/pull_request_check.yml b/.github/workflows/pull_request_check.yml index 976311d9e..e7dccb2bd 100644 --- a/.github/workflows/pull_request_check.yml +++ b/.github/workflows/pull_request_check.yml @@ -2,7 +2,10 @@ name: Pull request check on: pull_request: types: [opened, edited, synchronize, ready_for_review, review_requested] - + push: + - master + - develop + jobs: build: runs-on: ubuntu-latest @@ -33,3 +36,11 @@ jobs: - name: Validate license info run: npm run validate:licenses + - name: Set failure key + run: | + if [[ -f "layer_report.txt" || -f "missing_licenses.txt" ]]; then + echo "VALIDATION_FAILED=true" >>$GITHUB_ENV + fi + + - name: Test variable + run: echo "${{ env.VALIDATION_FAILED }}" \ No newline at end of file diff --git a/package.json b/package.json index 442d3195d..be63bb492 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ "generate:docs": "ts-node scripts/generateDocs.ts", "generate:layeroverview": "ts-node scripts/generateLayerOverview.ts --no-fail", "generate:licenses": "ts-node scripts/generateLicenseInfo.ts --no-fail", - "validate:layeroverview": "ts-node scripts/generateLayerOverview.ts", - "validate:licenses": "ts-node scripts/generateLicenseInfo.ts", + "validate:layeroverview": "ts-node scripts/generateLayerOverview.ts --report --no-fail", + "validate:licenses": "ts-node scripts/generateLicenseInfo.ts --report --no-fail", "optimize-images": "cd assets/generated/ && find -name '*.png' -exec optipng '{}' \\; && echo 'PNGs are optimized'", "generate": "npm run generate:images && npm run generate:translations && npm run generate:licenses", "build": "rm -rf dist/ && npm run generate && parcel build --public-url ./ *.html assets/** assets/**/** assets/**/**/** vendor/* vendor/*/*", diff --git a/scripts/generateLayerOverview.ts b/scripts/generateLayerOverview.ts index 638b50b64..a5eea0aff 100644 --- a/scripts/generateLayerOverview.ts +++ b/scripts/generateLayerOverview.ts @@ -61,7 +61,7 @@ function validateLayer(layerJson: LayerConfigJson, context?: string): string[] { const images = Array.from(layer.ExtractImages()) const remoteImages = images.filter(img => img.indexOf("http") == 0) for (const remoteImage of remoteImages) { - errorCount.push("Found a remote image: "+ remoteImage+ " in layer "+ layer.id) + errorCount.push("Found a remote image: " + remoteImage + " in layer " + layer.id) } for (const image of images) { if (!knownPaths.has(image)) { @@ -71,7 +71,7 @@ function validateLayer(layerJson: LayerConfigJson, context?: string): string[] { } } catch (e) { - return [`Layer ${layerJson.id}` ?? JSON.stringify(layerJson).substring(0, 50)+" is invalid: "+ e] + return [`Layer ${layerJson.id}` ?? JSON.stringify(layerJson).substring(0, 50) + " is invalid: " + e] } return errorCount } @@ -80,7 +80,7 @@ let layerErrorCount = [] const knownLayerIds = new Set(); for (const layerFile of layerFiles) { knownLayerIds.add(layerFile.id) - layerErrorCount .push(...validateLayer(layerFile)) + layerErrorCount.push(...validateLayer(layerFile)) } let themeErrorCount = [] @@ -89,16 +89,16 @@ for (const themeFile of themeFiles) { for (const layer of themeFile.layers) { if (typeof layer === "string") { if (!knownLayerIds.has(layer)) { - themeErrorCount.push("Unknown layer id: "+ layer) + themeErrorCount.push("Unknown layer id: " + layer) } } else { if (layer.builtin !== undefined) { if (!knownLayerIds.has(layer.builtin)) { - themeErrorCount.push("Unknown layer id: "+ layer.builtin+ "(which uses inheritance)") - } + themeErrorCount.push("Unknown layer id: " + layer.builtin + "(which uses inheritance)") + } } else { // layer.builtin contains layer overrides - we can skip those - layerErrorCount .push(...validateLayer(layer, themeFile.id)) + layerErrorCount.push(...validateLayer(layer, themeFile.id)) } } } @@ -110,10 +110,10 @@ for (const themeFile of themeFiles) { try { const theme = new LayoutConfig(themeFile, true, "test") if (theme.id !== theme.id.toLowerCase()) { - themeErrorCount.push("Theme ids should be in lowercase, but it is "+ theme.id) + themeErrorCount.push("Theme ids should be in lowercase, but it is " + theme.id) } } catch (e) { - themeErrorCount.push("Could not parse theme "+ themeFile["id"]+ "due to", e) + themeErrorCount.push("Could not parse theme " + themeFile["id"] + "due to", e) } } @@ -125,12 +125,12 @@ if (layerErrorCount.length + themeErrorCount.length == 0) { const errors = layerErrorCount.concat(themeErrorCount).join("\n") console.log(errors) const msg = (`Found ${errors.length} errors in the layers; ${themeErrorCount} errors in the themes`) - if(process.argv.indexOf("--no-fail") >= 0) { - console.log(msg) - }else if(process.argv.indexOf("--report") >= 0){ + console.log(msg) + if (process.argv.indexOf("--report") >= 0) { writeFileSync("layer_report.txt", errors) - }else{ - + } + + if (process.argv.indexOf("--no-fail") < 0) { throw msg; } } diff --git a/scripts/generateLicenseInfo.ts b/scripts/generateLicenseInfo.ts index 39c96e81d..409f75e16 100644 --- a/scripts/generateLicenseInfo.ts +++ b/scripts/generateLicenseInfo.ts @@ -27,7 +27,7 @@ function generateLicenseInfos(paths: string[]): SmallLicense[] { parsed.license === "CC-BY 4.0" writeFileSync(path, JSON.stringify(smallLicens, null, " ")) }*/ - + smallLicens.path = path.substring(0, 1 + path.lastIndexOf("/")) + smallLicens.path licenses.push(smallLicens) } @@ -140,32 +140,32 @@ function createLicenseInfoFor(path): void { writeFileSync(path + ".license_info.json", JSON.stringify(li, null, " ")) } -function cleanLicenseInfo(allPaths: string[], allLicenseInfos: SmallLicense[]){ +function cleanLicenseInfo(allPaths: string[], allLicenseInfos: SmallLicense[]) { // Read the license info file from the generated assets, creates a compiled license info in every directory // Note: this removes all the old license infos for (const licensePath of licensePaths) { unlinkSync(licensePath) } - + const perDirectory = new Map() for (const license of allLicenseInfos) { const p = license.path const dir = p.substring(0, p.lastIndexOf("/")) license.path = p.substring(dir.length + 1) - if(!perDirectory.has(dir)){ + if (!perDirectory.has(dir)) { perDirectory.set(dir, []) } perDirectory.get(dir).push(license) } - + perDirectory.forEach((licenses, dir) => { - writeFileSync( dir+"/license_info.json", JSON.stringify(licenses, null, 2)) + writeFileSync(dir + "/license_info.json", JSON.stringify(licenses, null, 2)) }) - + } -function queryMissingLicenses(missingLicenses: string[]) { +function queryMissingLicenses(missingLicenses: string[]) { process.on('SIGINT', function () { console.log("Aborting... Bye!"); process.exit(); @@ -195,17 +195,16 @@ const artwork = contents.filter(pth => pth.match(/(.svg|.png|.jpg)$/i) != null) const missingLicenses = missingLicenseInfos(licenseInfos, artwork) -if(process.argv.indexOf("--prompt") >= 0 || process.argv.indexOf("--query") >= 0 ) { +if (process.argv.indexOf("--prompt") >= 0 || process.argv.indexOf("--query") >= 0) { queryMissingLicenses(missingLicenses) } -if(missingLicenses.length > 0){ +if (missingLicenses.length > 0) { const msg = `There are ${missingLicenses.length} licenses missing.` console.error(msg) - if(process.argv.indexOf("--no-fail") >= 0){ - - }else if(process.argv.indexOf("--report") >= 0){ + if (process.argv.indexOf("--report") >= 0) { writeFileSync("missing_licenses.txt", missingLicenses.join("\n")) - } else{ + } + if (process.argv.indexOf("--no-fail") < 0) { throw msg } }