Skip to content

Commit e481863

Browse files
authored
fix(setup): use sudo for package install in CI environments (#220)
1 parent 261d2a7 commit e481863

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/toolbox/system/packages.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Dependency } from './types'
2-
import { pkexec } from '../system/exec'
2+
import { pkexec, execWithSudo } from '../system/exec'
33
import { system } from 'gluegun'
44
import type { Result } from '../../types'
55
import { failure, wrapAsync } from './errors'
@@ -44,11 +44,19 @@ export async function installPackages(packages: Dependency[]): Promise<Result<vo
4444
const packageManager = system.which('apt')
4545

4646
if (packageManager !== null && packageManager !== undefined) {
47-
const result = await pkexec(
48-
`${packageManager} install --yes ${packages.map((p) => p.packageName).join(' ')}`,
49-
{ stdout: process.stdout },
50-
)
51-
return result
47+
if (typeof process.env.CI !== 'undefined' && process.env.CI !== 'false') {
48+
const result = await execWithSudo(
49+
`${packageManager} install --yes ${packages.map((p) => p.packageName).join(' ')}`,
50+
{ stdout: process.stdout },
51+
)
52+
return result
53+
} else {
54+
const result = await pkexec(
55+
`${packageManager} install --yes ${packages.map((p) => p.packageName).join(' ')}`,
56+
{ stdout: process.stdout },
57+
)
58+
return result
59+
}
5260
} else {
5361
return failure(
5462
`xs-dev attempted to install dependencies, but does not yet support your package manager. ` +

0 commit comments

Comments
 (0)