Skip to content

Commit c87c81a

Browse files
Big-Iron-CheemsWide-Cat
authored andcommitted
Fix GitHub Actions mc version property read
1 parent 76d5063 commit c87c81a

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

.github/builds/mc_version.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@
44
*/
55

66
import * as fs from "fs"
7-
import * as readline from "readline"
7+
import * as path from "path"
8+
import {fileURLToPath} from "url"
89

9-
export async function getMcVersion() {
10-
let lines = readline.createInterface({
11-
input: fs.createReadStream("../../gradle.properties"),
12-
crlfDelay: Infinity
13-
})
10+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1411

15-
let mcVersion = ""
12+
export async function getMcVersion() {
13+
const filePath = path.resolve(__dirname, "../../gradle/libs.versions.toml")
1614

17-
for await (const line of lines) {
18-
if (line.startsWith("minecraft_version")) {
19-
mcVersion = line.substring(line.indexOf("=") + 1)
20-
break
21-
}
15+
if (!fs.existsSync(filePath)) {
16+
throw new Error(`File not found: ${filePath}`)
2217
}
2318

24-
if (mcVersion === "") {
25-
console.log("Failed to read minecraft_version")
26-
process.exit(1)
27-
}
19+
const content = await fs.promises.readFile(filePath, "utf-8")
20+
21+
const match = content.match(/^\s*minecraft\s*=\s*["']([^"']+)["']\s*$/m)
22+
if (match) return match[1].trim()
2823

29-
return mcVersion
24+
throw new Error(`Failed to find minecraft version in ${filePath}`)
3025
}

0 commit comments

Comments
 (0)