Experimenting with GH actions

This commit is contained in:
pietervdvn 2021-04-11 01:58:51 +02:00
parent 04b83311f7
commit 5ca83a4c03
4 changed files with 41 additions and 31 deletions

View file

@ -2,6 +2,9 @@ name: Pull request check
on:
pull_request:
types: [opened, edited, synchronize, ready_for_review, review_requested]
push:
- master
- develop
jobs:
build:
@ -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 }}"

View file

@ -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/*/*",

View file

@ -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<string>();
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;
}
}

View file

@ -140,7 +140,7 @@ 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) {
@ -153,19 +153,19 @@ function cleanLicenseInfo(allPaths: string[], allLicenseInfos: SmallLicense[]){
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
}
}