Skip to content

Commit

Permalink
Add CI+CD and update gradle build process
Browse files Browse the repository at this point in the history
  • Loading branch information
fr1kin committed Feb 15, 2022
1 parent d288657 commit ca70af7
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 54 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Caches Gradle dependencies and wrappers
uses: actions/cache@v2
with:
path: |
~/.gradle/caches/modules-2
~/.gradle/wrapper/dists
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/libs.versions.toml', '**/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Run cibuild script
id: exec
run: ./scripts/cibuild

- name: Cleanup Gradle Cache
run: |
sudo rm -f ~/.gradle/caches/modules-2/modules-2.lock
sudo rm -f ~/.gradle/caches/modules-2/gc.properties
- name: Create release if this is a tagged workflow
uses: ncipollo/release-action@v1
if: startsWith(github.ref, 'refs/tags/')
with:
artifacts: build/libs/${{ steps.exec.outputs.slimjar }},build/libs/${{ steps.exec.outputs.libszip }},build/libs/${{ steps.exec.outputs.fatjar }}
name: NiSCore ${{ steps.exec.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
.idea/
.gradle/
jars/
build/
*/build/
mcserver/

EnhancedChat/*.sqlite
73 changes: 46 additions & 27 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
plugins {
id 'java'
id 'nu.studer.jooq' version '5.2.1'
id 'com.palantir.git-version' version '0.12.3'
alias libs.plugins.jooqgradle
alias libs.plugins.gitgradle
}

final git = versionDetails()

group 'space.nerdsin.plugins'
version gitVersion()
version "${git.lastTag.substring(1)}.r${git.commitDistance}"
archivesBaseName = "$pluginName"

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_16
final isCiBuilding = System.getenv().get('CI') == 'true'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

configurations {
compileJar {}
Expand All @@ -18,7 +26,7 @@ configurations {
}

jooq {
version = jooqVersion
version = libs.versions.jooq

configurations {
main {
Expand Down Expand Up @@ -62,29 +70,21 @@ jooq {
}
}

repositories {
mavenCentral()
maven { url = 'https://papermc.io/repo/repository/maven-public/' }
}

dependencies {
implementation group: 'com.destroystokyo.paper', name: 'paper-api', version: paperApiVersion
implementation libs.paperapi

compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
compileOnly libs.lombok
annotationProcessor libs.lombok

compileJar group: 'com.h2database', name: 'h2', version: h2DatabaseVersion
jooqGenerator group: 'com.h2database', name: 'h2', version: h2DatabaseVersion
compileJar libs.h2

compileJar group: 'org.jooq', name: 'jooq'
jooqGenerator group: 'org.jooq', name: 'jooq-meta'
jooqGenerator group: 'org.jooq', name: 'jooq-meta-extensions'
jooqGenerator group: 'org.jooq', name: 'jooq-codegen'
compileJar libs.jooq
jooqGenerator libs.bundles.jooqgen

compileJar group: 'org.flywaydb', name: 'flyway-core', version: flywayCoreVersion
compileJar libs.flyway

compileJar group: 'com.google.inject', name: 'guice', version: guiceVersion
compileJar group: 'org.reflections', name: 'reflections', version: reflectionsVersion
compileJar libs.guice
compileJar libs.reflections
}

jar {
Expand All @@ -95,9 +95,16 @@ jar {
attributes("Class-Path": configurations.compileJar.collect { "libs/${it.getName()}" }.join(' '))
}

finalizedBy task("copyLibs", type: Copy) {
// finalizedBy task("copyLibs", type: Copy) {
// from configurations.compileJar
// into tasks.jar.destinationDirectory.dir("libs")
// }

finalizedBy task("zipLibs", type: Zip) {
archiveBaseName = "$archivesBaseName-libs"
destinationDirectory = tasks.jar.destinationDirectory

from configurations.compileJar
into tasks.jar.destinationDirectory.dir("libs")
}
}

Expand All @@ -122,9 +129,7 @@ processResources {
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
'name' : archivesBaseName,
'class' : pluginClass,
'version' : (project.version =~ /v([\d]+\.[\d]+\.[\d]+).*/)
.with { it[0] }
.with { m, ver -> ver },
'version' : git.lastTag.substring(1),
'apiversion': pluginApiVersion
]);
}
Expand All @@ -136,3 +141,17 @@ processResources {
]);
}
}

task createGitHubActionsVars() {
onlyIf { isCiBuilding }
doFirst {
println "::set-output name=slimjar::${jar.archiveFileName.get()}"
println "::set-output name=libszip::${tasks.zipLibs.archiveFileName.get()}"
println "::set-output name=fatjar::${fatJar.archiveFileName.get()}"
println "::set-output name=version::${project.version}"
}
}

build {
finalizedBy createGitHubActionsVars
}
15 changes: 15 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '2.4'

services:
gradle:
image: eclipse-temurin:17.0.2_8-jdk-focal
environment:
- CI=${CI:-}
volumes:
# gradle caches
- ~/.gradle/caches/modules-2:/root/.gradle/caches/modules-2:z
- ~/.gradle/wrapper/dists:/root/.gradle/wrapper/dists:z
# mount working directory
- ./:/opt/build:Z
working_dir: /opt/build
command: bash -c 'set -x && ./gradlew --no-daemon clean build --stacktrace'
11 changes: 0 additions & 11 deletions docker-compose.yml

This file was deleted.

10 changes: 0 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
# libraries
paperApiVersion=1.16.5-R0.1-SNAPSHOT
jooqVersion=3.14.11
h2DatabaseVersion=1.4.200
flywayCoreVersion=7.10.0
lombokVersion=1.18.20
guiceVersion=5.0.1
reflectionsVersion=0.9.12

# plugin
pluginApiVersion=1.13
pluginClass=space.nerdsin.plugins.PluginCore
pluginName=NiSCore
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Sat Oct 19 18:12:56 CDT 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
27 changes: 27 additions & 0 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[versions]
paper-api = "1.18.1-R0.1-SNAPSHOT"
jooq = "3.16.4"
h2 = "2.1.210"
flyway = "8.5.0"
lombok = "1.18.22"
guice = "5.1.0"
reflections = "0.10.2"

[libraries]
paperapi = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper-api" }
lombok = { group = "org.projectlombok", name = "lombok", version.ref = "lombok" }
h2 = { group = "com.h2database", name = "h2", version.ref = "h2" }
jooq = { group = "org.jooq", name = "jooq", version.ref = "jooq" }
jooqmeta = { group = "org.jooq", name = "jooq-meta", version.ref = "jooq" }
jooqmetaext = { group = "org.jooq", name = "jooq-meta-extensions", version.ref = "jooq" }
jooqcodegen = { group = "org.jooq", name = "jooq-codegen", version.ref = "jooq" }
flyway = { group = "org.flywaydb", name = "flyway-core", version.ref = "flyway" }
guice = { group = "com.google.inject", name = "guice", version.ref = "guice" }
reflections = { group = "org.reflections", name = "reflections", version.ref = "reflections" }

[bundles]
jooqgen = ["jooqmeta", "jooqmetaext", "jooqcodegen", "h2"]

[plugins]
jooqgradle = { id = "nu.studer.jooq", version = "5.2.1" }
gitgradle = { id = "com.palantir.git-version", version = "0.12.3" }
33 changes: 33 additions & 0 deletions scripts/cibuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -e

if [[ -n "${DEBUG_MODE}" ]]; then
set -x
fi

function usage() {
echo -n \
"Usage: $(basename "$0")
Build application for staging or a release.
"
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [[ "${1:-}" == "--help" ]]; then
usage
else
# if mounting the hosts cache folder, gradle inside the container will try and
# acquire a file lock that the host machine may already be holding. this will
# result in the container hanging indefinitely. stopping any existing daemons
# on the host is the simplest way to 'solve' this issue
if command -v java &>/dev/null; then
./gradlew --stop
fi

chmod +x ./gradlew

CI="${CI:-}" docker-compose -f docker-compose.ci.yml \
run --rm gradle
fi
fi
21 changes: 21 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
pluginManagement {
repositories {
gradlePluginPortal()
}
}

enableFeaturePreview 'VERSION_CATALOGS'

dependencyResolutionManagement {
repositories {
mavenCentral()
maven { url = 'https://papermc.io/repo/repository/maven-public/' }
}

versionCatalogs {
libs {
from files('libs.versions.toml')
}
}
}

rootProject.name = 'plugins'

0 comments on commit ca70af7

Please sign in to comment.