Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Jul 12, 2022
2 parents 1f01304 + e438319 commit 13ac1e6
Show file tree
Hide file tree
Showing 382 changed files with 10,600 additions and 4,543 deletions.
5 changes: 5 additions & 0 deletions .github/actions/ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ./github/actions/ci

Standalone files may be stored directly in this directory. (as long as they are used for the ci workflows)

Those that have dependencies (e.g. node_modules for node & composer for php) are stored in subdirectories.
25 changes: 25 additions & 0 deletions .github/actions/ci/kubejs-list-hose-pulley-fluids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fsp = require('fs/promises');

fsp
.readFile('kubejs/exported/kubejs-server-export.json')
.then(data => {
const exported = JSON.parse(data.toString());

let blacklisted = exported.tags.fluids['create:no_infinite_draining'];
let whitelisted = exported.registries.fluids.filter(fluid_id => !blacklisted.includes(fluid_id));

whitelisted = whitelisted.filter(fluid_id => {
const fluid_name = fluid_id.split(':')[1];

if (fluid_name.startsWith('flowing_')) return false;
if (fluid_name.endsWith('_flowing')) return false;

if (fluid_name.startsWith('fluid_')) return false;
if (fluid_name.endsWith('_fluid')) return false;

return true;
});

console.log(whitelisted);
console.log(`::notice::${whitelisted.length} fluids can be used with the hose pulley.`);
});
68 changes: 0 additions & 68 deletions .github/actions/ci/kubejs-todo-remove.js

This file was deleted.

25 changes: 17 additions & 8 deletions .github/actions/ci/log-kubejs-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@
// and determining whether it contained errors or not.

const fs = require('fs');

const server = fs.readFileSync('logs/kubejs/server.txt', 'utf-8');

let code = 0;
let warnings = [];

server.split(/\r?\n/).forEach((line) => {
if (line.includes('[ERR ] Error')) {
console.log(`::warning::${line}`);
code = 1;
} else if (line.includes('[ERR ]') || line.includes('[WARN ]')) {
console.log(line);

// the 2nd reload causes this error, avoid reporting this
if (line.includes('shadows.menu.PackMenuClient')) return;

// get the log level from this line, expected values: [ undefined, INFO, WARN, ERR ]
const in_brackets = line.match(/\[\d{2}:\d{2}:\d{2}] \[([A-Z\s]+)]/)?.[1];

switch (in_brackets) {
case 'ERR ': warnings.push(line);
case 'WARN ': console.log(line);
}
});

process.exit(code);
warnings.forEach(warning => {
console.log(`::warning::${warning}`);
});

// return with exit code 1 for any warning amount
process.exit(Math.min(1, warnings.length));
3 changes: 3 additions & 0 deletions .github/actions/ci/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules/
/artifact.zip
/artifact/
60 changes: 60 additions & 0 deletions .github/actions/ci/node/compare_artifact-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { exec, execSync } = require("child_process")
const fs = require("fs")
const util = require('node:util')

const negative = '\x1B[31m- #'
const positive = '\x1B[32m+\x1B[m\x1B[32m #'

const a = __dirname + '/artifact' // base
const b = __dirname + '/../../../..' // head

const kubejs = {
[a]: JSON.parse(fs.readFileSync(`${a}/kubejs/exported/kubejs-server-export.json`)),
[b]: JSON.parse(fs.readFileSync(`${b}/kubejs/exported/kubejs-server-export.json`)),
}

let changes = 0
let notices = []

// [ 'blocks', 'items', 'fluids', 'entity_types' ]
const types = Object.keys({...kubejs[a].tags, ...kubejs[b].tags})

types.forEach(type => {
[a, b].forEach(c => {
let lines = []

const keys = Object.keys(kubejs[c].tags[type]).sort()
keys.forEach(key => {
kubejs[c].tags[type][key].sort().forEach(item => lines.push(` #${key} > ${item}`))
lines.push('')
})

fs.writeFileSync(`${c}/kubejs/exported/tags/${type}.txt`, lines.join('\n'))
})

let diff = execSync(`git --no-pager diff --color --no-index '${a}/kubejs/exported/tags/${type}.txt' '${b}/kubejs/exported/tags/${type}.txt' || true`).toString()

let positives = 0
let negatives = 0

diff.split('\n').forEach(line => {
if (diff == '') return

// remove the + and - for empty lines
if (line == '\x1B[31m-\x1B[m' || line == '\x1B[32m+\x1B[m') line = '\x1B[m'
console.log(line) // debug: console.log(util.inspect(line, {colors: false}))

if (line.startsWith(positive)) {
positives++
changes++
} else
if (line.startsWith(negative)) {
negatives++
changes++
}
})

notices.push(`${type}(+${positives} -${negatives})`)
})

console.log(`::notice::${changes} changes to tags: ${notices.join(' ')}`)
43 changes: 43 additions & 0 deletions .github/actions/ci/node/compare_download-artifact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This script runs for pull requests, it downloads the artifact for the target branch.

const { default: axios } = require("axios")
const { exec } = require("child_process")
const fsp = require("fs/promises")

const arg_repo = process.argv[2]
const arg_hash = process.argv[3]
const arg_mode = process.argv[4]
const arg_auth = process.argv[5]

const name = `server (${arg_mode})`

axios.defaults.headers.common = {
'Accept': 'application/vnd.github.v3+json',
'Authorization': `token ${arg_auth}`,
}

// axios.get('https://api.github.com/user').then(response => {
// console.log(response.data);
// })

axios
.get(`https://api.github.com/repos/${arg_repo}/actions/artifacts`)
.then(response => {
let artifact = response.data.artifacts.find(artifact => {
return artifact.name == name && artifact.workflow_run.head_sha == arg_hash
})

console.log(artifact)
if (!artifact) throw new Error(`Artifact not found.`)

// ensure unzip target does not exist
exec(`rm -r '${__dirname}/artifact'`)

axios.get(artifact.archive_download_url, {responseType: 'stream'}).then(response => {
console.log('downloaded, saving...')
fsp.writeFile(`${__dirname}/artifact.zip`, response.data).then(() => {
console.log('saved, unzipping...')
exec(`unzip '${__dirname}/artifact.zip' -d '${__dirname}/artifact'`, (error, stdout, stderr) => console.log(stdout))
})
})
})
42 changes: 42 additions & 0 deletions .github/actions/ci/node/kubejs-list-global-variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const fs = require('fs')
const clc = require('cli-color');

// each of the kubejs log files
const filenames = ['startup', 'client', 'server'];

const loaded_script = / Loaded script (.*) in /;
const new_global = / - new global variable: (.*)/;

// color the string from the point where `Loaded script` & `- new global` starts
function console_log(color, line) {
const matches = line.match(/\[INFO ] (SourceFile:\d+: )?(.*)/);
console.log(color(matches[2]));
}

// filter out the lines that do not relate to `new global variable` and its context
filenames.forEach(filename => {
console.log(clc.blue(`${filename}.txt:`));
const lines = fs.readFileSync(`./logs/kubejs/${filename}.txt`).toString().split('\n');

let color = null;

lines.forEach((line, i) => {

if (new_global.test(line)) {
const previous_line = lines[i-1];
if (loaded_script.test(previous_line)) {

// - anything that likely shouldn't be global is red
// - anything defined the constants becomes is green
// - anything defined in the function file is yellow

color = clc.red;
if (previous_line.includes('constants')) color = clc.green;
if (previous_line.includes('functions')) color = clc.yellow;

console_log(color, previous_line);
}
console_log(color, line);
}
});
});
Loading

0 comments on commit 13ac1e6

Please sign in to comment.