更新 Jenkins CI 链接 (#4584)

This commit is contained in:
Glavo
2025-10-02 21:57:44 +08:00
committed by GitHub
parent 5abc1f1f9d
commit 8731faaac7
3 changed files with 63 additions and 44 deletions

View File

@@ -2,8 +2,8 @@ name: Check Update
on: on:
workflow_dispatch: workflow_dispatch:
schedule: # schedule:
- cron: '30 * * * *' # - cron: '30 * * * *'
permissions: permissions:
contents: write contents: write
@@ -28,14 +28,12 @@ jobs:
- name: Download artifacts - name: Download artifacts
if: ${{ env.continue == 'true' }} if: ${{ env.continue == 'true' }}
run: | run: |
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.exe" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.exe"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.exe.sha256" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.exe.sha256"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.jar" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.jar"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.jar.sha256" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.jar.sha256"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.sh" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.sh"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.sh.sha256" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.sh.sha256"
env:
DOWNLOAD_BASE_URL: https://ci.huangyuhui.net/job/HMCL/lastSuccessfulBuild/artifact/HMCL/build/libs
- name: Generate release note - name: Generate release note
if: ${{ env.continue == 'true' }} if: ${{ env.continue == 'true' }}
run: | run: |
@@ -84,14 +82,12 @@ jobs:
- name: Download artifacts - name: Download artifacts
if: ${{ env.continue == 'true' }} if: ${{ env.continue == 'true' }}
run: | run: |
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.exe" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.exe"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.exe.sha256" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.exe.sha256"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.jar" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.jar"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.jar.sha256" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.jar.sha256"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.sh" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.sh"
wget "$DOWNLOAD_BASE_URL/HMCL-$HMCL_VERSION.sh.sha256" wget "$HMCL_CI_DOWNLOAD_BASE_URI/HMCL-$HMCL_VERSION.sh.sha256"
env:
DOWNLOAD_BASE_URL: https://ci.huangyuhui.net/job/HMCL-stable/lastSuccessfulBuild/artifact/HMCL/build/libs
- name: Generate release note - name: Generate release note
if: ${{ env.continue == 'true' }} if: ${{ env.continue == 'true' }}
run: | run: |
@@ -103,9 +99,9 @@ jobs:
echo "" >> RELEASE_NOTE echo "" >> RELEASE_NOTE
echo "| File Name | SHA-256 Checksum |" >> RELEASE_NOTE echo "| File Name | SHA-256 Checksum |" >> RELEASE_NOTE
echo "| --- | --- |" >> RELEASE_NOTE echo "| --- | --- |" >> RELEASE_NOTE
echo "| [HMCL-$HMCL_VERSION.exe]($GH_DOWNLOAD_BASE_URL/release-$HMCL_VERSION/HMCL-$HMCL_VERSION.exe) | \`$(cat HMCL-$HMCL_VERSION.exe.sha256)\` |" >> RELEASE_NOTE echo "| [HMCL-$HMCL_VERSION.exe]($GH_DOWNLOAD_BASE_URL/v$HMCL_VERSION/HMCL-$HMCL_VERSION.exe) | \`$(cat HMCL-$HMCL_VERSION.exe.sha256)\` |" >> RELEASE_NOTE
echo "| [HMCL-$HMCL_VERSION.jar]($GH_DOWNLOAD_BASE_URL/release-$HMCL_VERSION/HMCL-$HMCL_VERSION.jar) | \`$(cat HMCL-$HMCL_VERSION.jar.sha256)\` |" >> RELEASE_NOTE echo "| [HMCL-$HMCL_VERSION.jar]($GH_DOWNLOAD_BASE_URL/v$HMCL_VERSION/HMCL-$HMCL_VERSION.jar) | \`$(cat HMCL-$HMCL_VERSION.jar.sha256)\` |" >> RELEASE_NOTE
echo "| [HMCL-$HMCL_VERSION.sh]($GH_DOWNLOAD_BASE_URL/release-$HMCL_VERSION/HMCL-$HMCL_VERSION.sh) | \`$(cat HMCL-$HMCL_VERSION.sh.sha256)\` |" >> RELEASE_NOTE echo "| [HMCL-$HMCL_VERSION.sh]($GH_DOWNLOAD_BASE_URL/v$HMCL_VERSION/HMCL-$HMCL_VERSION.sh) | \`$(cat HMCL-$HMCL_VERSION.sh.sha256)\` |" >> RELEASE_NOTE
env: env:
GH_DOWNLOAD_BASE_URL: https://github.com/HMCL-dev/HMCL/releases/download GH_DOWNLOAD_BASE_URL: https://github.com/HMCL-dev/HMCL/releases/download
- name: Create release - name: Create release
@@ -120,3 +116,4 @@ jobs:
target_commitish: ${{ env.HMCL_COMMIT_SHA }} target_commitish: ${{ env.HMCL_COMMIT_SHA }}
name: ${{ env.HMCL_TAG_NAME }} name: ${{ env.HMCL_TAG_NAME }}
tag_name: ${{ env.HMCL_TAG_NAME }} tag_name: ${{ env.HMCL_TAG_NAME }}
prerelease: true

View File

@@ -77,11 +77,9 @@ tasks.register<UpdateDocuments>("updateDocuments") {
} }
tasks.register<CheckUpdate>("checkUpdateDev") { tasks.register<CheckUpdate>("checkUpdateDev") {
tagPrefix.set("v") uri.set("https://ci.huangyuhui.net/job/HMCL-nightly")
uri.set("https://ci.huangyuhui.net/job/HMCL")
} }
tasks.register<CheckUpdate>("checkUpdateStable") { tasks.register<CheckUpdate>("checkUpdateStable") {
tagPrefix.set("release-")
uri.set("https://ci.huangyuhui.net/job/HMCL-stable") uri.set("https://ci.huangyuhui.net/job/HMCL-stable")
} }

View File

@@ -55,9 +55,6 @@ public abstract class CheckUpdate extends DefaultTask {
@Input @Input
public abstract Property<String> getUri(); public abstract Property<String> getUri();
@Input
public abstract Property<String> getTagPrefix();
public CheckUpdate() { public CheckUpdate() {
getOutputs().upToDateWhen(task -> false); getOutputs().upToDateWhen(task -> false);
} }
@@ -69,10 +66,21 @@ public abstract class CheckUpdate extends DefaultTask {
); );
} }
private static String concatUri(String base, String... others) {
var builder = new StringBuilder(base);
for (String other : others) {
if (builder.charAt(builder.length() - 1) != '/') {
builder.append('/');
}
builder.append(Objects.requireNonNull(other));
}
return builder.toString();
}
@TaskAction @TaskAction
public void run() throws Exception { public void run() throws Exception {
String uri = getUri().get(); String uri = getUri().get();
URI apiUri = toURI(uri, "api/json"); URI apiUri = URI.create(concatUri(uri, "api", "json"));
LOGGER.quiet("Fetching metadata from {}", apiUri); LOGGER.quiet("Fetching metadata from {}", apiUri);
BuildMetadata buildMetadata; BuildMetadata buildMetadata;
@@ -93,19 +101,19 @@ public abstract class CheckUpdate extends DefaultTask {
.filter(it -> !it.color().equals("disabled")) .filter(it -> !it.color().equals("disabled"))
.map(it -> { .map(it -> {
try { try {
return fetchBuildInfo(helper, toURI(it.url, "lastSuccessfulBuild/api/json")); return fetchBuildInfo(helper, it.url);
} catch (Throwable e) { } catch (Throwable e) {
throw new GradleException("Failed to retrieve build info from " + it.url(), e); throw new GradleException("Failed to fetch build info from " + it.url(), e);
} }
}).sorted(Comparator.comparing(BuildMetadata::timestamp)) }).sorted(Comparator.comparing(BuildMetadata::timestamp))
.toList(); .toList();
if (metadatas.isEmpty()) if (metadatas.isEmpty())
throw new GradleException("Failed to retrieve build metadata from " + apiUri); throw new GradleException("Failed to fetch build metadata from " + apiUri);
buildMetadata = metadatas.get(metadatas.size() - 1); buildMetadata = metadatas.get(metadatas.size() - 1);
} else if (WORKFLOW_JOB.equals(jobType) || FREE_STYLE_PROJECT.equals(jobType)) { } else if (WORKFLOW_JOB.equals(jobType) || FREE_STYLE_PROJECT.equals(jobType)) {
buildMetadata = fetchBuildInfo(helper, toURI(uri, "lastSuccessfulBuild/api/json")); buildMetadata = fetchBuildInfo(helper, uri);
} else { } else {
throw new GradleException("Unsupported job type: " + jobType); throw new GradleException("Unsupported job type: " + jobType);
} }
@@ -130,14 +138,17 @@ public abstract class CheckUpdate extends DefaultTask {
addEnv.accept("HMCL_COMMIT_SHA", buildMetadata.revision()); addEnv.accept("HMCL_COMMIT_SHA", buildMetadata.revision());
addEnv.accept("HMCL_VERSION", buildMetadata.version()); addEnv.accept("HMCL_VERSION", buildMetadata.version());
addEnv.accept("HMCL_TAG_NAME", getTagPrefix().get() + buildMetadata.version()); addEnv.accept("HMCL_TAG_NAME", "v" + buildMetadata.version());
addEnv.accept("HMCL_CI_DOWNLOAD_BASE_URI", buildMetadata.downloadBaseUri);
} }
} }
private record BuildMetadata(String version, String revision, long timestamp) { private record BuildMetadata(String version, String revision, long timestamp, String downloadBaseUri) {
} }
private BuildMetadata fetchBuildInfo(Helper helper, URI uri) throws IOException, InterruptedException { private BuildMetadata fetchBuildInfo(Helper helper, String jobUri) throws IOException, InterruptedException {
URI uri = URI.create(concatUri(jobUri, "lastSuccessfulBuild", "api", "json"));
LOGGER.quiet("Fetching build info from {}", uri); LOGGER.quiet("Fetching build info from {}", uri);
BuildInfo buildInfo = Objects.requireNonNull(helper.fetch(uri, BuildInfo.class), "build info"); BuildInfo buildInfo = Objects.requireNonNull(helper.fetch(uri, BuildInfo.class), "build info");
@@ -153,16 +164,28 @@ public abstract class CheckUpdate extends DefaultTask {
throw new GradleException("Invalid revision: " + revision); throw new GradleException("Invalid revision: " + revision);
Pattern fileNamePattern = Pattern.compile("HMCL-(?<version>\\d+(?:\\.\\d+)+)\\.jar"); Pattern fileNamePattern = Pattern.compile("HMCL-(?<version>\\d+(?:\\.\\d+)+)\\.jar");
String version = Objects.requireNonNullElse(buildInfo.artifacts(), List.<ArtifactInfo>of()) ArtifactInfo jarArtifact = Objects.requireNonNullElse(buildInfo.artifacts(), List.<ArtifactInfo>of()).stream()
.stream() .filter(it -> fileNamePattern.matcher(it.fileName()).matches())
.map(ArtifactInfo::fileName)
.map(fileNamePattern::matcher)
.filter(Matcher::matches)
.map(matcher -> matcher.group("version"))
.findFirst() .findFirst()
.orElseThrow(() -> new GradleException("Could not find .jar artifact")); .orElseThrow(() -> new GradleException("Could not find .jar artifact"));
return new BuildMetadata(version, revision, buildInfo.timestamp()); String fileName = jarArtifact.fileName();
String relativePath = jarArtifact.relativePath();
if (!relativePath.endsWith("/" + fileName)) {
throw new GradleException("Invalid artifact relative path: " + jarArtifact);
}
Matcher matcher = fileNamePattern.matcher(fileName);
if (!matcher.matches()) {
throw new AssertionError("Artifact: " + jarArtifact.fileName());
}
String version = matcher.group("version");
String downloadBaseUrl = concatUri(buildInfo.url(), "artifact",
relativePath.substring(0, relativePath.length() - fileName.length() - 1));
return new BuildMetadata(version, revision, buildInfo.timestamp(), downloadBaseUrl);
} }
private static final class Helper implements AutoCloseable { private static final class Helper implements AutoCloseable {
@@ -193,14 +216,15 @@ public abstract class CheckUpdate extends DefaultTask {
} }
private record BuildInfo(long number, private record BuildInfo(String url,
long number,
long timestamp, long timestamp,
List<ArtifactInfo> artifacts, List<ArtifactInfo> artifacts,
List<ActionInfo> actions List<ActionInfo> actions
) { ) {
} }
record ArtifactInfo(String fileName) { record ArtifactInfo(String fileName, String relativePath) {
} }
record ActionInfo(String _class, BuiltRevision lastBuiltRevision) { record ActionInfo(String _class, BuiltRevision lastBuiltRevision) {