diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml new file mode 100644 index 0000000..73b5549 --- /dev/null +++ b/.github/workflows/build-and-push.yml @@ -0,0 +1,44 @@ +name: Build and publish artifacts + +on: + push: + branches: + - stable + - dev + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Java + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b + + - name: Extract branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + + - name: Set Repository Environment Variable + run: | + if [ "${{ steps.extract_branch.outputs.branch }}" == "stable" ]; then + echo "NEXUS_REPOSITORY=${{ secrets.NEXUS_STABLE_REPOSITORY }}" >> $GITHUB_ENV + else + echo "NEXUS_REPOSITORY=${{ secrets.NEXUS_DEV_REPOSITORY }}" >> $GITHUB_ENV + fi + + - name: Publish package + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: publish + env: + NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} + NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} + NEXUS_REPOSITORY: ${{ env.NEXUS_REPOSITORY }} \ No newline at end of file diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index 4536d4d..0000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,44 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Gradle - -on: - push: - branches: [ "*" ] - pull_request: - branches: [ "*" ] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - name: Build with Gradle - uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 - with: - arguments: build - - name: Rename JAR - run: mv build/libs/eclobby-*.jar ./eclobby.jar - - name: Upload a Build Artifact - uses: actions/upload-artifact@v3.1.0 - with: - # Artifact name - name: eclobby-build - # A file, directory or wildcard pattern that describes what to upload - path: ./eclobby.jar - # The desired behavior if no files are found using the provided path. diff --git a/build.gradle b/build.gradle index 7508065..133a012 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'maven-publish' } group = 'fr.efreicraft' @@ -17,14 +18,23 @@ repositories { name = 'sonatype' url = 'https://oss.sonatype.org/content/groups/public/' } + if (System.getenv("NEXUS_REPOSITORY")) { + println "Using Nexus repository" + maven { + name = 'nexus' + url = uri(System.getenv("NEXUS_REPOSITORY")) + credentials { + username = System.getenv("NEXUS_USERNAME") + password = System.getenv("NEXUS_PASSWORD") + } + } + } } dependencies { compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT' - compileOnly files("../AnimusClient/swagger/code/") - compileOnly "fr.efreicraft:AnimusClient" - compileOnly "fr.efreicraft:ECATUP" + compileOnly "fr.efreicraft:ECATUP:latest.integration" } def targetJavaVersion = 17 @@ -56,6 +66,37 @@ configurations { jar.archiveName = rootProject.name + ".jar" } +publishing { + publications { + maven(MavenPublication) { + groupId = rootProject.group + artifactId = rootProject.name + version = rootProject.version + + from components.java + + pom.packaging = 'jar' + + artifact("${buildDir}/libs/${rootProject.name}.jar") { + classifier = 'jar' + } + } + } + repositories { + if (System.getenv("NEXUS_REPOSITORY")) { + maven { + url = uri(System.getenv("NEXUS_REPOSITORY")) + credentials { + username = System.getenv("NEXUS_USERNAME") + password = System.getenv("NEXUS_PASSWORD") + } + } + } else { + mavenLocal() + } + } +} + task devBuildDockerImage(type: Exec) { dependsOn build diff --git a/settings.gradle b/settings.gradle index 2598d66..2f76092 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,7 @@ rootProject.name = 'eclobby' -includeBuild("../ECATUP") { - name = "ecatup" +if(!System.getenv("NEXUS_REPOSITORY")) { + includeBuild("../ECATUP") { + name = "ecatup" + } } \ No newline at end of file