Merge pull request #60 from SpraxDev/use-jdk-8

* GitHub Actions: Use JDK 8
* Use SpigotMC BuildTools by default
This commit is contained in:
Christian Koop 2021-04-01 21:53:05 +02:00 committed by GitHub
parent fd4df7496c
commit 3fa105973c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 187 additions and 171 deletions

View File

@ -21,6 +21,12 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
# Setup JDK version
- uses: actions/setup-java@v1
with:
java-version: '8'
java-package: jdk
- name: Compile 2 spigot version - name: Compile 2 spigot version
uses: ./ uses: ./
with: with:
@ -44,6 +50,13 @@ jobs:
original-run: original-run:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# Setup JDK version
- uses: actions/setup-java@v1
with:
# This version should probably match the ones from the 'run'-job
java-version: '8'
java-package: jdk
- name: Run original Spigot-BuildTools - name: Run original Spigot-BuildTools
# These versions should match the ones from the 'run'-job # These versions should match the ones from the 'run'-job
# Using '--compile Spigot' as this action does the same by default # Using '--compile Spigot' as this action does the same by default

View File

@ -73,7 +73,8 @@ as they are set automatically.
threads: -1 # Optional threads: -1 # Optional
# You can choose between different BuildTools to be used by this action # You can choose between different BuildTools to be used by this action
# 'SpraxDev' is my fork of SpigotMC's that introduces some changes (https://github.com/SpraxDev/Spigot-BuildTools/#breaking-changes) # ~~'SpraxDev' is my fork of SpigotMC's that introduces some changes (https://github.com/SpraxDev/Spigot-BuildTools/#breaking-changes)~~
# My (SpraxDev) provider is causing some builds to fail depending on the build environment
# Available: SpraxDev, SpigotMC # Available: SpraxDev, SpigotMC
buildToolProvider: SpraxDev # Optional buildToolProvider: SpigotMC # Optional
``` ```

View File

@ -33,8 +33,8 @@ inputs:
description: The amount of builds allowed to run at a time, set to '-1' to use system's cpu count description: The amount of builds allowed to run at a time, set to '-1' to use system's cpu count
buildToolProvider: buildToolProvider:
required: false required: false
default: SpraxDev default: SpigotMC
description: Whose BuildTool should be used? (SpraxDev [default], SpigotMC) description: Whose BuildTool should be used? (SpigotMC [default], SpraxDev)
runs: runs:
using: node12 using: node12

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

2
dist/package.json generated vendored
View File

@ -47,8 +47,8 @@
"@types/async": "^3.2.5", "@types/async": "^3.2.5",
"@types/fs-extra": "^9.0.6", "@types/fs-extra": "^9.0.6",
"@types/n-readlines": "^1.0.1", "@types/n-readlines": "^1.0.1",
"@vercel/ncc": "^0.26.1",
"@types/node": "~12.19.11", "@types/node": "~12.19.11",
"@vercel/ncc": "^0.26.1",
"ts-node": "^9.1.1", "ts-node": "^9.1.1",
"typescript": "^4.1.3" "typescript": "^4.1.3"
} }

View File

@ -47,8 +47,8 @@
"@types/async": "^3.2.5", "@types/async": "^3.2.5",
"@types/fs-extra": "^9.0.6", "@types/fs-extra": "^9.0.6",
"@types/n-readlines": "^1.0.1", "@types/n-readlines": "^1.0.1",
"@vercel/ncc": "^0.26.1",
"@types/node": "~12.19.11", "@types/node": "~12.19.11",
"@vercel/ncc": "^0.26.1",
"ts-node": "^9.1.1", "ts-node": "^9.1.1",
"typescript": "^4.1.3" "typescript": "^4.1.3"
} }

View File

@ -6,30 +6,30 @@ import { join as joinPath, resolve as resolvePath } from 'path';
import { xml2js } from 'xml-js'; import { xml2js } from 'xml-js';
import { import {
cpuCount, cpuCount,
downloadFile, downloadFile,
exit, exit,
fixArgArr, fixArgArr,
isNumeric, isNumeric,
readLastLines, readLastLines,
resetWorkingDir, resetWorkingDir,
runCmd, runCmd,
userHomeDir userHomeDir
} from './utils'; } from './utils';
const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[] } } = { const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[] } } = {
spraxdev: { spraxdev: {
url: 'https://github.com/SpraxDev/Spigot-BuildTools/releases/latest/download/BuildTools.jar', url: 'https://github.com/SpraxDev/Spigot-BuildTools/releases/latest/download/BuildTools.jar',
prepareArgs: ['--exit-after-fetch'] prepareArgs: ['--exit-after-fetch']
}, },
spigotmc: { spigotmc: {
url: 'https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar', url: 'https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar',
prepareArgs: ['--compile', 'None'] prepareArgs: ['--compile', 'None']
} }
}; };
/* GitHub Actions inputs */ /* GitHub Actions inputs */
const buildToolProvider: string = (core.getInput('buildToolProvider') || 'SpraxDev').toLowerCase(); const buildToolProvider: string = (core.getInput('buildToolProvider') || 'SpigotMC').toLowerCase();
let versions: string[] = fixArgArr((core.getInput('versions') || 'latest').toLowerCase().split(',')); let versions: string[] = fixArgArr((core.getInput('versions') || 'latest').toLowerCase().split(','));
const generateSrc: boolean = core.getInput('generateSrc') == 'true'; const generateSrc: boolean = core.getInput('generateSrc') == 'true';
const generateDoc: boolean = core.getInput('generateDoc') == 'true'; const generateDoc: boolean = core.getInput('generateDoc') == 'true';
@ -43,183 +43,185 @@ const appLogFile = joinPath(workingDir.logs, 'SpraxDev_Actions-SpigotMC.log');
const appLogStream = createWriteStream(appLogFile, {encoding: 'utf-8', flags: 'a' /* append */}); const appLogStream = createWriteStream(appLogFile, {encoding: 'utf-8', flags: 'a' /* append */});
async function run(): Promise<{ code: number, msg?: string }> { async function run(): Promise<{ code: number, msg?: string }> {
return new Promise(async (resolve, reject): Promise<void> => { return new Promise(async (resolve, reject): Promise<void> => {
try { try {
if (versions.length == 0) return resolve({code: 0, msg: 'No version(s) provided to build'}); if (versions.length == 0) return resolve({code: 0, msg: 'No version(s) provided to build'});
if (!Object.keys(supportedBuildTools).includes(buildToolProvider)) { if (!Object.keys(supportedBuildTools).includes(buildToolProvider)) {
return reject(new Error(`'${buildToolProvider}' is not a valid BuildTool-Provider (${Object.keys(supportedBuildTools).join(', ')})`)); return reject(new Error(`'${buildToolProvider}' is not a valid BuildTool-Provider (${Object.keys(supportedBuildTools).join(', ')})`));
} } else if (buildToolProvider == 'spraxdev') {
logError(`SpraxDev's BuildTool has known issues causing builds to fail, please use 'SpigotMC' if you encounter any problems`);
if (!forceRun) {
versions = await removeExistingVersions(versions, (ver, jarPath) => {
logInfo(`Skipping version '${ver}' because it has been found in the local maven repository: ${jarPath}`);
});
if (versions.length == 0) return resolve({code: 0, msg: 'No new versions to build'});
}
const buildTool = supportedBuildTools[buildToolProvider];
logInfo('Installed Java-Version:');
await runCmd('java', ['-version'], workingDir.base, appLogStream);
logInfo(`\nDownloading '${buildTool.url}'...`);
await downloadFile(buildTool.url, joinPath(workingDir.cache, 'BuildTools.jar'));
const gotTemplateDirectory = versions.length != 1;
// Prepare template directory if more than one version is provided
if (gotTemplateDirectory) {
logInfo('Prepare for future tasks by running BuildTools...');
await core.group('Prepare BuildTools', async (): Promise<void> => {
try {
return runCmd('java', ['-jar', 'BuildTools.jar', (disableJavaCheck ? '--disable-java-check' : ''), ...buildTool.prepareArgs],
workingDir.cache, appLogStream);
} catch (err) {
logError(err);
logError(`\nPrinting last 30 lines from '${resolvePath(appLogFile)}':`);
for (const line of readLastLines(appLogFile, 30)) {
logError(line);
} }
return exit(1); if (!forceRun) {
} versions = await removeExistingVersions(versions, (ver, jarPath) => {
}); logInfo(`Skipping version '${ver}' because it has been found in the local maven repository: ${jarPath}`);
} });
const buildToolsArgs = ['-jar', 'BuildTools.jar', '--compile', 'Spigot']; if (versions.length == 0) return resolve({code: 0, msg: 'No new versions to build'});
}
if (generateSrc) { const buildTool = supportedBuildTools[buildToolProvider];
buildToolsArgs.push('--generate-source');
}
if (generateDoc) { logInfo('Installed Java-Version:');
buildToolsArgs.push('--generate-docs'); await runCmd('java', ['-version'], workingDir.base, appLogStream);
}
if (disableJavaCheck) { logInfo(`\nDownloading '${buildTool.url}'...`);
buildToolsArgs.push('--disable-java-check'); await downloadFile(buildTool.url, joinPath(workingDir.cache, 'BuildTools.jar'));
}
const tasks = []; const gotTemplateDirectory = versions.length != 1;
for (const ver of versions) {
tasks.push(async (): Promise<void> => {
return new Promise(async (resolveTask, rejectTask): Promise<void> => {
const start = Date.now();
const logFile = joinPath(workingDir.logs, `${ver}.log`);
logInfo(`Building version '${ver}'...`);
// If there is only one version to build, the cache directory is used instead of copying it first
const versionDir = gotTemplateDirectory ? joinPath(workingDir.base, `${ver}`) : workingDir.cache;
// Prepare template directory if more than one version is provided
if (gotTemplateDirectory) { if (gotTemplateDirectory) {
await copy(workingDir.cache, versionDir); logInfo('Prepare for future tasks by running BuildTools...');
await core.group('Prepare BuildTools', async (): Promise<void> => {
try {
return runCmd('java', ['-jar', 'BuildTools.jar', (disableJavaCheck ? '--disable-java-check' : ''), ...buildTool.prepareArgs],
workingDir.cache, appLogStream);
} catch (err) {
logError(err);
logError(`\nPrinting last 30 lines from '${resolvePath(appLogFile)}':`);
for (const line of readLastLines(appLogFile, 30)) {
logError(line);
}
return exit(1);
}
});
} }
try { const buildToolsArgs = ['-jar', 'BuildTools.jar', '--compile', 'Spigot'];
// set to silent because multiple builds can run at once
await runCmd('java', [...buildToolsArgs, '--rev', ver], versionDir, logFile, true);
if (gotTemplateDirectory) { if (generateSrc) {
rmdirSync(versionDir, {recursive: true}); // delete our task dir buildToolsArgs.push('--generate-source');
}
const end = Date.now();
logInfo(`Finished '${ver}' in ${((end - start) / 60_000).toFixed(2)} minutes`);
resolveTask();
} catch (err) {
logInfo(`An error occurred while building '${ver}'`);
logError(err);
logError(`\nPrinting last 30 lines from '${resolvePath(logFile)}':`);
for (const line of readLastLines(logFile, 30)) {
logError(line);
}
rejectTask(err);
} }
});
});
}
parallelLimit(tasks, threadCount, (err) => { if (generateDoc) {
if (err) return reject(err); buildToolsArgs.push('--generate-docs');
}
resolve({code: 0}); if (disableJavaCheck) {
}); buildToolsArgs.push('--disable-java-check');
} catch (err) { }
reject(err);
} const tasks = [];
}); for (const ver of versions) {
tasks.push(async (): Promise<void> => {
return new Promise(async (resolveTask, rejectTask): Promise<void> => {
const start = Date.now();
const logFile = joinPath(workingDir.logs, `${ver}.log`);
logInfo(`Building version '${ver}'...`);
// If there is only one version to build, the cache directory is used instead of copying it first
const versionDir = gotTemplateDirectory ? joinPath(workingDir.base, `${ver}`) : workingDir.cache;
if (gotTemplateDirectory) {
await copy(workingDir.cache, versionDir);
}
try {
// set to silent because multiple builds can run at once
await runCmd('java', [...buildToolsArgs, '--rev', ver], versionDir, logFile, true);
if (gotTemplateDirectory) {
rmdirSync(versionDir, {recursive: true}); // delete our task dir
}
const end = Date.now();
logInfo(`Finished '${ver}' in ${((end - start) / 60_000).toFixed(2)} minutes`);
resolveTask();
} catch (err) {
logInfo(`An error occurred while building '${ver}'`);
logError(err);
logError(`\nPrinting last 30 lines from '${resolvePath(logFile)}':`);
for (const line of readLastLines(logFile, 30)) {
logError(line);
}
rejectTask(err);
}
});
});
}
parallelLimit(tasks, threadCount, (err) => {
if (err) return reject(err);
resolve({code: 0});
});
} catch (err) {
reject(err);
}
});
} }
async function removeExistingVersions(versionArr: string[], onExist: (ver: string, jarPath: string) => void): Promise<string[]> { async function removeExistingVersions(versionArr: string[], onExist: (ver: string, jarPath: string) => void): Promise<string[]> {
return new Promise(async (resolve, _reject): Promise<void> => { return new Promise(async (resolve, _reject): Promise<void> => {
const result = []; const result = [];
for (const ver of versionArr) { for (const ver of versionArr) {
let skipVersion = false; let skipVersion = false;
let versionToCheck: string | null = ver != 'latest' ? ver : null; let versionToCheck: string | null = ver != 'latest' ? ver : null;
try { try {
const verJsonBuff = await downloadFile(`https://hub.spigotmc.org/versions/${ver}.json`, null); const verJsonBuff = await downloadFile(`https://hub.spigotmc.org/versions/${ver}.json`, null);
const verJson = verJsonBuff instanceof Buffer ? JSON.parse(verJsonBuff.toString('utf-8')) : null; const verJson = verJsonBuff instanceof Buffer ? JSON.parse(verJsonBuff.toString('utf-8')) : null;
const bukkitRef: undefined | string = verJson?.refs?.Bukkit; const bukkitRef: undefined | string = verJson?.refs?.Bukkit;
if (bukkitRef) { if (bukkitRef) {
const verPomBuff = await downloadFile(`https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/raw/pom.xml?at=${bukkitRef}`, null); const verPomBuff = await downloadFile(`https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/raw/pom.xml?at=${bukkitRef}`, null);
if (verPomBuff instanceof Buffer) { if (verPomBuff instanceof Buffer) {
const result = xml2js(verPomBuff.toString('utf-8'), { const result = xml2js(verPomBuff.toString('utf-8'), {
compact: true, compact: true,
ignoreComment: true, ignoreComment: true,
ignoreAttributes: true ignoreAttributes: true
}) as any; }) as any;
versionToCheck = result.project?.version?._text; versionToCheck = result.project?.version?._text;
} }
}
} catch (err) {
logError(err);
}
const jarPath = resolvePath(joinPath(userHomeDir, `/.m2/repository/org/spigotmc/spigot/${versionToCheck}/spigot-${versionToCheck}.jar`));
if (versionToCheck) {
skipVersion = existsSync(jarPath);
}
if (skipVersion) {
onExist(ver, jarPath);
} else {
result.push(ver);
}
} }
} catch (err) {
logError(err);
}
const jarPath = resolvePath(joinPath(userHomeDir, `/.m2/repository/org/spigotmc/spigot/${versionToCheck}/spigot-${versionToCheck}.jar`)); resolve(result);
if (versionToCheck) { });
skipVersion = existsSync(jarPath);
}
if (skipVersion) {
onExist(ver, jarPath);
} else {
result.push(ver);
}
}
resolve(result);
});
} }
export function logInfo(msg?: string): void { export function logInfo(msg?: string): void {
console.log(msg); console.log(msg);
appLogStream.write(msg + '\n'); appLogStream.write(msg + '\n');
} }
export function logError(msg?: string | object): void { export function logError(msg?: string | object): void {
if (typeof msg != 'string') { if (typeof msg != 'string') {
msg = JSON.stringify(msg, null, 2); msg = JSON.stringify(msg, null, 2);
} }
console.error(msg); console.error(msg);
appLogStream.write(msg + '\n'); appLogStream.write(msg + '\n');
} }
run() run()
.then((result) => exit(result.code, result.msg)) .then((result) => exit(result.code, result.msg))
.catch((err) => exit(1, err)); .catch((err) => exit(1, err));