fix: do not fallback to latest apt package by default

This commit is contained in:
Amin Yahyaabadi 2025-01-29 00:56:32 -08:00
parent 12e62a1b8d
commit d58ee0edd1
7 changed files with 15 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "setup-apt",
"version": "2.1.0",
"version": "3.0.0",
"description": "Setup apt packages and repositories in Debian/Ubuntu-based distributions",
"repository": "https://github.com/aminya/setup-cpp",
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/setup-apt",

View File

@ -34,6 +34,11 @@ export type AptPackage = {
repository?: string
/** The key to add before installing the package (optional) */
key?: AddAptKeyOptions
/**
* If the given version is not available, fall back to the latest version
* @default false
*/
fallBackToLatest?: boolean
}
const retryErrors = [

View File

@ -32,7 +32,7 @@ export async function filterAndQualifyAptPackages(packages: AptPackage[], apt: s
*/
export async function qualifiedNeededAptPackage(pack: AptPackage, apt: string = getApt()) {
// Qualify the package into full package name/version
const qualified = await getAptArg(apt, pack.name, pack.version)
const qualified = await getAptArg(apt, pack)
// filter out the package that are already installed
return (await isAptPackInstalled(qualified)) ? undefined : qualified
}
@ -78,7 +78,9 @@ async function aptPackageType(apt: string, name: string, version: string | undef
return AptPackageType.None
}
async function getAptArg(apt: string, name: string, version: string | undefined) {
async function getAptArg(apt: string, pack: AptPackage) {
const { name, version, fallBackToLatest = false } = pack
const package_type = await aptPackageType(apt, name, version)
switch (package_type) {
case AptPackageType.NameDashVersion:
@ -86,7 +88,7 @@ async function getAptArg(apt: string, name: string, version: string | undefined)
case AptPackageType.NameEqualsVersion:
return `${name}=${version}`
case AptPackageType.Name:
if (version !== undefined && version !== "") {
if (version !== undefined && version !== "" && fallBackToLatest) {
warning(`Could not find package ${name} with version ${version}. Installing the latest version.`)
}
return name