11import { info } from "console"
2+ import { tmpdir } from "os"
3+ import { join } from "path"
4+ import { HttpClient } from "@actions/http-client"
25import { execRoot } from "admina"
36import { addPath } from "envosman"
4- import { execa } from "execa"
5- import { chmod , readFile , writeFile } from "fs/promises"
7+ import { chmod , writeFile } from "fs/promises"
68import { aptTimeout , hasNala , installAptPack , isAptPackRegexInstalled } from "setup-apt"
79import { rcOptions } from "../cli-options.js"
810import { DEFAULT_TIMEOUT } from "../installTool.js"
@@ -21,14 +23,26 @@ export async function setupLLVMApt(
2123 // TODO for older versions, this also includes the minor version
2224 const installationFolder = `/usr/lib/llvm-${ majorVersion } `
2325
24- await installAptPack ( [ { name : "curl" } ] )
25- await execa ( "curl" , [ "-LJO" , "https://apt.llvm.org/llvm.sh" ] , { cwd : "/tmp" } )
26- const neededPackages = await patchAptLLVMScript ( "/tmp/llvm.sh" , "/tmp/llvm-setup-cpp.sh" , majorVersion , packages )
26+ // download the installation script
27+ const http = new HttpClient ( "setup-llvm" )
28+ const response = await http . get ( "https://apt.llvm.org/llvm.sh" )
29+ if ( response . message . statusCode !== 200 ) {
30+ throw new Error ( `Failed to download LLVM installation script: ${ response . message . statusCode } ` )
31+ }
32+ const installerScript = await response . readBody ( )
33+
34+ const installerPath = join ( tmpdir ( ) , "llvm-setup-cpp.sh" )
35+ const neededPackages = await patchAptLLVMScript (
36+ installerScript ,
37+ installerPath ,
38+ majorVersion ,
39+ packages ,
40+ )
2741 await installAptPack ( neededPackages )
28- await chmod ( "/tmp/llvm-setup-cpp.sh" , "755" )
42+ await chmod ( installerPath , "755" )
2943 await execRoot (
3044 "bash" ,
31- [ "/tmp/llvm-setup-cpp.sh" , `${ majorVersion } ` , ...( packages === LLVMPackages . All ? [ "all" ] : [ ] ) ] ,
45+ [ installerPath , `${ majorVersion } ` , ...( packages === LLVMPackages . All ? [ "all" ] : [ ] ) ] ,
3246 {
3347 stdio : "inherit" ,
3448 shell : true ,
@@ -45,10 +59,13 @@ export async function setupLLVMApt(
4559 }
4660}
4761
48- async function patchAptLLVMScript ( path : string , target_path : string , majorVersion : number , packages : LLVMPackages ) {
49- let script = await readFile ( path , "utf-8" )
50-
51- script = debugScript ( script )
62+ async function patchAptLLVMScript (
63+ givenScript : string ,
64+ target_path : string ,
65+ majorVersion : number ,
66+ packages : LLVMPackages ,
67+ ) {
68+ let script = debugScript ( givenScript )
5269 script = nonInteractiveScript ( script )
5370 script = choosePackages ( packages , script , majorVersion )
5471 script = await removeConflictingPackages ( script )
0 commit comments