import * as fs from "fs" ; import * as core from "@actions/core" ; import * as tc from "@actions/tool-cache" ; import getHrefs from "get-hrefs" ; import * as types from "../types" ; import * as constants from "../constants" ; import * as base from "./base" ; param arch async function minicondaVersions ( arch ) { try { let extension = constants . IS_UNIX ? "sh" : "exe" ; const downloadPath = await tc . downloadTool ( constants . MINICONDA_BASE_URL ) ; const content = fs . readFileSync ( downloadPath , "utf8" ) ; let hrefs = getHrefs ( content ) ; hrefs = hrefs . filter ( ( item ) => item . startsWith ( "/Miniconda3" ) ) ; hrefs = hrefs . filter ( ( item ) => item . endsWith ( `${ arch }.${ extension }` ) ) ; hrefs = hrefs . map ( ( item ) => item . substring ( 1 ) ) ; return hrefs ; } catch ( err ) { core . warning ( err ) ; return [ ] ; } } param pythonMajorVersion param minicondaVersion param architecture export async function downloadMiniconda ( pythonMajorVersion , inputs ) { const arch = constants . MINICONDA_ARCHITECTURES [ inputs . architecture ] ; if ( ! arch ) { throw new Error ( `Invalid arch "${ inputs . architecture }"!` ) ; } let extension = constants . IS_UNIX ? "sh" : "exe" ; let osName = constants . OS_NAMES [ process . platform ] ; const minicondaInstallerName = `Miniconda${ pythonMajorVersion }-${ inputs . minicondaVersion }-${ osName }-${ arch }.${ extension }` ; core . info ( minicondaInstallerName ) ; let versions = await minicondaVersions ( arch ) ; if ( versions ) { if ( ! versions . includes ( minicondaInstallerName ) ) { throw new Error ( `Invalid miniconda version!\n\nMust be among ${ versions . toString ( ) }` ) ; } } return await base . ensureLocalInstaller ( { url : constants . MINICONDA_BASE_URL + minicondaInstallerName , tool : `Miniconda${ pythonMajorVersion }` , version : inputs . minicondaVersion , arch : arch , } ) ; } /**
 * Provide a path to a Miniconda downloaded from repo.anaconda.com.
 *
 * ### Note
 * Uses the well-known structure of the repo.anaconda.com to resolve and download
 * a particular Miniconda installer.
 */ export const minicondaDownloader = { label : "download Miniconda" , provides : async ( inputs , options ) => { return inputs . minicondaVersion !== "" && inputs . installerUrl === "" ; } , installerPath : async ( inputs , options ) => { return { localInstallerPath : await downloadMiniconda ( 3 , inputs ) , options : { ... options , useBundled : false , } , } ; } , } ;