Skip to content

Commit ca4084c

Browse files
authored
add github actions & fix version (#43)
* add github actions * remove cache * fix Version codings
1 parent dc1759e commit ca4084c

File tree

6 files changed

+117
-32
lines changed

6 files changed

+117
-32
lines changed

.github/workflows/autobuild.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ref:
2+
# Writing Workflows:
3+
# https://docs.github.com/en/actions/writing-workflows
4+
# Setup Java JDK:
5+
# https://github.com/marketplace/actions/setup-java-jdk
6+
# And the github action env is clean by default so the project need to be pulled and checkout by job
7+
# https://github.com/marketplace/actions/checkout
8+
# otherwise there is nothing in the workspace folder (can also run git pull but this one make thing easy)
9+
# @v4 seems like the latest version matches v4.x.x for a job
10+
#
11+
name: AutoBuilder
12+
run-name: 'Auto build on ${{github.ref_type}} ${{github.ref_name}} #${{github.run_number}}'
13+
on: [push]
14+
jobs:
15+
Build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: setup jdk
19+
uses: actions/setup-java@v4
20+
with:
21+
distribution: 'oracle'
22+
java-version: '21'
23+
- name: checkout repo
24+
uses: actions/checkout@v4
25+
- name: build project with gradle
26+
run: ./gradlew build -i
27+
- name: upload artifacts
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: ${{github.event.repository.name}}-autobuild-${{github.run_number}}-git-${{github.sha}}.zip
31+
path: ./build/libs/*.jar
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3+
# also ref:
4+
# Publishing packages to GitHub Packages:
5+
# https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-java-packages-with-maven#publishing-packages-to-github-packages
6+
#
7+
# Upgrade to Automatic token authentication, no need for personal access token anymore
8+
# ref: https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-a-registry-using-a-personal-access-token
9+
#
10+
11+
name: Publish to GitHub Packages
12+
13+
run-name: 'Package Publish #${{github.run_number}}'
14+
15+
on:
16+
release:
17+
types: [published]
18+
workflow_dispatch:
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
24+
permissions:
25+
packages: write
26+
contents: read
27+
28+
steps:
29+
- name: Checkout Code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up JDK
33+
uses: actions/setup-java@v4
34+
with:
35+
java-version: '21'
36+
distribution: 'oracle'
37+
38+
- name: Publish to GitHub Packages Apache Maven
39+
run: ./gradlew publish -i
40+
env:
41+
BUILD_NUMBER: ${{github.run_number}}
42+
MAVEN_DIR: https://maven.pkg.github.com/${{github.repository}}
43+
MAVEN_USERNAME: ${{github.actor}}
44+
MAVEN_PASSWORD: ${{secrets.GITHUB_TOKEN}}

build.gradle.kts

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@ val paperApiName = "1.21-R0.1-SNAPSHOT"
1919
// = = =
2020

2121
// for Jenkins CI
22-
val buildNumber = System.getenv("BUILD_NUMBER") ?: "local"
23-
val mavenDirectory =
24-
System.getenv("MAVEN_DIR")
25-
?: layout.buildDirectory.dir("repo").path.toString()
26-
val javaDocDirectory =
27-
System.getenv("JAVADOC_DIR")
28-
?: layout.buildDirectory.dir("javadoc").path.toString()
22+
val buildNumber = System.getenv("BUILD_NUMBER") ?: "x"
23+
val mavenDirectory = System.getenv("MAVEN_DIR") ?: layout.buildDirectory.dir("repo").path.toString()
24+
val javaDocDirectory = System.getenv("JAVADOC_DIR") ?: layout.buildDirectory.dir("javadoc").path.toString()
2925

3026
// Version used for distribution. Different from maven repo
3127
group = "cat.nyaa"
3228
//archivesBaseName = "${pluginNameUpper}-mc$minecraftVersion"
33-
version =
34-
"$majorVersion.$minorVersion"
29+
version ="$majorVersion.$minorVersion"
3530

3631
java {
3732
// Configure the java toolchain. This allows gradle to auto-provision JDK 21 on systems that only have JDK 8 installed for example.
@@ -45,12 +40,12 @@ repositories {
4540
} //paper
4641
maven { url = uri("https://libraries.minecraft.net") } // mojang
4742
maven { url = uri("https://repo.essentialsx.net/releases/") } // essentials
48-
maven { url = uri("https://ci.nyaacat.com/maven/") } // nyaacat
43+
// maven { url = uri("https://ci.nyaacat.com/maven/") } // nyaacat
4944

5045
}
5146

5247
dependencies {
53-
paperweightDevelopmentBundle(paperweight.paperDevBundle(paperApiName))
48+
paperweight.paperDevBundle(paperApiName)
5449
// paperweight.foliaDevBundle("1.21-R0.1-SNAPSHOT")
5550
// paperweight.devBundle("com.example.paperfork", "1.21-R0.1-SNAPSHOT")
5651
compileOnly("net.essentialsx:EssentialsX:2.20.1") // soft dep
@@ -68,23 +63,24 @@ dependencies {
6863
publishing {
6964
publications {
7065
create<MavenPublication>("mavenJava") {
71-
from(getComponents()["java"])
72-
afterEvaluate {
73-
artifactId = pluginName.lowercase()
74-
groupId = "$group"
75-
version =
76-
"$majorVersion.$minorVersion.$buildNumber-${
77-
getMcVersion(
78-
paperApiName
79-
)
80-
}"
81-
}
66+
from(components["java"])
67+
groupId = group.toString()
68+
artifactId = pluginName.lowercase()
69+
version = "$majorVersion.$minorVersion.$buildNumber-mc${getMcVersion(paperApiName)}"
8270
}
8371
}
8472
repositories {
8573
maven {
86-
name = "nyaaMaven"
74+
name = "PublishMaven"
8775
url = uri(mavenDirectory)
76+
val mavenUserName = System.getenv("MAVEN_USERNAME")
77+
val mavenPassword = System.getenv("MAVEN_PASSWORD")
78+
if(mavenUserName != null && mavenPassword != null) {
79+
credentials {
80+
username = mavenUserName
81+
password = mavenPassword
82+
}
83+
}
8884
}
8985
}
9086
}
@@ -99,11 +95,29 @@ reobfJar {
9995

10096

10197
tasks {
98+
99+
// 1)
100+
// For >=1.20.5 when you don't care about supporting spigot
101+
// paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.MOJANG_PRODUCTION
102+
103+
// 2)
104+
// For 1.20.4 or below, or when you care about supporting Spigot on >=1.20.5
105+
// Configure reobfJar to run when invoking the build task
106+
/*
102107
// Configure reobfJar to run when invoking the build task
103108
assemble {
104109
dependsOn(reobfJar)
105110
}
111+
*/
106112

113+
withType<ProcessResources> {
114+
115+
val newProperties = project.properties.toMutableMap()
116+
newProperties["api_version"] = getMcVersion(paperApiName)
117+
filesMatching("plugin.yml") {
118+
expand(newProperties)
119+
}
120+
}
107121

108122
compileJava {
109123
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
@@ -112,6 +126,7 @@ tasks {
112126
// See https://openjdk.java.net/jeps/247 for more information.
113127
options.release.set(21)
114128
}
129+
115130
javadoc {
116131
with((options as StandardJavadocDocletOptions)) {
117132
options.encoding =

src/main/java/cat/nyaa/nyaacore/NyaaCoreLoader.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,9 @@ public void onEnable() {
5656
getLogger().severe(e.getMessage());
5757
Bukkit.getPluginManager().disablePlugin(this);
5858
}
59-
try {
60-
var VersionResource = getResource("MCVersion");
61-
targetVersion = VersionResource == null ? "" : new String(VersionResource.readAllBytes());
62-
getLogger().info("target minecraft version:" + targetVersion + "server version:" + serverVersion);
63-
} catch (Exception e) {
64-
throw new RuntimeException(e);
65-
}
59+
var pluginDescription = getDescription();
60+
targetVersion = pluginDescription.getAPIVersion();
61+
getLogger().info("target minecraft version:" + targetVersion + " ,server version:" + serverVersion);
6662
Bukkit.getPluginManager().registerEvents(new ClickSelectionUtils._Listener(), this);
6763
Bukkit.getPluginManager().registerEvents(new OfflinePlayerUtils._Listener(), this);
6864
OfflinePlayerUtils.init();

src/main/resources/MCVersion

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ loadbefore:
88
- aolib
99
authors: [ RecursiveG,Librazy,cyilin ]
1010
website: "https://github.com/NyaaCat/NyaaCore"
11-
api-version: 1.19
11+
api-version: ${api_version}

0 commit comments

Comments
 (0)