Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Added support for gradle projects #85

Open
wants to merge 106 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
c58d4ae
An attempt on supporting gradle based
RobotHanzo Mar 21, 2021
045895b
Debugging
RobotHanzo Mar 21, 2021
9854808
Debugging
RobotHanzo Mar 21, 2021
d88a845
Debugging
RobotHanzo Mar 21, 2021
869da1e
Debugging
RobotHanzo Mar 21, 2021
1561d20
Switched order for Debugging
RobotHanzo Mar 21, 2021
0601f52
Fixes
RobotHanzo Mar 21, 2021
52e3bdf
Change debugging repo
RobotHanzo Mar 21, 2021
d7bcd66
Changed to repo
RobotHanzo Mar 21, 2021
d3e5c99
Successfully compiled: RobotHanzo/BusyBiscuitBuilderTestRepo:master (1)
Mar 21, 2021
d187827
Make `job` writable
RobotHanzo Mar 21, 2021
fe3861a
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
31c4320
Auto-Formatter
RobotHanzo Mar 21, 2021
acbb250
Make logging work
RobotHanzo Mar 21, 2021
0d35bdb
Require build tool to be specified
RobotHanzo Mar 21, 2021
a5c06f3
fixing
RobotHanzo Mar 21, 2021
39356d8
Fix attempt
RobotHanzo Mar 21, 2021
f8d6acd
debug logs
RobotHanzo Mar 21, 2021
4b9cb97
You gotta resolve()
RobotHanzo Mar 21, 2021
945de76
Failed to compile: RobotHanzo/BusyBiscuitBuilderTestRepo:gradle (1)
Mar 21, 2021
24d06b6
Escape chars
RobotHanzo Mar 21, 2021
4cfb223
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
28a0d44
Auto-Formatter
RobotHanzo Mar 21, 2021
c870374
Force recompile
RobotHanzo Mar 21, 2021
3283314
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
ba488dd
Failed to compile: RobotHanzo/BusyBiscuitBuilderTestRepo:gradle (1)
Mar 21, 2021
a903277
JS outdated
RobotHanzo Mar 21, 2021
8636e87
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
0d593d5
Force recompiling
RobotHanzo Mar 21, 2021
556b742
Failed to compile: RobotHanzo/BusyBiscuitBuilderTestRepo:gradle (1)
Mar 21, 2021
4c0f87d
ABS path
RobotHanzo Mar 21, 2021
f9dad25
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
2dd9ca9
Force recomp.
RobotHanzo Mar 21, 2021
053b96d
Failed to compile: RobotHanzo/BusyBiscuitBuilderTestRepo:gradle (1)
Mar 21, 2021
35cfd93
attempt
RobotHanzo Mar 21, 2021
ee3d2ec
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
3dd23c9
force rec.
RobotHanzo Mar 21, 2021
c4e29a7
Failed to compile: RobotHanzo/BusyBiscuitBuilderTestRepo:gradle (1)
Mar 21, 2021
a938d97
grant perms
RobotHanzo Mar 21, 2021
98e92c2
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
27c83c0
f. rec
RobotHanzo Mar 21, 2021
d0fc4c8
Auto-Formatter
RobotHanzo Mar 21, 2021
3e8f3da
Check
RobotHanzo Mar 21, 2021
2a34f12
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
136a07d
Auto-Formatter
RobotHanzo Mar 21, 2021
b9c62ae
fix
RobotHanzo Mar 21, 2021
820502a
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
335814a
use gradle.properties
RobotHanzo Mar 21, 2021
4e64eb4
Auto-Formatter
RobotHanzo Mar 21, 2021
55e3293
Fix renaming
RobotHanzo Mar 21, 2021
2df8094
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
ad5afac
Auto-Formatter
RobotHanzo Mar 21, 2021
c11b9ed
Successfully compiled: RobotHanzo/BusyBiscuitBuilderTestRepo:gradle (1)
Mar 21, 2021
8611df9
Restored debugging leftovers
RobotHanzo Mar 21, 2021
1cd2a54
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
1bdf1e2
More leftovers
RobotHanzo Mar 21, 2021
5092e3f
Make the tests compatible
RobotHanzo Mar 21, 2021
2cdd81b
Fixes
RobotHanzo Mar 21, 2021
f8239dc
Separate files
RobotHanzo Mar 21, 2021
704bb80
Typo
RobotHanzo Mar 21, 2021
84d7482
Use jitpack
RobotHanzo Mar 21, 2021
1e7e75a
Creates file if not exists
RobotHanzo Mar 21, 2021
68afe93
Auto-Formatter
RobotHanzo Mar 21, 2021
0a4467f
Give us the logs
RobotHanzo Mar 21, 2021
55bf84c
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo Mar 21, 2021
3253cce
Fix attempt
RobotHanzo Mar 21, 2021
4b1998e
Fix paths
RobotHanzo Mar 21, 2021
fc4ec20
Add prefix
RobotHanzo Mar 21, 2021
c154fe6
settings.gradle generator
RobotHanzo Mar 21, 2021
a6bbb9f
settings.gradle generator
RobotHanzo Mar 21, 2021
92d280b
Another way
RobotHanzo Mar 21, 2021
8d0bb2a
Another way
RobotHanzo Mar 21, 2021
9fdc6b7
Typo sucks
RobotHanzo Mar 21, 2021
213801d
Attempt on copying TestMaven.js for test
RobotHanzo Mar 21, 2021
5b1a102
import the stuff
RobotHanzo Mar 21, 2021
c5208ce
Ensure folder exists
RobotHanzo Mar 21, 2021
080fc26
New lines fixed
RobotHanzo Mar 21, 2021
e584720
New lines fixed
RobotHanzo Mar 21, 2021
3f253b2
No async
RobotHanzo Mar 21, 2021
b53f29d
use variable in string
RobotHanzo May 11, 2021
6faf99f
use +x instead of a+x
RobotHanzo May 11, 2021
d74a4f5
variable in string
RobotHanzo May 11, 2021
8427051
default to maven if not specified
RobotHanzo May 11, 2021
f3886da
variable in string
RobotHanzo May 11, 2021
3d452ef
remove the use of having to escape characters
RobotHanzo May 11, 2021
4cba9bf
variable in string
RobotHanzo May 11, 2021
68d33ff
variable in string
RobotHanzo May 11, 2021
e65e172
optimize code
RobotHanzo May 11, 2021
a77f91c
variable in string
RobotHanzo May 11, 2021
05d5491
dont need extra comparision
RobotHanzo May 11, 2021
655845d
variable in string
RobotHanzo May 11, 2021
f840689
default to maven if not specified
RobotHanzo May 11, 2021
2dddef1
dont need extra comparision
RobotHanzo May 11, 2021
60447da
default to maven if not specified
RobotHanzo May 11, 2021
8ca676f
Auto-Formatter
RobotHanzo May 11, 2021
65f7791
default to maven
RobotHanzo May 11, 2021
45ae4c2
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo May 11, 2021
cc1d1e4
fixes
RobotHanzo May 11, 2021
3ef9b3e
optimized if
RobotHanzo May 11, 2021
9fff35f
Auto-Formatter
RobotHanzo May 11, 2021
e7802b5
node version issues
RobotHanzo May 11, 2021
43885c9
Merge remote-tracking branch 'origin/gh-pages' into gh-pages
RobotHanzo May 11, 2021
7577454
actual fix
RobotHanzo May 11, 2021
b54a187
node 12 doesnt support many things
RobotHanzo May 11, 2021
86c9a6d
use the old way to ensure everything works
RobotHanzo May 11, 2021
9676202
Merge branch 'TheBusyBiscuit:gh-pages' into gh-pages
RobotHanzo May 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Maven Builds Server
# Maven and Gradle Builds Server
This is the repository of the backend for my builds-page.
The page can be found here: https://thebusybiscuit.github.io/builds/

This kinda serves as a "Continous Integration/Deployment" Service for Maven Projects which utilises static GitHub Pages.
This kinda serves as a "Continous Integration/Deployment" Service for Maven and Gradle Projects which utilises static GitHub Pages.

# Status
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=TheBusyBiscuit_builds&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=TheBusyBiscuit_builds)
Expand All @@ -26,10 +26,11 @@ After that it will proceed to step 2.<br>

### 2. Cloning
After we established that our repository is out of date, this program will ```git clone``` said repository.<br>
It will also locate it's pom.xml file and set the version to "DEV - $id (git $commit)".<br>
It will also locate it's `pom.xml` or `gradle.properties` file and set the version to "DEV - $id (git $commit)".<br>

### 3. Compiling
This is the easiest step, the program just runs ```mvn clean package -B``` to compile our Maven Project.<br>
If a Gradle project is detected, the program runs ```gradlew build``` to compile our Gradle Project.<br>
It will also catch the state (Success / Failure).<br>
If you enabled Sonar-Integration for this project, then it will also run a sonar-scan on the repository.<br>

Expand Down Expand Up @@ -62,7 +63,7 @@ Note that many of these guidelines are requirements of technical nature.

1. They must be publicly available on GitHub and Open-Source.
2. They must have a valid `LICENSE` file with a permissive Open-Source license (e.g. MIT, Apache or GNU GPL or similar).
3. They must have a valid `pom.xml` file.
3. They must have a valid `pom.xml` or `gradle.properties` file.
4. They are not allowed to force auto-updates on people without providing an option to disable it.

### Example
Expand All @@ -73,10 +74,12 @@ Note that many of these guidelines are requirements of technical nature.
// Some repositories support the usage of sonar-scanner, custom repositories cannot have this feature though (yet)
"sonar": {
"enabled": false
},
// What the builds will be prefixed with. "DEV" would make builds like "CoolAddon - DEV 1 (githash)"
},
"options": {
"prefix": "DEV"
// What the builds will be prefixed with. "DEV" would make builds like "CoolAddon - DEV 1 (githash)"
"prefix": "DEV",
// What type of build tool will be used, must be "maven" or "gradle"
"buildTool": "maven"
},
// What your addon supports/depends on. The number key indicates the minium build.
// You can list any text or even links here.
Expand Down
1 change: 0 additions & 1 deletion resources/repos.json
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,6 @@
}
}
},

"John000708/SlimeXpansion:master": {
"sonar": {
"enabled": false
Expand Down
5 changes: 4 additions & 1 deletion resources/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"options": {
"type": "object",
"required": ["prefix"],
"required": ["prefix", "buildTool"],
"additionalProperties": false,

"properties": {
Expand All @@ -49,6 +49,9 @@
},
"createJar": {
"type": "boolean"
},
"buildTool": {
"type": "string"
}
}
},
Expand Down
130 changes: 130 additions & 0 deletions src/gradle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
const process = require('child-process-promise')
const lodash = require('lodash/lang')

const FileSystem = require('fs')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, can just do fs/promises

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant, theres one usage on fs.existSync

const fs = FileSystem.promises
const path = require('path')

const log = require('../src/logger.js')
const projects = require('../src/projects.js')

module.exports = {
getGradleArguments,
setVersion,
compile,
relocate,
isValid
}

/**
* This will return the console line arguments for gradle.compile()
*
* @return {Array<String>} The needed console line arguments
*/
function getGradleArguments () {
return ['build']
}

/**
* This method changes the project's version in your gradle.properties file
* It also returns a Promise that resolves when it's done.
*
* @param {Object} job The currently handled Job Object
* @param {String} version The Version that shall be set
*/
function setVersion (job, version) {
return new Promise((resolve, reject) => {
if (!isValid(job)) {
reject(new Error('Invalid Job'))
return
}
const file = path.resolve(__dirname, `../${job.directory}/files/gradle.properties`)
if (!FileSystem.existsSync(file)) {
fs.writeFile(file, '\nversion=' + version, 'utf8').then(resolve, reject)
} else {
fs.readFile(file, 'utf8').then((data) => {
const content = data.split('\n')
const result = []
let line
for (line in content) {
if (!line.includes('version=')) {
result.push(line)
}
}
result.push('\nversion=' + version)
fs.writeFile(file, result, 'utf8').then(resolve, reject)
}, reject)
}
})
}

/**
* This method will compile a project using the command
* 'gradlew build'
*
* @param {Object} job The currently handled Job Object
* @param {Boolean} logging Whether the internal activity should be logged
* @return {Promise} A promise that resolves when this activity finished
*/
function compile (job, logging) {
return new Promise((resolve, reject) => {
if (!isValid(job)) {
reject(new Error('Invalid Job'))
return
}

log(logging, '-> Granting gradlew +x permissions')

process.spawn('chmod', ['+x', 'gradlew'], {
cwd: path.resolve(__dirname, `../${job.directory}/files`),
shell: true
})

log(logging, "-> Executing './gradlew build'")

const args = getGradleArguments()
const compiler = process.spawn('./gradlew', args, {
cwd: path.resolve(__dirname, `../${job.directory}/files`),
shell: true
})

const logger = (data) => {
log(logging, data, true)
fs.appendFile(path.resolve(__dirname, `../${job.directory}/${job.repo}-${job.id}.log`), data, 'utf8').catch(err => console.log(err))
}

compiler.childProcess.stdout.on('data', logger)
compiler.childProcess.stderr.on('data', logger)

compiler.then(resolve, reject)
})
}

/**
* This method will relocate a project's compiled jar file
* to the appropriate directory
*
* @param {Object} job The currently handled Job Object
* @return {Promise} A promise that resolves when this activity finished
*/
function relocate (job) {
if (!job.success) {
return Promise.resolve()
}
return fs.rename(
path.resolve(__dirname, `../${job.directory}/files/build/libs/${job.repo}-${(job.options ? job.options.prefix : 'DEV')} - ${job.id} (git ${job.commit.sha.substr(0, 8)}).jar`),
path.resolve(__dirname, `../${job.directory}/${job.repo}-${job.id}.jar`)
)
}

/**
* This method will check if a Job is valid.
* null / undefined or incomplete Job Objects will fail.
*
* @param {Object} job The job object to be tested
* @return {Boolean} Whether the job is a valid Job
*/
function isValid (job) {
if (!projects.isValid(job)) return false
return lodash.isInteger(job.id)
}
62 changes: 43 additions & 19 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const cfg = require('../src/config.js')(path.resolve(__dirname, '../resources/co
// Modules
const projects = require('../src/projects.js')
const maven = require('../src/maven.js')
const gradle = require('../src/gradle.js')
const github = require('../src/github.js')(cfg.github)
const discord = require('../src/discord.js')(cfg.discord)
const log = require('../src/logger.js')
Expand Down Expand Up @@ -149,13 +150,18 @@ function update (job, logging) {

github.clone(job, job.commit.sha, logging).then(() => {
const name = (job.options ? job.options.prefix : 'DEV') + ' - ' + job.id + ' (git ' + job.commit.sha.substr(0, 8) + ')'
maven.setVersion(job, name, true).then(resolve, reject)
log(logging, `-> Building using: ${job.options.buildTool === null ? 'maven' : job.options.buildTool}`)
if (!job.options.buildTool || job.options.buildTool === 'maven') {
maven.setVersion(job, name, true).then(resolve, reject)
} else {
gradle.setVersion(job, name).then(resolve, reject)
}
}, reject)
})
}

/**
* This method compiles the project using Maven.
* This method compiles the project using Maven or Gradle depending on job.config.buildTool.
* After completing, the job update will have the flag 'success',
* that is either true or false.
*
Expand All @@ -175,18 +181,32 @@ function compile (job, logging) {
updateStatus(job, 'Compiling')

return new Promise((resolve) => {
log(logging, 'Compiling: ' + job.author + '/' + job.repo + ':' + job.branch + ' (' + job.id + ')')

maven.compile(job, cfg, logging)
.then(() => {
job.success = true
resolve()
})
.catch((err) => {
log(logging, err.stack)
job.success = false
resolve()
})
if (!job.options.buildTool || job.options.buildTool === 'maven') {
log(logging, `Compiling using Maven: ${job.author}/${job.repo}:${job.branch} (${job.id})`)

maven.compile(job, cfg, logging)
.then(() => {
job.success = true
resolve()
})
.catch((err) => {
log(logging, err.stack)
job.success = false
resolve()
})
} else {
log(logging, `Compiling using Gradle: ${job.author}/${job.repo}:${job.branch} (${job.id})`)
gradle.compile(job, logging)
.then(() => {
job.success = true
resolve()
})
.catch((err) => {
log(logging, err.stack)
job.success = false
resolve()
})
}
})
}

Expand All @@ -211,12 +231,16 @@ function gatherResources (job, logging) {

return new Promise((resolve, reject) => {
log(logging, 'Gathering Resources: ' + job.author + '/' + job.repo + ':' + job.branch)

Promise.all([
const promises = [
github.getLicense(job, logging),
github.getTags(job, logging),
maven.relocate(job)
]).then((values) => {
github.getTags(job, logging)
]
if (job.options.buildTool === 'maven') {
promises.push(maven.relocate(job))
} else {
promises.push(gradle.relocate(job))
}
Promise.all(promises).then((values) => {
const license = values[0]
const tags = values[1]

Expand Down
1 change: 0 additions & 1 deletion src/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function getProjects (logging) {

if (json[repo].options) {
job.options = json[repo].options

if (json[repo].options.custom_directory) {
job.directory = json[repo].options.custom_directory
}
Expand Down
2 changes: 1 addition & 1 deletion src/setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git config user.name "TheBusyBot"
git config user.email ${LOGIN_EMAIL}

git remote set-url origin https://${ACCESS_TOKEN}@github.com/TheBusyBiscuit/builds.git
git remote set-url origin https://${ACCESS_TOKEN}@github.com/TheBusyBiscuit/builds.git
Loading