import * as path from "path" ; import * as core from "@actions/core" ; import * as types from "../types" ; import * as utils from "../utils" ; import * as conda from "../conda" ; import { miniforgeDownloader } from "./download-miniforge" ; import { minicondaDownloader } from "./download-miniconda" ; import { urlDownloader } from "./download-url" ; import { bundledMinicondaUser } from "./bundled-miniconda" ; /**
 * Providers of `constructor`-compatible installers, ordered roughly by "cost".
 *
 * ### Note
 * To add a new installer,
 * - implement IInstallerProvider and add it here
 * - add to `../../action.yaml`
 * - add any new RULEs in ../input.ts, for example if the installer is not
 *   compatible with some architectures
 * - add a test!
 */ const INSTALLER_PROVIDERS = [ bundledMinicondaUser , urlDownloader , minicondaDownloader , miniforgeDownloader , ] ; /** See if any provider works with the given inputs and options */ export async function getLocalInstallerPath ( inputs , options ) { for ( const provider of INSTALLER_PROVIDERS ) { core . info ( `Can we ${ provider . label }?` ) ; if ( await provider . provides ( inputs , options ) ) { core . info ( `... will ${ provider . label }.` ) ; return provider . installerPath ( inputs , options ) ; } } throw Error ( `No installer could be found for the given inputs` ) ; } param installerPath export async function runInstaller ( installerPath , outputPath , inputs , options ) { const installerExtension = path . extname ( installerPath ) ; let command ; switch ( installerExtension ) { case ".exe" : command = [ `"${ installerPath }" /InstallationType=JustMe /RegisterPython=0 /S /D=${ outputPath }` , ] ; break ; case ".sh" : command = [ "bash" , installerPath , "-f" , "-b" , "-p" , outputPath ] ; break ; default : throw Error ( `Unknown installer extension: ${ installerExtension }` ) ; } await utils . execute ( command ) ; const mambaInInstaller = conda . isMambaInstalled ( options ) ; if ( mambaInInstaller ) { core . info ( "Mamba was found in the `base` env" ) ; options = { ... options , mambaInInstaller , useMamba : mambaInInstaller && inputs . useMamba === "true" , } ; } return options ; }