Skip to content

Commit

Permalink
Enhance CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlgo committed Jul 28, 2022
1 parent 05e40c0 commit 583bece
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 125 deletions.
60 changes: 31 additions & 29 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
name: Java CI

on: [push]
on: [ push ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Change wrapper permissions
run: chmod +x ./gradlew

- name: Gradle Build
uses: gradle/gradle-build-action@v2
with:
arguments: build --scan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- id: commit
uses: pr-mpt/actions-commit-hash@v1

- uses: actions/upload-artifact@v3
with:
name: MikChanNoFood-${{ steps.commit.outputs.short }}.zip
path: |
build/libs/
LICENSE.txt
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Get Commit Data
id: commit
uses: pr-mpt/actions-commit-hash@v1

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Change Wrapper Permissions
run: chmod +x ./gradlew

- name: Gradle Build
uses: gradle/gradle-build-action@v2
with:
arguments: shadowJar --scan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: dev-${{ steps.commit.outputs.short }}

- uses: actions/upload-artifact@v3
with:
name: MikChanNoFood-dev-${{ steps.commit.outputs.short }}.zip
path: |
build/libs/
LICENSE.txt
87 changes: 44 additions & 43 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,56 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Change wrapper permissions
run: chmod +x ./gradlew

- name: Build Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: shadowJar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
LICENSE.txt
build/libs/*.jar
- name: Change wrapper permissions
run: chmod +x ./gradlew

- name: Build Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
LICENSE.txt
build/libs/MCnFood-*.jar
publish:
runs-on: ubuntu-latest

permissions:
permissions:
contents: read
packages: write
packages: write

steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Change wrapper permissions
run: chmod +x ./gradlew

- name: Publish package
uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish package
uses: gradle/gradle-build-action@v2
with:
arguments: publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95 changes: 42 additions & 53 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
id 'org.jetbrains.dokka' version "1.7.10"
id "java"
id "org.jetbrains.kotlin.jvm" version "1.7.10"
id 'maven-publish'
id "com.github.johnrengelman.shadow" version "7.1.2"
}
Expand All @@ -13,53 +12,33 @@ if (hasProperty('buildScan')) {
}
}

group = 'dev.mikchan.mcnp'
version = '1.0.4'

compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

static def determineVersion(String defaultVersion) {
def envVersion = System.getenv("VERSION")
return envVersion == null ? defaultVersion : envVersion
}

group = "dev.mikchan.mcnp"
version = determineVersion("0.0.4")

def localProperties = new Properties()
def propertiesFile = rootProject.file('local.properties')
if (propertiesFile.exists()) {
localProperties.load(new FileInputStream(propertiesFile))
}

if (file("local.gradle").exists()) {
apply from: "local.gradle"
}

publishing {
repositories {
maven {
name = "GitHub"
url = "https://maven.pkg.github.com/MikChanNoPlugins/Food"
credentials {
username = localProperties['user'] ?: System.getenv("GITHUB_ACTOR")
password = localProperties['key'] ?: System.getenv("GITHUB_TOKEN")
}
}
}

publications {
gpr(MavenPublication) {
groupId = group
artifactId = 'food'
version = version

from(components.java)
}
}
}

repositories {
mavenCentral()

maven {
name = 'spigotmc-repo'
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}

maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/'
Expand All @@ -86,17 +65,8 @@ java {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}

withJavadocJar()
withSourcesJar()
}

assemble.dependsOn(shadowJar)
jar {
enabled = false
dependsOn(shadowJar {
//noinspection GrDeprecatedAPIUsage
classifier = null
})
withJavadocJar()
}

tasks.withType(JavaCompile).configureEach {
Expand All @@ -108,8 +78,8 @@ tasks.withType(JavaCompile).configureEach {
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
filteringCharset "UTF-8"
filesMatching("plugin.yml") {
expand props
}
}
Expand All @@ -126,17 +96,13 @@ compileTestKotlin {
}
}

dokkaHtml {
outputDirectory.set(file("${buildDir}/dokka"))
}

javadocJar {
archiveClassifier.set("javadoc")
dependsOn("dokkaHtml")
from("$buildDir/dokka")
if (file("local.gradle").exists()) {
apply from: "local.gradle"
}

shadowJar {
archiveClassifier.set(null)

dependencies {
include(dependency('org.bstats:bstats-bukkit'))
include(dependency('org.bstats:bstats-base'))
Expand All @@ -145,3 +111,26 @@ shadowJar {
relocate "org.bstats", "dev.mikchan.mcnp.food.bstats"
}

publishing {
repositories {
maven {
name = "GitHub"
url = "https://maven.pkg.github.com/MikChanNoPlugins/Food"
credentials {
username = localProperties['user'] ?: System.getenv("GITHUB_ACTOR")
password = localProperties['key'] ?: System.getenv("GITHUB_TOKEN")
}
}
}

publications {
gpr(MavenPublication) {
groupId = group
artifactId = 'food'

artifact jar
artifact javadocJar
artifact sourcesJar
}
}
}

0 comments on commit 583bece

Please sign in to comment.