Skip to content

Commit 0f89aa0

Browse files
committed
Implemented loader self update, added github action workflows
1 parent 4a73ea6 commit 0f89aa0

File tree

10 files changed

+1000
-367
lines changed

10 files changed

+1000
-367
lines changed

.github/workflows/build.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches: [ master, main, develop ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up JDK 21
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '21'
19+
distribution: 'temurin'
20+
cache: gradle
21+
22+
- name: Grant execute permission for gradlew
23+
run: chmod +x gradlew
24+
25+
- name: Build with Gradle
26+
run: ./gradlew build
27+
28+
- name: Run tests
29+
run: ./gradlew test
30+
31+
- name: Upload build artifacts
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: Lambda-Loader-PR-${{ github.event.pull_request.number }}
35+
path: build/libs/*.jar
36+
if-no-files-found: error

.github/workflows/publish.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Publish to Maven
2+
3+
on:
4+
push:
5+
branches: [ master, main, develop ]
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up JDK 21
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '21'
23+
distribution: 'temurin'
24+
cache: gradle
25+
26+
- name: Grant execute permission for gradlew
27+
run: chmod +x gradlew
28+
29+
- name: Determine version and repository
30+
id: version
31+
run: |
32+
if [ "${{ github.event_name }}" == "release" ]; then
33+
# This is a GitHub release - publish as release version
34+
VERSION="${{ github.event.release.tag_name }}"
35+
# Remove 'v' prefix if present
36+
VERSION="${VERSION#v}"
37+
REPO_TYPE="releases"
38+
echo "is_snapshot=false" >> $GITHUB_OUTPUT
39+
echo "Publishing release version: $VERSION"
40+
else
41+
# This is a regular commit - publish as snapshot
42+
# Get base version from gradle.properties
43+
BASE_VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | tr -d ' ')
44+
# Remove -SNAPSHOT suffix if present
45+
BASE_VERSION="${BASE_VERSION%-SNAPSHOT}"
46+
47+
# Get current Minecraft version from gradle.properties
48+
MC_VERSION=$(grep "minecraft_version" gradle.properties | cut -d'=' -f2 | tr -d ' ')
49+
50+
# Get short commit hash
51+
COMMIT_HASH=$(git rev-parse --short HEAD)
52+
53+
# Get commit count for this branch
54+
COMMIT_COUNT=$(git rev-list --count HEAD)
55+
56+
# Build snapshot version: base+mcVersion-SNAPSHOT
57+
VERSION="${BASE_VERSION}+${MC_VERSION}-SNAPSHOT"
58+
REPO_TYPE="snapshots"
59+
echo "is_snapshot=true" >> $GITHUB_OUTPUT
60+
echo "Publishing snapshot version: $VERSION (commit: $COMMIT_HASH, build: $COMMIT_COUNT)"
61+
fi
62+
63+
echo "version=$VERSION" >> $GITHUB_OUTPUT
64+
echo "repo_type=$REPO_TYPE" >> $GITHUB_OUTPUT
65+
66+
- name: Update version in gradle.properties
67+
run: |
68+
sed -i "s/mod_version = .*/mod_version = ${{ steps.version.outputs.version }}/" gradle.properties
69+
70+
- name: Build with Gradle
71+
run: ./gradlew build
72+
73+
- name: Publish to Maven Repository
74+
env:
75+
MAVEN_URL: ${{ secrets.MAVEN_URL }}
76+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
77+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
78+
run: |
79+
# Append repository type to maven URL if not already present
80+
if [[ ! "$MAVEN_URL" == */${{ steps.version.outputs.repo_type }} ]]; then
81+
export MAVEN_URL="${MAVEN_URL}/${{ steps.version.outputs.repo_type }}"
82+
fi
83+
84+
echo "Publishing to ${{ steps.version.outputs.repo_type }} repository: $MAVEN_URL"
85+
./gradlew publish
86+
87+
- name: Upload build artifacts
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: Lambda-Loader-${{ steps.version.outputs.version }}
91+
path: build/libs/*.jar
92+
if-no-files-found: error

build.gradle.kts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,60 @@ tasks.jar {
8989
publishing {
9090
publications {
9191
create<MavenPublication>("mavenJava") {
92-
artifactId = project.property("archives_base_name") as String
92+
groupId = project.property("maven_group") as String
93+
artifactId = "loader"
94+
version = project.version as String
95+
9396
from(components["java"])
97+
98+
pom {
99+
name.set("Lambda Loader")
100+
description.set("A Fabric mod loader for Lambda Client")
101+
url.set("https://github.com/lambda-client/Lambda-loader")
102+
103+
licenses {
104+
license {
105+
name.set("MIT License")
106+
url.set("https://opensource.org/licenses/MIT")
107+
}
108+
}
109+
110+
developers {
111+
developer {
112+
id.set("lambda")
113+
name.set("Lambda Client Team")
114+
}
115+
}
116+
117+
scm {
118+
connection.set("scm:git:git://github.com/lambda-client/Lambda-loader.git")
119+
developerConnection.set("scm:git:ssh://github.com/lambda-client/Lambda-loader.git")
120+
url.set("https://github.com/lambda-client/Lambda-loader")
121+
}
122+
}
94123
}
95124
}
96125

97-
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
98126
repositories {
99-
// Add repositories to publish to here.
100-
// Notice: This block does NOT have the same function as the block in the top level.
101-
// The repositories here will be used for publishing your artifact, not for
102-
// retrieving dependencies.
127+
// Publish to local maven repository for testing
128+
mavenLocal()
129+
130+
// Publish to remote maven repository
131+
// Set credentials via environment variables or gradle.properties:
132+
// MAVEN_URL, MAVEN_USERNAME, MAVEN_PASSWORD
133+
val mavenUrl = System.getenv("MAVEN_URL") ?: project.findProperty("mavenUrl") as String?
134+
val mavenUsername = System.getenv("MAVEN_USERNAME") ?: project.findProperty("mavenUsername") as String?
135+
val mavenPassword = System.getenv("MAVEN_PASSWORD") ?: project.findProperty("mavenPassword") as String?
136+
137+
if (mavenUrl != null && mavenUsername != null && mavenPassword != null) {
138+
maven {
139+
name = "RemoteMaven"
140+
url = uri(mavenUrl)
141+
credentials {
142+
username = mavenUsername
143+
password = mavenPassword
144+
}
145+
}
146+
}
103147
}
104148
}

0 commit comments

Comments
 (0)