更新 Jenkins CI 服务器的发布模型 (#4559)
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
|
import org.jackhuang.hmcl.gradle.ci.GitHubActionUtils
|
||||||
|
import org.jackhuang.hmcl.gradle.ci.JenkinsUtils
|
||||||
import org.jackhuang.hmcl.gradle.l10n.CheckTranslations
|
import org.jackhuang.hmcl.gradle.l10n.CheckTranslations
|
||||||
import org.jackhuang.hmcl.gradle.l10n.CreateLanguageList
|
import org.jackhuang.hmcl.gradle.l10n.CreateLanguageList
|
||||||
import org.jackhuang.hmcl.gradle.l10n.CreateLocaleNamesResourceBundle
|
import org.jackhuang.hmcl.gradle.l10n.CreateLocaleNamesResourceBundle
|
||||||
import org.jackhuang.hmcl.gradle.l10n.UpsideDownTranslate
|
import org.jackhuang.hmcl.gradle.l10n.UpsideDownTranslate
|
||||||
import org.jackhuang.hmcl.gradle.mod.ParseModDataTask
|
import org.jackhuang.hmcl.gradle.mod.ParseModDataTask
|
||||||
|
import org.jackhuang.hmcl.gradle.utils.PropertiesUtils
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.nio.file.FileSystems
|
import java.nio.file.FileSystems
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
@@ -16,30 +19,36 @@ plugins {
|
|||||||
alias(libs.plugins.shadow)
|
alias(libs.plugins.shadow)
|
||||||
}
|
}
|
||||||
|
|
||||||
val isOfficial = System.getenv("HMCL_SIGNATURE_KEY") != null
|
val projectConfig = PropertiesUtils.load(rootProject.file("config/project.properties").toPath())
|
||||||
|| (System.getenv("GITHUB_REPOSITORY_OWNER") == "HMCL-dev" && System.getenv("GITHUB_BASE_REF")
|
|
||||||
.isNullOrEmpty())
|
val isOfficial = JenkinsUtils.IS_ON_CI || GitHubActionUtils.IS_ON_OFFICIAL_REPO
|
||||||
|
|
||||||
val buildNumber = System.getenv("BUILD_NUMBER")?.toInt().let { number ->
|
|
||||||
val offset = System.getenv("BUILD_NUMBER_OFFSET")?.toInt() ?: 0
|
|
||||||
if (number != null) {
|
|
||||||
(number - offset).toString()
|
|
||||||
} else {
|
|
||||||
val shortCommit = System.getenv("GITHUB_SHA")?.lowercase()?.substring(0, 7)
|
|
||||||
val prefix = if (isOfficial) "dev" else "unofficial"
|
|
||||||
if (!shortCommit.isNullOrEmpty()) "$prefix-$shortCommit" else "SNAPSHOT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val versionRoot = System.getenv("VERSION_ROOT") ?: "3.6"
|
|
||||||
val versionType = System.getenv("VERSION_TYPE") ?: if (isOfficial) "nightly" else "unofficial"
|
val versionType = System.getenv("VERSION_TYPE") ?: if (isOfficial) "nightly" else "unofficial"
|
||||||
|
val versionRoot = System.getenv("VERSION_ROOT") ?: projectConfig.getProperty("versionRoot") ?: "3"
|
||||||
|
|
||||||
val microsoftAuthId = System.getenv("MICROSOFT_AUTH_ID") ?: ""
|
val microsoftAuthId = System.getenv("MICROSOFT_AUTH_ID") ?: ""
|
||||||
val microsoftAuthSecret = System.getenv("MICROSOFT_AUTH_SECRET") ?: ""
|
val microsoftAuthSecret = System.getenv("MICROSOFT_AUTH_SECRET") ?: ""
|
||||||
val curseForgeApiKey = System.getenv("CURSEFORGE_API_KEY") ?: ""
|
val curseForgeApiKey = System.getenv("CURSEFORGE_API_KEY") ?: ""
|
||||||
|
|
||||||
val launcherExe = System.getenv("HMCL_LAUNCHER_EXE")
|
val launcherExe = System.getenv("HMCL_LAUNCHER_EXE") ?: ""
|
||||||
|
|
||||||
version = "$versionRoot.$buildNumber"
|
val buildNumber = System.getenv("BUILD_NUMBER")?.toInt()
|
||||||
|
if (buildNumber != null) {
|
||||||
|
version = if (JenkinsUtils.IS_ON_CI && versionType == "dev") {
|
||||||
|
"$versionRoot.0.$buildNumber"
|
||||||
|
} else {
|
||||||
|
"$versionRoot.$buildNumber"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val shortCommit = System.getenv("GITHUB_SHA")?.lowercase()?.substring(0, 7)
|
||||||
|
version = if (shortCommit.isNullOrBlank()) {
|
||||||
|
"$versionRoot.SNAPSHOT"
|
||||||
|
} else if (isOfficial) {
|
||||||
|
"$versionRoot.dev-$shortCommit"
|
||||||
|
} else {
|
||||||
|
"$versionRoot.unofficial-$shortCommit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val embedResources by configurations.registering
|
val embedResources by configurations.registering
|
||||||
|
|
||||||
@@ -50,7 +59,7 @@ dependencies {
|
|||||||
implementation(libs.twelvemonkeys.imageio.webp)
|
implementation(libs.twelvemonkeys.imageio.webp)
|
||||||
implementation(libs.java.info)
|
implementation(libs.java.info)
|
||||||
|
|
||||||
if (launcherExe == null) {
|
if (launcherExe.isBlank()) {
|
||||||
implementation(libs.hmclauncher)
|
implementation(libs.hmclauncher)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +204,7 @@ tasks.shadowJar {
|
|||||||
"Enable-Native-Access" to "ALL-UNNAMED"
|
"Enable-Native-Access" to "ALL-UNNAMED"
|
||||||
)
|
)
|
||||||
|
|
||||||
if (launcherExe != null) {
|
if (launcherExe.isNotBlank()) {
|
||||||
into("assets") {
|
into("assets") {
|
||||||
from(file(launcherExe))
|
from(file(launcherExe))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,14 @@ subprojects {
|
|||||||
name = "libs"
|
name = "libs"
|
||||||
dirs = setOf(rootProject.file("lib"))
|
dirs = setOf(rootProject.file("lib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.getenv("MAVEN_CENTRAL_REPO").let { repo ->
|
||||||
|
if (repo.isNullOrBlank())
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
else
|
||||||
|
maven(url = repo)
|
||||||
|
}
|
||||||
|
|
||||||
maven(url = "https://jitpack.io")
|
maven(url = "https://jitpack.io")
|
||||||
maven(url = "https://libraries.minecraft.net")
|
maven(url = "https://libraries.minecraft.net")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
repositories {
|
repositories {
|
||||||
|
System.getenv("MAVEN_CENTRAL_REPO").let { repo ->
|
||||||
|
if (repo.isNullOrBlank())
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
else
|
||||||
|
maven(url = repo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher
|
||||||
|
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.gradle.ci;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/// @author Glavo
|
||||||
|
public final class GitHubActionUtils {
|
||||||
|
private static final String OFFICIAL_ORGANIZATION = "HMCL-dev";
|
||||||
|
|
||||||
|
public static final boolean IS_ON_OFFICIAL_REPO =
|
||||||
|
OFFICIAL_ORGANIZATION.equalsIgnoreCase(System.getenv("GITHUB_REPOSITORY_OWNER"))
|
||||||
|
&& Objects.requireNonNullElse(System.getenv("GITHUB_BASE_REF"), "").isBlank();
|
||||||
|
|
||||||
|
private GitHubActionUtils() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher
|
||||||
|
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.gradle.ci;
|
||||||
|
|
||||||
|
/// @author Glavo
|
||||||
|
public final class JenkinsUtils {
|
||||||
|
|
||||||
|
public static final boolean IS_ON_CI = "1".equals(System.getenv("HMCL_CI"));
|
||||||
|
|
||||||
|
private JenkinsUtils() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher
|
||||||
|
* Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.gradle.utils;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/// @author Glavo
|
||||||
|
public final class PropertiesUtils {
|
||||||
|
public static @NotNull Properties load(Path path) throws IOException {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
try (var reader = Files.newBufferedReader(path)) {
|
||||||
|
properties.load(reader);
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PropertiesUtils() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
_HMCL_PROJECT_ROOT=$(dirname "${BASH_SOURCE[0]}")
|
|
||||||
|
|
||||||
sed -i 's,//services.gradle.org/distributions/,//mirrors.cloud.tencent.com/gradle/,g' "$_HMCL_PROJECT_ROOT/gradle/wrapper/gradle-wrapper.properties"
|
|
||||||
4
config/jenkins/config-jenkins.sh
Executable file
4
config/jenkins/config-jenkins.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
sed -i 's,//services.gradle.org/distributions/,//mirrors.cloud.tencent.com/gradle/,g' "$PWD/gradle/wrapper/gradle-wrapper.properties"
|
||||||
|
|
||||||
23
config/jenkins/dev/Jenkinsfile
vendored
Normal file
23
config/jenkins/dev/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
environment {
|
||||||
|
HMCL_CI = '1'
|
||||||
|
|
||||||
|
VERSION_TYPE = 'dev'
|
||||||
|
MICROSOFT_AUTH_ID = credentials('microsoft_auth_id')
|
||||||
|
MICROSOFT_AUTH_SECRET = credentials('microsoft_auth_secret')
|
||||||
|
CURSEFORGE_API_KEY = credentials('curseforge_api_key')
|
||||||
|
HMCL_SIGNATURE_KEY = credentials('hmcl_signature_key')
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Build') {
|
||||||
|
steps {
|
||||||
|
sh 'bash ./config/jenkins/config-jenkins.sh'
|
||||||
|
sh './gradlew clean makeExecutables --stacktrace --no-daemon'
|
||||||
|
archiveArtifacts artifacts: 'HMCL/build/libs/*'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
config/jenkins/stable/Jenkinsfile
vendored
Normal file
23
config/jenkins/stable/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
environment {
|
||||||
|
HMCL_CI = '1'
|
||||||
|
|
||||||
|
VERSION_TYPE = 'stable'
|
||||||
|
MICROSOFT_AUTH_ID = credentials('microsoft_auth_id')
|
||||||
|
MICROSOFT_AUTH_SECRET = credentials('microsoft_auth_secret')
|
||||||
|
CURSEFORGE_API_KEY = credentials('curseforge_api_key')
|
||||||
|
HMCL_SIGNATURE_KEY = credentials('hmcl_signature_key')
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Build') {
|
||||||
|
steps {
|
||||||
|
sh 'bash ./config/jenkins/config-jenkins.sh'
|
||||||
|
sh './gradlew clean makeExecutables --stacktrace --no-daemon'
|
||||||
|
archiveArtifacts artifacts: 'HMCL/build/libs/*'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
config/project.properties
Normal file
18
config/project.properties
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#
|
||||||
|
# Hello Minecraft! Launcher
|
||||||
|
# Copyright (C) 2025 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
versionRoot=3.7
|
||||||
Reference in New Issue
Block a user