Check for existing artifacts in local maven repository
This commit is contained in:
parent
e6e1593004
commit
3a72e11367
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -33,7 +33,8 @@
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"async": "^3.2.0",
|
"async": "^3.2.0",
|
||||||
"fs-extra": "^9.0.1",
|
"fs-extra": "^9.0.1",
|
||||||
"n-readlines": "^1.0.1"
|
"n-readlines": "^1.0.1",
|
||||||
|
"xml-js": "^1.6.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/node12": "^1.0.7",
|
"@tsconfig/node12": "^1.0.7",
|
||||||
|
|
|
@ -122,6 +122,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/n-readlines/-/n-readlines-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/n-readlines/-/n-readlines-1.0.1.tgz",
|
||||||
"integrity": "sha512-z4SyAIVgMy7CkgsoNw7YVz40v0g4+WWvvqy8+ZdHrCtgevcEO758WQyrYcw3XPxcLxF+//RszTz/rO48nzD0wQ=="
|
"integrity": "sha512-z4SyAIVgMy7CkgsoNw7YVz40v0g4+WWvvqy8+ZdHrCtgevcEO758WQyrYcw3XPxcLxF+//RszTz/rO48nzD0wQ=="
|
||||||
},
|
},
|
||||||
|
"sax": {
|
||||||
|
"version": "1.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
||||||
|
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
|
||||||
|
},
|
||||||
"source-map": {
|
"source-map": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
|
@ -162,6 +167,14 @@
|
||||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz",
|
||||||
"integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug=="
|
"integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug=="
|
||||||
},
|
},
|
||||||
|
"xml-js": {
|
||||||
|
"version": "1.6.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz",
|
||||||
|
"integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==",
|
||||||
|
"requires": {
|
||||||
|
"sax": "^1.2.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"yn": {
|
"yn": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"async": "^3.2.0",
|
"async": "^3.2.0",
|
||||||
"fs-extra": "^9.0.1",
|
"fs-extra": "^9.0.1",
|
||||||
"n-readlines": "^1.0.1"
|
"n-readlines": "^1.0.1",
|
||||||
|
"xml-js": "^1.6.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/node12": "^1.0.7",
|
"@tsconfig/node12": "^1.0.7",
|
||||||
|
|
83
src/index.ts
83
src/index.ts
|
@ -1,10 +1,21 @@
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { join as joinPath, resolve as resolvePath } from 'path';
|
|
||||||
import { copy } from 'fs-extra';
|
|
||||||
import { rmdirSync } from 'fs';
|
|
||||||
import { parallelLimit } from 'async';
|
import { parallelLimit } from 'async';
|
||||||
|
import { existsSync, rmdirSync } from 'fs';
|
||||||
|
import { copy } from 'fs-extra';
|
||||||
|
import { join as joinPath, resolve as resolvePath } from 'path';
|
||||||
|
import { xml2js } from 'xml-js';
|
||||||
|
|
||||||
import { cpuCount, downloadFile, exit, fixArgArr, isNumeric, readLastLines, resetWorkingDir, runCmd } from './utils';
|
import {
|
||||||
|
cpuCount,
|
||||||
|
downloadFile,
|
||||||
|
exit,
|
||||||
|
fixArgArr,
|
||||||
|
isNumeric,
|
||||||
|
readLastLines,
|
||||||
|
resetWorkingDir,
|
||||||
|
runCmd,
|
||||||
|
userHomeDir
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[] } } = {
|
const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[] } } = {
|
||||||
spraxdev: {
|
spraxdev: {
|
||||||
|
@ -19,7 +30,7 @@ const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[]
|
||||||
|
|
||||||
/* GitHub Actions inputs */
|
/* GitHub Actions inputs */
|
||||||
const buildToolProvider: string = (core.getInput('buildToolProvider') || 'SpraxDev').toLowerCase();
|
const buildToolProvider: string = (core.getInput('buildToolProvider') || 'SpraxDev').toLowerCase();
|
||||||
const versions: string[] = fixArgArr((core.getInput('versions') || 'latest').split(','));
|
let versions: string[] = fixArgArr((core.getInput('versions') || 'latest').toLowerCase().split(','));
|
||||||
const target: string[] = fixArgArr((core.getInput('target') || 'Spigot').toUpperCase().split(','));
|
const target: string[] = fixArgArr((core.getInput('target') || 'Spigot').toUpperCase().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';
|
||||||
|
@ -40,6 +51,14 @@ async function run(): Promise<{ code: number, msg?: string }> {
|
||||||
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(', ')})`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!forceRun) {
|
||||||
|
versions = await removeExistingVersions(versions, (ver, jarPath) => {
|
||||||
|
console.log(`Skipping version '${ver}' because it has been found in the local maven repository: ${jarPath}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (versions.length == 0) return exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const buildTool = supportedBuildTools[buildToolProvider];
|
const buildTool = supportedBuildTools[buildToolProvider];
|
||||||
const appLogFile = joinPath(workingDir.logs, 'SpraxDev_Actions-SpigotMC.log');
|
const appLogFile = joinPath(workingDir.logs, 'SpraxDev_Actions-SpigotMC.log');
|
||||||
|
|
||||||
|
@ -55,21 +74,21 @@ async function run(): Promise<{ code: number, msg?: string }> {
|
||||||
if (gotTemplateDirectory) {
|
if (gotTemplateDirectory) {
|
||||||
console.log('Prepare for future tasks by running BuildTools...');
|
console.log('Prepare for future tasks by running BuildTools...');
|
||||||
|
|
||||||
try {
|
|
||||||
await core.group('Prepare BuildTools', async (): Promise<void> => {
|
await core.group('Prepare BuildTools', async (): Promise<void> => {
|
||||||
|
try {
|
||||||
return runCmd('java', ['-jar', 'BuildTools.jar', (disableJavaCheck ? '--disable-java-check' : ''), ...buildTool.prepareArgs],
|
return runCmd('java', ['-jar', 'BuildTools.jar', (disableJavaCheck ? '--disable-java-check' : ''), ...buildTool.prepareArgs],
|
||||||
workingDir.cache, appLogFile);
|
workingDir.cache, appLogFile);
|
||||||
});
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
console.error(`\nPrinting last 25 lines from '${resolvePath(appLogFile)}':`);
|
console.error(`\nPrinting last 30 lines from '${resolvePath(appLogFile)}':`);
|
||||||
for (const line of readLastLines(appLogFile, 25)) {
|
for (const line of readLastLines(appLogFile, 30)) {
|
||||||
console.error(line);
|
console.error(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return exit(1);
|
return exit(1);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildToolsArgs = ['-jar', 'BuildTools.jar', '--compile', target.join(',')];
|
const buildToolsArgs = ['-jar', 'BuildTools.jar', '--compile', target.join(',')];
|
||||||
|
@ -142,6 +161,52 @@ async function run(): Promise<{ code: number, msg?: string }> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function removeExistingVersions(versionArr: string[], onExist: (ver: string, jarPath: string) => void): Promise<string[]> {
|
||||||
|
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;
|
||||||
|
|
||||||
|
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 (verPomBuff instanceof Buffer) {
|
||||||
|
const result = xml2js(verPomBuff.toString('utf-8'), {
|
||||||
|
compact: true,
|
||||||
|
ignoreComment: true,
|
||||||
|
ignoreAttributes: true
|
||||||
|
}) as any;
|
||||||
|
|
||||||
|
versionToCheck = result.project?.version?._text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
30
src/utils.ts
30
src/utils.ts
|
@ -1,15 +1,16 @@
|
||||||
import { spawn as spawnProcess } from 'child_process';
|
import { spawn as spawnProcess } from 'child_process';
|
||||||
import { join as joinPath } from 'path';
|
import { createWriteStream, mkdirSync, readFileSync, rmdirSync, WriteStream } from 'fs';
|
||||||
import { get as httpGet } from 'http';
|
import { get as httpGet } from 'http';
|
||||||
import { get as httpsGet } from 'https';
|
import { get as httpsGet } from 'https';
|
||||||
import { cpus, tmpdir } from 'os';
|
|
||||||
import { createWriteStream, mkdirSync, readFileSync, rmdirSync, WriteStream } from 'fs';
|
|
||||||
import readLines from 'n-readlines';
|
import readLines from 'n-readlines';
|
||||||
|
import { cpus, homedir, tmpdir } from 'os';
|
||||||
|
import { join as joinPath } from 'path';
|
||||||
|
|
||||||
const packageJson = JSON.parse(readFileSync(joinPath(__dirname, '..', 'package.json'), 'utf-8'));
|
const packageJson = JSON.parse(readFileSync(joinPath(__dirname, '..', 'package.json'), 'utf-8'));
|
||||||
const userAgent = `${packageJson.name || 'Action-SpigotMC'}/${packageJson.version || 'UNKNOWN_VERSION'} (+${packageJson.homepage || 'https://github.com/SpraxDev/'})`;
|
const userAgent = `${packageJson.name || 'Action-SpigotMC'}/${packageJson.version || 'UNKNOWN_VERSION'} (+${packageJson.homepage || 'https://github.com/SpraxDev/Action-SpigotMC'})`;
|
||||||
|
|
||||||
export const cpuCount = cpus().length;
|
export const cpuCount = cpus().length;
|
||||||
|
export const userHomeDir = homedir();
|
||||||
|
|
||||||
export function fixArgArr(arr: string[]): string[] {
|
export function fixArgArr(arr: string[]): string[] {
|
||||||
const result: string[] = [];
|
const result: string[] = [];
|
||||||
|
@ -61,7 +62,12 @@ export async function runCmd(cmd: string, args: string[], workingDir: string, lo
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadFile(url: string, dest: string, currRedirectDepth: number = 0): Promise<void> {
|
/**
|
||||||
|
* @param url The URL to fetch the data from
|
||||||
|
* @param dest Set to `null` to get an Buffer instead of writing it to the file system
|
||||||
|
* @param currRedirectDepth Internally used to track how often the function has been redirected
|
||||||
|
*/
|
||||||
|
export async function downloadFile(url: string, dest: string | null, currRedirectDepth: number = 0): Promise<Buffer | void> {
|
||||||
const doGetRequest = url.toLowerCase().startsWith('http://') ? httpGet : httpsGet;
|
const doGetRequest = url.toLowerCase().startsWith('http://') ? httpGet : httpsGet;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -72,7 +78,7 @@ export async function downloadFile(url: string, dest: string, currRedirectDepth:
|
||||||
writeStream.close();
|
writeStream.close();
|
||||||
writeStream = null;
|
writeStream = null;
|
||||||
|
|
||||||
if (errored) {
|
if (errored && dest != null) {
|
||||||
rmdirSync(dest, {recursive: true});
|
rmdirSync(dest, {recursive: true});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +112,7 @@ export async function downloadFile(url: string, dest: string, currRedirectDepth:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dest != null) {
|
||||||
writeStream = createWriteStream(dest, {encoding: 'binary'})
|
writeStream = createWriteStream(dest, {encoding: 'binary'})
|
||||||
.on('finish', () => {
|
.on('finish', () => {
|
||||||
done(false);
|
done(false);
|
||||||
|
@ -119,6 +126,17 @@ export async function downloadFile(url: string, dest: string, currRedirectDepth:
|
||||||
});
|
});
|
||||||
|
|
||||||
httpRes.pipe(writeStream);
|
httpRes.pipe(writeStream);
|
||||||
|
} else {
|
||||||
|
const chunks: Buffer[] = [];
|
||||||
|
|
||||||
|
httpRes.on('data', (chunk) => {
|
||||||
|
chunks.push(Buffer.from(chunk, 'binary'));
|
||||||
|
});
|
||||||
|
|
||||||
|
httpRes.on('end', () => {
|
||||||
|
resolve(Buffer.concat(chunks));
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.on('error', (err) => {
|
.on('error', (err) => {
|
||||||
done(true);
|
done(true);
|
||||||
|
|
Loading…
Reference in New Issue