Skip to content

Commit 892e248

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/types/node-22.15.34
2 parents 57be141 + bb4f90c commit 892e248

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/VersionsManifest.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import http from "node:http";
2-
31
export class VersionsManifest {
42
public static MOJANG_VERSIONS_MANIFEST_URL = "https://launchermeta.mojang.com/mc/game/version_manifest.json";
53

@@ -8,7 +6,8 @@ export class VersionsManifest {
86

97
static async fetch() {
108
const res = await fetch(VersionsManifest.MOJANG_VERSIONS_MANIFEST_URL);
11-
if (!res.ok) throw new Error(`Failed to load Mojang versions manifest: ${res.status} (${http.STATUS_CODES[res.status] ?? "unknown"})`);
9+
if (!res.ok) throw new Error("Failed to load Mojang versions manifest: "
10+
+ res.status + res.statusText !== "" ? ` (${res.statusText})` : "");
1211
const json: {versions: {id: string, type: string}[]} = await res.json();
1312
return new VersionsManifest(json.versions
1413
.filter(v => v.type === "release")

src/index.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import core from "@actions/core";
12
import fs from "node:fs/promises";
23
import path from "node:path";
3-
import http from "node:http";
4-
import core from "@actions/core";
54
import {VersionsManifest} from "./VersionsManifest.js";
65

76
const GH_INPUTS: Record<string, string> = JSON.parse(process.env.GH_INPUTS!);
@@ -30,9 +29,9 @@ if (inputs.name === "")
3029
inputs.name = inputs.version;
3130

3231
if (inputs.channel === "") {
33-
if (/\balpha\b/.test(inputs.version.toLowerCase()))
32+
if (/\balpha\b/i.test(inputs.version))
3433
inputs.channel = "alpha";
35-
else if (/\b(rc\d*|pre\d*|beta)\b/.test(inputs.version.toLowerCase()))
34+
else if (/\b(rc\d*|pre\d*|beta)\b/i.test(inputs.version))
3635
inputs.channel = "beta";
3736
else inputs.channel = "release";
3837
}
@@ -43,9 +42,20 @@ if (inputs.featured === "")
4342
// Parse inputs
4443
core.info("Parsing inputs…");
4544
const featured = inputs.featured === "true";
46-
const loaders = inputs.loaders.startsWith("[") ? JSON.parse(inputs.loaders) : inputs.loaders.split("\n").map(l => l.trim());
47-
const gameVersions = (inputs.gameVersions.startsWith("[") ? JSON.parse(inputs.gameVersions) as string[] : inputs.gameVersions.split("\n").map(l => l.trim())).map(v => v.trim()).filter(v => v !== "");
48-
const filePaths = inputs.files.startsWith("[") ? JSON.parse(inputs.files) as string[] : inputs.files.split("\n").map(l => l.trim());
45+
46+
const loaders = inputs.loaders.startsWith("[")
47+
? JSON.parse(inputs.loaders)
48+
: inputs.loaders.split("\n").map(l => l.trim());
49+
50+
const gameVersions = (inputs.gameVersions.startsWith("[")
51+
? JSON.parse(inputs.gameVersions) as string[]
52+
: inputs.gameVersions.split("\n").map(l => l.trim()))
53+
.map(v => v.trim()).filter(v => v !== "");
54+
55+
const filePaths = inputs.files.startsWith("[")
56+
? JSON.parse(inputs.files) as string[]
57+
: inputs.files.split("\n").map(l => l.trim());
58+
4959
const dependencies = JSON.parse(inputs.dependencies);
5060

5161
const changelog = inputs.changelog === "" ? null : inputs.changelog;
@@ -62,7 +72,7 @@ const fileTypesMap: Record<string, string> = {
6272

6373
const files = await Promise.all(filePaths.map(async filePath => {
6474
const type = fileTypesMap[path.extname(filePath)];
65-
// Check if the path is an url
75+
// Check if the path is a URL
6676
if (/^https?:\/\//.test(filePath)) {
6777
const url = new URL(filePath);
6878
const res = await fetch(url);
@@ -88,7 +98,9 @@ if (gameVersions.some(v => /^\d+\.\d+\.x$/i.test(v))) {
8898
for (const version of gameVersions.filter(v => /^\d+\.\d+\.x$/i.test(v))) {
8999
const index = gameVersions.indexOf(version);
90100
const baseVersion = version.slice(0, -2);
91-
const versions = versionsManifest.versions.filter(v => v === baseVersion || v.startsWith(baseVersion + "."));
101+
const versions = versionsManifest.versions.filter(v =>
102+
v === baseVersion || v.startsWith(baseVersion + ".")
103+
);
92104
gameVersions.splice(index, 1, ...versions);
93105
}
94106
}
@@ -133,7 +145,9 @@ catch (err) {
133145
}
134146

135147
if (!res.ok) {
136-
core.setFailed(`Modrinth API returned error status ${res.status} (${http.STATUS_CODES[res.status] ?? "unknown"}): ${typeof parsedBody === "string" ? parsedBody : JSON.stringify(parsedBody, null, 2)}`);
148+
core.setFailed("Modrinth API returned error status"
149+
+ res.status + (res.statusText !== "" ? ` (${res.statusText})` : "") + ": "
150+
+ typeof parsedBody === "string" ? parsedBody : JSON.stringify(parsedBody, null, 2));
137151
process.exit(1);
138152
}
139153

0 commit comments

Comments
 (0)