Skip to content

Commit 785f334

Browse files
authored
[release/3.6] 更新 Jenkins CI 服务器的发布模型 (#4582)
#4559
1 parent 0b87959 commit 785f334

File tree

11 files changed

+207
-25
lines changed

11 files changed

+207
-25
lines changed

HMCL/build.gradle.kts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import org.jackhuang.hmcl.gradle.ci.GitHubActionUtils
2+
import org.jackhuang.hmcl.gradle.ci.JenkinsUtils
13
import org.jackhuang.hmcl.gradle.mod.ParseModDataTask
4+
import org.jackhuang.hmcl.gradle.utils.PropertiesUtils
25
import java.net.URI
36
import java.nio.file.FileSystems
47
import java.nio.file.Files
@@ -12,38 +15,44 @@ plugins {
1215
alias(libs.plugins.shadow)
1316
}
1417

15-
val isOfficial = System.getenv("HMCL_SIGNATURE_KEY") != null
16-
|| (System.getenv("GITHUB_REPOSITORY_OWNER") == "HMCL-dev" && System.getenv("GITHUB_BASE_REF")
17-
.isNullOrEmpty())
18+
val projectConfig = PropertiesUtils.load(rootProject.file("config/project.properties").toPath())
19+
20+
val isOfficial = JenkinsUtils.IS_ON_CI || GitHubActionUtils.IS_ON_OFFICIAL_REPO
1821

19-
val buildNumber = System.getenv("BUILD_NUMBER")?.toInt().let { number ->
20-
val offset = System.getenv("BUILD_NUMBER_OFFSET")?.toInt() ?: 0
21-
if (number != null) {
22-
(number - offset).toString()
23-
} else {
24-
val shortCommit = System.getenv("GITHUB_SHA")?.lowercase()?.substring(0, 7)
25-
val prefix = if (isOfficial) "dev" else "unofficial"
26-
if (!shortCommit.isNullOrEmpty()) "$prefix-$shortCommit" else "SNAPSHOT"
27-
}
28-
}
29-
val versionRoot = System.getenv("VERSION_ROOT") ?: "3.6"
3022
val versionType = System.getenv("VERSION_TYPE") ?: if (isOfficial) "nightly" else "unofficial"
23+
val versionRoot = System.getenv("VERSION_ROOT") ?: projectConfig.getProperty("versionRoot") ?: "3"
3124

3225
val microsoftAuthId = System.getenv("MICROSOFT_AUTH_ID") ?: ""
3326
val microsoftAuthSecret = System.getenv("MICROSOFT_AUTH_SECRET") ?: ""
3427
val curseForgeApiKey = System.getenv("CURSEFORGE_API_KEY") ?: ""
3528

36-
val launcherExe = System.getenv("HMCL_LAUNCHER_EXE")
29+
val launcherExe = System.getenv("HMCL_LAUNCHER_EXE") ?: ""
3730

38-
version = "$versionRoot.$buildNumber"
31+
val buildNumber = System.getenv("BUILD_NUMBER")?.toInt()
32+
if (buildNumber != null) {
33+
version = if (JenkinsUtils.IS_ON_CI && versionType == "dev") {
34+
"$versionRoot.0.$buildNumber"
35+
} else {
36+
"$versionRoot.$buildNumber"
37+
}
38+
} else {
39+
val shortCommit = System.getenv("GITHUB_SHA")?.lowercase()?.substring(0, 7)
40+
version = if (shortCommit.isNullOrBlank()) {
41+
"$versionRoot.SNAPSHOT"
42+
} else if (isOfficial) {
43+
"$versionRoot.dev-$shortCommit"
44+
} else {
45+
"$versionRoot.unofficial-$shortCommit"
46+
}
47+
}
3948

4049
dependencies {
4150
implementation(project(":HMCLCore"))
4251
implementation("libs:JFoenix")
4352
implementation(libs.twelvemonkeys.imageio.webp)
4453
implementation(libs.java.info)
4554

46-
if (launcherExe == null) {
55+
if (launcherExe.isBlank()) {
4756
implementation(libs.hmclauncher)
4857
}
4958
}
@@ -162,7 +171,7 @@ tasks.shadowJar {
162171
}
163172
}
164173

165-
if (launcherExe != null) {
174+
if (launcherExe.isNotBlank()) {
166175
into("assets") {
167176
from(file(launcherExe))
168177
}

build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ subprojects {
1818
name = "libs"
1919
dirs = setOf(rootProject.file("lib"))
2020
}
21-
mavenCentral()
21+
22+
System.getenv("MAVEN_CENTRAL_REPO").let { repo ->
23+
if (repo.isNullOrBlank())
24+
mavenCentral()
25+
else
26+
maven(url = repo)
27+
}
28+
2229
maven(url = "https://jitpack.io")
2330
maven(url = "https://libraries.minecraft.net")
2431
}

buildSrc/build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
repositories {
2-
mavenCentral()
2+
System.getenv("MAVEN_CENTRAL_REPO").let { repo ->
3+
if (repo.isNullOrBlank())
4+
mavenCentral()
5+
else
6+
maven(url = repo)
7+
}
38
}
49

510
dependencies {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Hello Minecraft! Launcher
3+
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package org.jackhuang.hmcl.gradle.ci;
19+
20+
import java.util.Objects;
21+
22+
/// @author Glavo
23+
public final class GitHubActionUtils {
24+
private static final String OFFICIAL_ORGANIZATION = "HMCL-dev";
25+
26+
public static final boolean IS_ON_OFFICIAL_REPO =
27+
OFFICIAL_ORGANIZATION.equalsIgnoreCase(System.getenv("GITHUB_REPOSITORY_OWNER"))
28+
&& Objects.requireNonNullElse(System.getenv("GITHUB_BASE_REF"), "").isBlank();
29+
30+
private GitHubActionUtils() {
31+
}
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Hello Minecraft! Launcher
3+
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package org.jackhuang.hmcl.gradle.ci;
19+
20+
/// @author Glavo
21+
public final class JenkinsUtils {
22+
23+
public static final boolean IS_ON_CI = "1".equals(System.getenv("HMCL_CI"));
24+
25+
private JenkinsUtils() {
26+
}
27+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Hello Minecraft! Launcher
3+
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package org.jackhuang.hmcl.gradle.utils;
19+
20+
import org.jetbrains.annotations.NotNull;
21+
22+
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import java.util.Properties;
26+
27+
/// @author Glavo
28+
public final class PropertiesUtils {
29+
public static @NotNull Properties load(Path path) throws IOException {
30+
Properties properties = new Properties();
31+
try (var reader = Files.newBufferedReader(path)) {
32+
properties.load(reader);
33+
}
34+
return properties;
35+
}
36+
37+
private PropertiesUtils() {
38+
}
39+
}

config-jenkins.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/jenkins/config-jenkins.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
sed -i 's,//services.gradle.org/distributions/,//mirrors.cloud.tencent.com/gradle/,g' "$PWD/gradle/wrapper/gradle-wrapper.properties"
4+

config/jenkins/dev/Jenkinsfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pipeline {
2+
agent any
3+
4+
environment {
5+
HMCL_CI = '1'
6+
7+
VERSION_TYPE = 'dev'
8+
MICROSOFT_AUTH_ID = credentials('microsoft_auth_id')
9+
MICROSOFT_AUTH_SECRET = credentials('microsoft_auth_secret')
10+
CURSEFORGE_API_KEY = credentials('curseforge_api_key')
11+
HMCL_SIGNATURE_KEY = credentials('hmcl_signature_key')
12+
}
13+
14+
stages {
15+
stage('Build') {
16+
steps {
17+
sh 'bash ./config/jenkins/config-jenkins.sh'
18+
sh './gradlew clean makeExecutables --stacktrace --no-daemon'
19+
archiveArtifacts artifacts: 'HMCL/build/libs/*'
20+
}
21+
}
22+
}
23+
}

config/jenkins/stable/Jenkinsfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pipeline {
2+
agent any
3+
4+
environment {
5+
HMCL_CI = '1'
6+
7+
VERSION_TYPE = 'stable'
8+
MICROSOFT_AUTH_ID = credentials('microsoft_auth_id')
9+
MICROSOFT_AUTH_SECRET = credentials('microsoft_auth_secret')
10+
CURSEFORGE_API_KEY = credentials('curseforge_api_key')
11+
HMCL_SIGNATURE_KEY = credentials('hmcl_signature_key')
12+
}
13+
14+
stages {
15+
stage('Build') {
16+
steps {
17+
sh 'bash ./config/jenkins/config-jenkins.sh'
18+
sh './gradlew clean makeExecutables --stacktrace --no-daemon'
19+
archiveArtifacts artifacts: 'HMCL/build/libs/*'
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)