1+ import core from "@actions/core" ;
12import fs from "node:fs/promises" ;
23import path from "node:path" ;
3- import http from "node:http" ;
4- import core from "@actions/core" ;
54import { VersionsManifest } from "./VersionsManifest.js" ;
65
76const GH_INPUTS : Record < string , string > = JSON . parse ( process . env . GH_INPUTS ! ) ;
@@ -30,9 +29,9 @@ if (inputs.name === "")
3029 inputs . name = inputs . version ;
3130
3231if ( inputs . channel === "" ) {
33- if ( / \b a l p h a \b / . test ( inputs . version . toLowerCase ( ) ) )
32+ if ( / \b a l p h a \b / i . test ( inputs . version ) )
3433 inputs . channel = "alpha" ;
35- else if ( / \b ( r c \d * | p r e \d * | b e t a ) \b / . test ( inputs . version . toLowerCase ( ) ) )
34+ else if ( / \b ( r c \d * | p r e \d * | b e t a ) \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
4443core . info ( "Parsing inputs…" ) ;
4544const 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+
4959const dependencies = JSON . parse ( inputs . dependencies ) ;
5060
5161const changelog = inputs . changelog === "" ? null : inputs . changelog ;
@@ -62,7 +72,7 @@ const fileTypesMap: Record<string, string> = {
6272
6373const 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 ( / ^ h t t p s ? : \/ \/ / . 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
135147if ( ! 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