Merge pull request #60 from SpraxDev/use-jdk-8
* GitHub Actions: Use JDK 8 * Use SpigotMC BuildTools by default
This commit is contained in:
parent
fd4df7496c
commit
3fa105973c
|
@ -21,6 +21,12 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
# Setup JDK version
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: '8'
|
||||
java-package: jdk
|
||||
|
||||
- name: Compile 2 spigot version
|
||||
uses: ./
|
||||
with:
|
||||
|
@ -44,6 +50,13 @@ jobs:
|
|||
original-run:
|
||||
runs-on: ubuntu-latest
|
||||
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
|
||||
# These versions should match the ones from the 'run'-job
|
||||
# Using '--compile Spigot' as this action does the same by default
|
||||
|
|
|
@ -73,7 +73,8 @@ as they are set automatically.
|
|||
threads: -1 # Optional
|
||||
|
||||
# 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
|
||||
buildToolProvider: SpraxDev # Optional
|
||||
buildToolProvider: SpigotMC # Optional
|
||||
```
|
|
@ -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
|
||||
buildToolProvider:
|
||||
required: false
|
||||
default: SpraxDev
|
||||
description: Whose BuildTool should be used? (SpraxDev [default], SpigotMC)
|
||||
default: SpigotMC
|
||||
description: Whose BuildTool should be used? (SpigotMC [default], SpraxDev)
|
||||
|
||||
runs:
|
||||
using: node12
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -47,8 +47,8 @@
|
|||
"@types/async": "^3.2.5",
|
||||
"@types/fs-extra": "^9.0.6",
|
||||
"@types/n-readlines": "^1.0.1",
|
||||
"@vercel/ncc": "^0.26.1",
|
||||
"@types/node": "~12.19.11",
|
||||
"@vercel/ncc": "^0.26.1",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.1.3"
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@
|
|||
"@types/async": "^3.2.5",
|
||||
"@types/fs-extra": "^9.0.6",
|
||||
"@types/n-readlines": "^1.0.1",
|
||||
"@vercel/ncc": "^0.26.1",
|
||||
"@types/node": "~12.19.11",
|
||||
"@vercel/ncc": "^0.26.1",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "^4.1.3"
|
||||
}
|
||||
|
|
326
src/index.ts
326
src/index.ts
|
@ -6,30 +6,30 @@ import { join as joinPath, resolve as resolvePath } from 'path';
|
|||
import { xml2js } from 'xml-js';
|
||||
|
||||
import {
|
||||
cpuCount,
|
||||
downloadFile,
|
||||
exit,
|
||||
fixArgArr,
|
||||
isNumeric,
|
||||
readLastLines,
|
||||
resetWorkingDir,
|
||||
runCmd,
|
||||
userHomeDir
|
||||
cpuCount,
|
||||
downloadFile,
|
||||
exit,
|
||||
fixArgArr,
|
||||
isNumeric,
|
||||
readLastLines,
|
||||
resetWorkingDir,
|
||||
runCmd,
|
||||
userHomeDir
|
||||
} from './utils';
|
||||
|
||||
const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[] } } = {
|
||||
spraxdev: {
|
||||
url: 'https://github.com/SpraxDev/Spigot-BuildTools/releases/latest/download/BuildTools.jar',
|
||||
prepareArgs: ['--exit-after-fetch']
|
||||
},
|
||||
spigotmc: {
|
||||
url: 'https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar',
|
||||
prepareArgs: ['--compile', 'None']
|
||||
}
|
||||
spraxdev: {
|
||||
url: 'https://github.com/SpraxDev/Spigot-BuildTools/releases/latest/download/BuildTools.jar',
|
||||
prepareArgs: ['--exit-after-fetch']
|
||||
},
|
||||
spigotmc: {
|
||||
url: 'https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar',
|
||||
prepareArgs: ['--compile', 'None']
|
||||
}
|
||||
};
|
||||
|
||||
/* 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(','));
|
||||
const generateSrc: boolean = core.getInput('generateSrc') == '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 */});
|
||||
|
||||
async function run(): Promise<{ code: number, msg?: string }> {
|
||||
return new Promise(async (resolve, reject): Promise<void> => {
|
||||
try {
|
||||
if (versions.length == 0) return resolve({code: 0, msg: 'No version(s) provided to build'});
|
||||
return new Promise(async (resolve, reject): Promise<void> => {
|
||||
try {
|
||||
if (versions.length == 0) return resolve({code: 0, msg: 'No version(s) provided to build'});
|
||||
|
||||
if (!Object.keys(supportedBuildTools).includes(buildToolProvider)) {
|
||||
return reject(new Error(`'${buildToolProvider}' is not a valid BuildTool-Provider (${Object.keys(supportedBuildTools).join(', ')})`));
|
||||
}
|
||||
|
||||
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);
|
||||
if (!Object.keys(supportedBuildTools).includes(buildToolProvider)) {
|
||||
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`);
|
||||
}
|
||||
|
||||
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) {
|
||||
buildToolsArgs.push('--generate-source');
|
||||
}
|
||||
const buildTool = supportedBuildTools[buildToolProvider];
|
||||
|
||||
if (generateDoc) {
|
||||
buildToolsArgs.push('--generate-docs');
|
||||
}
|
||||
logInfo('Installed Java-Version:');
|
||||
await runCmd('java', ['-version'], workingDir.base, appLogStream);
|
||||
|
||||
if (disableJavaCheck) {
|
||||
buildToolsArgs.push('--disable-java-check');
|
||||
}
|
||||
logInfo(`\nDownloading '${buildTool.url}'...`);
|
||||
await downloadFile(buildTool.url, joinPath(workingDir.cache, 'BuildTools.jar'));
|
||||
|
||||
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;
|
||||
const gotTemplateDirectory = versions.length != 1;
|
||||
|
||||
// Prepare template directory if more than one version is provided
|
||||
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 {
|
||||
// set to silent because multiple builds can run at once
|
||||
await runCmd('java', [...buildToolsArgs, '--rev', ver], versionDir, logFile, true);
|
||||
const buildToolsArgs = ['-jar', 'BuildTools.jar', '--compile', 'Spigot'];
|
||||
|
||||
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);
|
||||
if (generateSrc) {
|
||||
buildToolsArgs.push('--generate-source');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
parallelLimit(tasks, threadCount, (err) => {
|
||||
if (err) return reject(err);
|
||||
if (generateDoc) {
|
||||
buildToolsArgs.push('--generate-docs');
|
||||
}
|
||||
|
||||
resolve({code: 0});
|
||||
});
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
if (disableJavaCheck) {
|
||||
buildToolsArgs.push('--disable-java-check');
|
||||
}
|
||||
|
||||
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[]> {
|
||||
return new Promise(async (resolve, _reject): Promise<void> => {
|
||||
const result = [];
|
||||
return new Promise(async (resolve, _reject): Promise<void> => {
|
||||
const result = [];
|
||||
|
||||
for (const ver of versionArr) {
|
||||
let skipVersion = false;
|
||||
let versionToCheck: string | null = ver != 'latest' ? ver : null;
|
||||
for (const ver of versionArr) {
|
||||
let skipVersion = false;
|
||||
let versionToCheck: string | null = ver != 'latest' ? ver : null;
|
||||
|
||||
try {
|
||||
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 bukkitRef: undefined | string = verJson?.refs?.Bukkit;
|
||||
try {
|
||||
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 bukkitRef: undefined | string = verJson?.refs?.Bukkit;
|
||||
|
||||
if (bukkitRef) {
|
||||
const verPomBuff = await downloadFile(`https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/raw/pom.xml?at=${bukkitRef}`, null);
|
||||
if (bukkitRef) {
|
||||
const verPomBuff = await downloadFile(`https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/raw/pom.xml?at=${bukkitRef}`, null);
|
||||
|
||||
if (verPomBuff instanceof Buffer) {
|
||||
const result = xml2js(verPomBuff.toString('utf-8'), {
|
||||
compact: true,
|
||||
ignoreComment: true,
|
||||
ignoreAttributes: true
|
||||
}) as any;
|
||||
if (verPomBuff instanceof Buffer) {
|
||||
const result = xml2js(verPomBuff.toString('utf-8'), {
|
||||
compact: true,
|
||||
ignoreComment: true,
|
||||
ignoreAttributes: true
|
||||
}) 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`));
|
||||
if (versionToCheck) {
|
||||
skipVersion = existsSync(jarPath);
|
||||
}
|
||||
|
||||
if (skipVersion) {
|
||||
onExist(ver, jarPath);
|
||||
} else {
|
||||
result.push(ver);
|
||||
}
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
});
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
|
||||
export function logInfo(msg?: string): void {
|
||||
console.log(msg);
|
||||
appLogStream.write(msg + '\n');
|
||||
console.log(msg);
|
||||
appLogStream.write(msg + '\n');
|
||||
}
|
||||
|
||||
export function logError(msg?: string | object): void {
|
||||
if (typeof msg != 'string') {
|
||||
msg = JSON.stringify(msg, null, 2);
|
||||
}
|
||||
if (typeof msg != 'string') {
|
||||
msg = JSON.stringify(msg, null, 2);
|
||||
}
|
||||
|
||||
console.error(msg);
|
||||
appLogStream.write(msg + '\n');
|
||||
console.error(msg);
|
||||
appLogStream.write(msg + '\n');
|
||||
}
|
||||
|
||||
run()
|
||||
.then((result) => exit(result.code, result.msg))
|
||||
.catch((err) => exit(1, err));
|
||||
.then((result) => exit(result.code, result.msg))
|
||||
.catch((err) => exit(1, err));
|
Loading…
Reference in New Issue