Initial commit
This commit is contained in:
parent
2277d29179
commit
ecb587ae2f
|
@ -0,0 +1 @@
|
|||
dist/** -diff linguist-generated=true
|
|
@ -0,0 +1,11 @@
|
|||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
|
@ -0,0 +1,34 @@
|
|||
name: 'Build & Run'
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
# Make sure clean build works properly
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm i
|
||||
npm run build
|
||||
|
||||
# Make sure the action works on a clean machine without building
|
||||
run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
versions: latest, 1.8
|
||||
|
||||
# Run the original BuildTools in GitHub Actions to easily compare the build times etc.
|
||||
original-run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Run original Spigot-BuildTools
|
||||
run: |
|
||||
wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -O BuildTools.jar
|
||||
java -jar BuildTools.jar --rev latest --compile Spigot
|
||||
java -jar BuildTools.jar --rev 1.8 --compile Spigot
|
|
@ -0,0 +1,4 @@
|
|||
/node_modules/
|
||||
/build/
|
||||
|
||||
/.idea/
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 Christian Koop
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,37 @@
|
|||
name: Compile Minecraft Spigot (BuildTools)
|
||||
description: Makes it easier to compile multiple Spigot versions at the same time and speed up clean builds
|
||||
author: Christian Koop
|
||||
|
||||
inputs:
|
||||
versions:
|
||||
required: false
|
||||
default: latest
|
||||
description: Versions to build (sperate multiple with ',')
|
||||
target:
|
||||
required: false
|
||||
default: Spigot
|
||||
description: Select what exactly you want to compile (none, Spigot, CraftBukkit) (sperate multiple with ',')
|
||||
forceRun:
|
||||
required: false
|
||||
default: 'false'
|
||||
description: Disables the check for existing files in the local maven repository
|
||||
generateSrc:
|
||||
required: false
|
||||
default: 'false'
|
||||
description: Should sources be generated?
|
||||
generateDoc:
|
||||
required: false
|
||||
default: 'false'
|
||||
description: Should the documentation be generated?
|
||||
disableJavaCheck:
|
||||
required: false
|
||||
default: 'false'
|
||||
description: Should we disable the BuildTools's Java-Version-Check
|
||||
threads:
|
||||
required: false
|
||||
default: '-1'
|
||||
description: The amount of builds allowed to run at a time, set to '-1' to use system's cpu count
|
||||
|
||||
runs:
|
||||
using: node12
|
||||
main: dist/index.js
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "action-spigotmc",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"homepage": "https://github.com/SpraxDev/Action-SpigotMC#readme",
|
||||
"main": "dist/index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "ncc build src/index.ts -s -m",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "ncc run src/index.ts"
|
||||
},
|
||||
"author": {
|
||||
"name": "Christian Koop",
|
||||
"url": "https://Sprax2013.de",
|
||||
"email": "developer@sprax2013.de"
|
||||
},
|
||||
"contributors": [],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/SpraxDev/Action-SpigotMC.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/SpraxDev/Action-SpigotMC/issues"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"async": "^3.2.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"read-last-lines": "^1.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node12": "^1.0.7",
|
||||
"@types/async": "^3.2.3",
|
||||
"@types/fs-extra": "^9.0.2",
|
||||
"@types/node": "~12.19.2",
|
||||
"@vercel/ncc": "^0.24.1",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.5"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,202 @@
|
|||
{
|
||||
"name": "action-spigotmc",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@actions/core": {
|
||||
"version": "1.2.6",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
||||
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
|
||||
},
|
||||
"@tsconfig/node12": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.7.tgz",
|
||||
"integrity": "sha512-dgasobK/Y0wVMswcipr3k0HpevxFJLijN03A8mYfEPvWvOs14v0ZlYTR4kIgMx8g4+fTyTFv8/jLCIfRqLDJ4A==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/async": {
|
||||
"version": "3.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/async/-/async-3.2.3.tgz",
|
||||
"integrity": "sha512-deXFjLZc1h6SOh3hicVgD+S2EAkhSBGX/vdlD4nTzCjjOFQ+bfNiXocQ21xJjFAUwqaCeyvOQMgrnbg4QEV63A==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/fs-extra": {
|
||||
"version": "9.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.2.tgz",
|
||||
"integrity": "sha512-jp0RI6xfZpi5JL8v7WQwpBEQTq63RqW2kxwTZt+m27LcJqQdPVU1yGnT1ZI4EtCDynQQJtIGyQahkiCGCS7e+A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.19.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.3.tgz",
|
||||
"integrity": "sha512-8Jduo8wvvwDzEVJCOvS/G6sgilOLvvhn1eMmK3TW8/T217O7u1jdrK6ImKLv80tVryaPSVeKu6sjDEiFjd4/eg==",
|
||||
"dev": true
|
||||
},
|
||||
"@vercel/ncc": {
|
||||
"version": "0.24.1",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.24.1.tgz",
|
||||
"integrity": "sha512-r9m7brz2hNmq5TF3sxrK4qR/FhXn44XIMglQUir4sT7Sh5GOaYXlMYikHFwJStf8rmQGTlvOoBXt4yHVonRG8A==",
|
||||
"dev": true
|
||||
},
|
||||
"any-promise": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
|
||||
"integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8="
|
||||
},
|
||||
"arg": {
|
||||
"version": "4.1.3",
|
||||
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
|
||||
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
|
||||
"dev": true
|
||||
},
|
||||
"async": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
|
||||
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw=="
|
||||
},
|
||||
"at-least-node": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz",
|
||||
"integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg=="
|
||||
},
|
||||
"buffer-from": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||
"dev": true
|
||||
},
|
||||
"diff": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||
"dev": true
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz",
|
||||
"integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==",
|
||||
"requires": {
|
||||
"at-least-node": "^1.0.0",
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.2.4",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
|
||||
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6",
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"make-error": {
|
||||
"version": "1.3.6",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
||||
"dev": true
|
||||
},
|
||||
"mz": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
|
||||
"integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==",
|
||||
"requires": {
|
||||
"any-promise": "^1.0.0",
|
||||
"object-assign": "^4.0.1",
|
||||
"thenify-all": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
|
||||
},
|
||||
"read-last-lines": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/read-last-lines/-/read-last-lines-1.7.2.tgz",
|
||||
"integrity": "sha512-K0yUvTYAYn6qpyLJufaJ7yC6BeL23qpgZ8SKM7/fA1R1rHotCDxB/zDp9i1I2JHvexWBW6/35jkt07iiIKKp4g==",
|
||||
"requires": {
|
||||
"mz": "^2.7.0"
|
||||
}
|
||||
},
|
||||
"source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
|
||||
"dev": true
|
||||
},
|
||||
"source-map-support": {
|
||||
"version": "0.5.19",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz",
|
||||
"integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"buffer-from": "^1.0.0",
|
||||
"source-map": "^0.6.0"
|
||||
}
|
||||
},
|
||||
"thenify": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
|
||||
"integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==",
|
||||
"requires": {
|
||||
"any-promise": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"thenify-all": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz",
|
||||
"integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=",
|
||||
"requires": {
|
||||
"thenify": ">= 3.1.0 < 4"
|
||||
}
|
||||
},
|
||||
"ts-node": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.0.0.tgz",
|
||||
"integrity": "sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"arg": "^4.1.0",
|
||||
"diff": "^4.0.1",
|
||||
"make-error": "^1.1.1",
|
||||
"source-map-support": "^0.5.17",
|
||||
"yn": "3.1.1"
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "4.0.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.5.tgz",
|
||||
"integrity": "sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==",
|
||||
"dev": true
|
||||
},
|
||||
"universalify": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz",
|
||||
"integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug=="
|
||||
},
|
||||
"yn": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
||||
"integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "action-spigotmc",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"homepage": "https://github.com/SpraxDev/Action-SpigotMC#readme",
|
||||
"main": "dist/index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "ncc build src/index.ts -s -m",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "ncc run src/index.ts"
|
||||
},
|
||||
"author": {
|
||||
"name": "Christian Koop",
|
||||
"url": "https://Sprax2013.de",
|
||||
"email": "developer@sprax2013.de"
|
||||
},
|
||||
"contributors": [],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/SpraxDev/Action-SpigotMC.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/SpraxDev/Action-SpigotMC/issues"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"async": "^3.2.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"read-last-lines": "^1.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node12": "^1.0.7",
|
||||
"@types/async": "^3.2.3",
|
||||
"@types/fs-extra": "^9.0.2",
|
||||
"@types/node": "~12.19.2",
|
||||
"@vercel/ncc": "^0.24.1",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.5"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
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 { cpuCount, downloadFile, exit, fixArgArr, isNumeric, resetWorkingDir, runCmd } from './utils';
|
||||
import { parallelLimit } from 'async';
|
||||
|
||||
|
||||
const rll = require('read-last-lines');
|
||||
|
||||
/* GitHub Actions inputs */
|
||||
const versions: string[] = fixArgArr((core.getInput('versions') || 'latest').split(','));
|
||||
const target: string[] = fixArgArr((core.getInput('target') || 'Spigot').toUpperCase().split(','));
|
||||
const generateSrc: boolean = core.getInput('generateSrc') == 'true';
|
||||
const generateDoc: boolean = core.getInput('generateDoc') == 'true';
|
||||
const disableJavaCheck: boolean = core.getInput('disableJavaCheck') == 'true';
|
||||
|
||||
const forceRun: boolean = core.getInput('forceRun') == 'true'; // TODO
|
||||
const threadCount: number = isNumeric(core.getInput('threads')) ? parseInt(core.getInput('threads')) : cpuCount;
|
||||
|
||||
const workingDir = resetWorkingDir();
|
||||
|
||||
async function run(): Promise<{ code: number, msg?: string }> {
|
||||
return new Promise<{ code: number, msg?: string }>(async (resolve, reject): Promise<void> => {
|
||||
if (versions.length == 0) return resolve({code: 0, msg: 'No version(s) provided to build'});
|
||||
if (target.length == 0) return resolve({code: 0, msg: 'No target(s) provided to build'});
|
||||
|
||||
const appLogFile = joinPath(workingDir.logs, 'SpraxDev_Actions-SpigotMC.log');
|
||||
|
||||
console.log('Installed Java-Version:');
|
||||
await runCmd('java', ['-version'], workingDir.base, appLogFile);
|
||||
|
||||
console.log(`Downloading BuildTools.jar from 'hub.spigotmc.org'...`);
|
||||
await downloadFile('https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar', joinPath(workingDir.cache, 'BuildTools.jar'));
|
||||
|
||||
const gotTemplateDirectory = versions.length != 1;
|
||||
|
||||
// Prepare template directory if more than one version is provided
|
||||
if (gotTemplateDirectory) {
|
||||
console.log('Prepare for future tasks by running BuildTools...');
|
||||
|
||||
try {
|
||||
await core.group('Prepare BuildTools', async (): Promise<void> => {
|
||||
return runCmd('java', ['-jar', 'BuildTools.jar', '--compile', 'NONE'],
|
||||
workingDir.cache, appLogFile);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
console.error(`\nPrinting last 25 lines from '${resolvePath(appLogFile)}':`);
|
||||
for (const line of (await rll.read(appLogFile, 25))) {
|
||||
console.error(line);
|
||||
}
|
||||
|
||||
return exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const buildToolsArgs = ['-jar', 'BuildTools.jar', '--compile', target.join(',')];
|
||||
|
||||
if (generateSrc) {
|
||||
buildToolsArgs.push('--generate-source');
|
||||
}
|
||||
|
||||
if (generateDoc) {
|
||||
buildToolsArgs.push('--generate-docs');
|
||||
}
|
||||
|
||||
if (disableJavaCheck) {
|
||||
buildToolsArgs.push('--disable-java-check');
|
||||
}
|
||||
|
||||
const tasks = [];
|
||||
for (const ver of versions) {
|
||||
tasks.push((callback: (err?: Error, result?: unknown) => void) => {
|
||||
try {
|
||||
const start = Date.now();
|
||||
|
||||
const logFile = joinPath(workingDir.logs, `${ver}.log`);
|
||||
|
||||
console.log(`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) {
|
||||
copy(workingDir.cache, versionDir)
|
||||
.then(() => {
|
||||
runCmd('java', [...buildToolsArgs, '--rev', ver],
|
||||
versionDir, logFile, true) // set to silent because multiple builds can run at once
|
||||
.then(() => {
|
||||
rmdirSync(versionDir, {recursive: true}); // delete our task dir
|
||||
|
||||
const end = Date.now();
|
||||
|
||||
console.log(`Finished building '${ver}' in ${((end - start) / 60_000)} minutes`);
|
||||
callback();
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(`An error occurred while building '${ver}'`);
|
||||
console.error(err);
|
||||
|
||||
console.error(`\nPrinting last 25 lines from '${resolvePath(logFile)}':`);
|
||||
rll.read(logFile, 25)
|
||||
.then((lines: string[]) => {
|
||||
for (const line of lines) {
|
||||
console.error(line);
|
||||
}
|
||||
})
|
||||
.catch(console.error)
|
||||
.finally(() => callback(err));
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
(parallelLimit(tasks, threadCount) as unknown as Promise<unknown[]>) // Valid according to docs - types outdated?
|
||||
.then(() => resolve({code: 0}))
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
run()
|
||||
.then((result) => exit(result.code, result.msg))
|
||||
.catch((err) => exit(1, err));
|
|
@ -0,0 +1,138 @@
|
|||
import { spawn as spawnProcess } from 'child_process';
|
||||
import { join as joinPath } from 'path';
|
||||
import { get as httpGet } from 'http';
|
||||
import { get as httpsGet } from 'https';
|
||||
import { cpus, tmpdir } from 'os';
|
||||
import { createWriteStream, mkdirSync, readFileSync, rmdirSync, WriteStream } from 'fs';
|
||||
|
||||
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/'})`;
|
||||
|
||||
export const cpuCount = cpus().length;
|
||||
|
||||
export function fixArgArr(arr: string[]): string[] {
|
||||
const result: string[] = [];
|
||||
|
||||
for (const element of arr) {
|
||||
const newValue = element.trim();
|
||||
|
||||
if (newValue && !result.includes(newValue)) {
|
||||
result.push(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function isNumeric(str: string): boolean {
|
||||
return /^[0-9]+$/.test(str);
|
||||
}
|
||||
|
||||
export async function runCmd(cmd: string, args: string[], workingDir: string, logFile: string, silent: boolean = false): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const logStream = createWriteStream(logFile, {encoding: 'utf-8', flags: 'a'}); // Use UTF-8 and append when file exists
|
||||
const runningProcess = spawnProcess(cmd, args, {shell: true, cwd: workingDir, env: process.env});
|
||||
|
||||
runningProcess.stdout.on('data', (data) => {
|
||||
logStream.write(data);
|
||||
|
||||
if (!silent) {
|
||||
process.stdout.write(data); // Not using console.log to prevent '\n\n'
|
||||
}
|
||||
});
|
||||
runningProcess.stderr.on('data', (data) => {
|
||||
logStream.write(data);
|
||||
|
||||
if (!silent) {
|
||||
process.stderr.write(data); // Not using console.error to prevent '\n\n'
|
||||
}
|
||||
});
|
||||
|
||||
runningProcess.on('close', (code) => {
|
||||
logStream.close();
|
||||
|
||||
if (code != 0) {
|
||||
return reject({err: new Error(`process exited with code ${code}`), cmd, workingDir});
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function downloadFile(url: string, dest: string): Promise<void> {
|
||||
const getURL = url.toLowerCase().startsWith('http://') ? httpGet : httpsGet;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let writeStream: WriteStream | null = null;
|
||||
|
||||
const done = function (err: boolean) {
|
||||
if (writeStream) {
|
||||
writeStream.close();
|
||||
writeStream = null;
|
||||
|
||||
if (err) {
|
||||
rmdirSync(dest, {recursive: true});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// TODO
|
||||
getURL(url, {
|
||||
headers: {
|
||||
'User-Agent': userAgent
|
||||
}
|
||||
}, (httpRes) => {
|
||||
if (httpRes.statusCode != 200) {
|
||||
done(true);
|
||||
|
||||
return reject(new Error(`Server responded with ${httpRes.statusCode}`));
|
||||
}
|
||||
|
||||
writeStream = createWriteStream(dest, {encoding: 'binary'})
|
||||
.on('finish', () => {
|
||||
done(false);
|
||||
|
||||
return resolve();
|
||||
})
|
||||
.on('error', (err) => {
|
||||
done(true);
|
||||
|
||||
return reject(err);
|
||||
});
|
||||
|
||||
httpRes.pipe(writeStream);
|
||||
})
|
||||
.on('error', (err) => {
|
||||
done(true);
|
||||
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function resetWorkingDir(): { base: string, cache: string, logs: string } {
|
||||
const baseDir = joinPath(tmpdir(), 'SpraxDev-Action-SpigotMC');
|
||||
const cacheDir = joinPath(baseDir, 'cache');
|
||||
const logDir = joinPath(baseDir, 'logs');
|
||||
|
||||
rmdirSync(baseDir, {recursive: true}); // delete dir
|
||||
|
||||
// create directories
|
||||
mkdirSync(cacheDir, {recursive: true});
|
||||
mkdirSync(logDir);
|
||||
|
||||
return {base: baseDir, cache: cacheDir, logs: logDir};
|
||||
}
|
||||
|
||||
export function exit(code: number, msg?: string | Error): never {
|
||||
if (msg) {
|
||||
if (typeof msg == 'string') {
|
||||
console.log(msg);
|
||||
} else {
|
||||
console.error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
return process.exit(code);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"extends": "@tsconfig/node12/tsconfig.json",
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue