Skip to content

Commit

Permalink
Add branch name when not master, simplify publish, use GitHub Actions
Browse files Browse the repository at this point in the history
And updated Gradle
  • Loading branch information
Tim203 committed Feb 12, 2023
1 parent f44319c commit da97a0f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 55 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v3
with:
submodules: recursive

- uses: actions/setup-java@v3
with:
java-version: 8
distribution: temurin

- name: Build
uses: gradle/gradle-build-action@v2
with:
arguments: build

- name: Publish
uses: gradle/gradle-build-action@v2
env:
ORG_GRADLE_PROJECT_geysermcUsername: "${{ secrets.DEPLOY_USER }}"
ORG_GRADLE_PROJECT_geysermcPassword: "${{ secrets.DEPLOY_PASS }}"
with:
arguments: publish
4 changes: 2 additions & 2 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ repositories {
}

dependencies {
implementation("net.kyori", "indra-common", "2.0.6")
implementation("org.jfrog.buildinfo", "build-info-extractor-gradle", "4.26.1")
implementation("net.kyori", "indra-common", "3.0.1")
implementation("net.kyori", "indra-git", "3.0.1")
implementation("gradle.plugin.com.github.johnrengelman", "shadow", "7.1.1")
implementation("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext", "gradle-idea-ext", "1.1.7")
}
Expand Down
20 changes: 11 additions & 9 deletions build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.kotlin.dsl.the

fun Project.isSnapshot(): Boolean =
version.toString().endsWith("-SNAPSHOT")

fun Project.fullVersion(): String {
var version = version.toString()
if (version.endsWith("-SNAPSHOT")) {
Expand All @@ -42,14 +39,19 @@ fun Project.fullVersion(): String {
fun Project.lastCommitHash(): String? =
the<IndraGitExtension>().commit()?.name?.substring(0, 7)

// retrieved from https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
// some properties might be specific to Jenkins
fun Project.branchName(): String =
System.getenv("GIT_BRANCH") ?: "local/dev"
fun Project.buildNumber(): Int =
Integer.parseInt(System.getenv("BUILD_NUMBER") ?: "-1")
the<IndraGitExtension>().branchName() ?: System.getenv("BRANCH_NAME") ?: "local/dev"

fun Project.shouldAddBranchName(): Boolean =
System.getenv("IGNORE_BRANCH")?.toBoolean() ?: (branchName() !in arrayOf("master", "local/dev"))

fun Project.versionWithBranchName(): String =
branchName().replace(Regex("[^0-9A-Za-z-_]"), "-") + '-' + version

fun buildNumber(): Int =
System.getenv("BUILD_NUMBER")?.let { Integer.parseInt(it) } ?: -1

fun Project.buildNumberAsString(): String =
fun buildNumberAsString(): String =
buildNumber().takeIf { it != -1 }?.toString() ?: "??"

val providedDependencies = mutableMapOf<String, MutableSet<Pair<String, Any>>>()
Expand Down
27 changes: 16 additions & 11 deletions build-logic/src/main/kotlin/floodgate.base-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
plugins {
`java-library`
`maven-publish`
// id("net.ltgt.errorprone")
id("net.kyori.indra")
id("net.kyori.indra.git")
}

dependencies {
compileOnly("org.checkerframework", "checker-qual", Versions.checkerQual)
}

indra {
github("GeyserMC", "Floodgate") {
ci(true)
issues(true)
scm(true)
}
mitLicense()

javaVersions {
// without toolchain & strictVersion sun.misc.Unsafe won't be found
minimumToolchain(8)
strictVersions(true)
}
}

tasks {
processResources {
filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json")) {
Expand All @@ -22,14 +37,4 @@ tasks {
)
}
}
compileJava {
options.encoding = Charsets.UTF_8.name()
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

withSourcesJar()
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
plugins {
id("floodgate.shadow-conventions")
id("com.jfrog.artifactory")
id("maven-publish")
id("net.kyori.indra.publishing")
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = project.group as String
artifactId = project.name
version = project.version as String

from(components["java"])
indra {
configurePublications {
if (shouldAddBranchName()) {
version = versionWithBranchName()
}
}
}

artifactory {
setContextUrl("https://repo.opencollab.dev/artifactory")
publish {
repository {
setRepoKey(if (isSnapshot()) "maven-snapshots" else "maven-releases")
setMavenCompatible(true)
}
defaults {
publications("mavenJava")
setPublishArtifacts(true)
setPublishPom(true)
setPublishIvy(false)
}
}
publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/artifactory/maven-snapshots")
publishReleasesTo("geysermc", "https://repo.opencollab.dev/artifactory/maven-releases")
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static Object getValue(Object instance, String fieldName) {
}

/**
* Get the value of a field and cast it to <T>.
* Get the value of a field and cast it to T.
*
* @param instance the instance to get the value from
* @param field the field to get the value from
Expand All @@ -301,7 +301,7 @@ public static <T> T getCastedValue(Object instance, Field field) {
}

/**
* Get the value of a field and cast it to <T>.
* Get the value of a field and cast it to T.
*
* @param instance the instance to get the value from
* @param fieldName the field to get the value from
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 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 5 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
Expand Down
5 changes: 5 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@file:Suppress("UnstableApiUsage")
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

dependencyResolutionManagement {
Expand Down Expand Up @@ -54,6 +55,10 @@ pluginManagement {
repositories {
gradlePluginPortal()
}
plugins {
id("net.kyori.indra")
id("net.kyori.indra.git")
}
includeBuild("build-logic")
}

Expand Down

0 comments on commit da97a0f

Please sign in to comment.