Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 52 additions & 1 deletion src/main.ts
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a unit test for your desired behavior. also, what should happen when specifying pixi-url and running twice?

Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,68 @@ import * as core from '@actions/core'
import { downloadTool } from '@actions/tool-cache'
import type { PixiSource } from './options'
import { options } from './options'
import { execute, pixiCmd, renderPixiUrl } from './util'
import { execute, executeGetOutput, pixiCmd, renderPixiUrl } from './util'
import { tryRestoreGlobalCache, tryRestoreProjectCache, saveGlobalCache, saveProjectCache } from './cache'
import { activateEnvironment } from './activate'

const fileExists = async (p: string) => {
try {
await fs.access(p)
return true
} catch {
return false
}
}

// Returns the installed version (e.g. "0.67.2") or undefined if the binary
// cannot be executed or the output does not match the expected format.
const readInstalledPixiVersion = async (binPath: string) => {
try {
const { stdout, exitCode } = await executeGetOutput([binPath, '--version'], {
silent: true,
ignoreReturnCode: true
})
if (exitCode !== 0) {
return undefined
}
// `pixi --version` prints something like "pixi 0.67.2"
const match = /\b(\d+\.\d+\.\d+\S*)/.exec(stdout)
return match?.[1]
} catch {
return undefined
}
}

const downloadPixi = async (source: PixiSource) => {
const url = renderPixiUrl(source.urlTemplate, source.version)
await core.group('Downloading Pixi', async () => {
core.debug('Installing pixi')
core.debug(`Downloading pixi from ${url}`)
core.debug(`Using headers: ${JSON.stringify(source.headers)}`)
await fs.mkdir(path.dirname(options.pixiBinPath), { recursive: true })

// If a previous step in this job already installed pixi at the same path,
// @actions/tool-cache's downloadTool will throw "Destination file path
// ... already exists". If the existing binary matches the requested
// version we can safely skip the download; otherwise remove it so the
// download can proceed. See prefix-dev/setup-pixi#107.
if (await fileExists(options.pixiBinPath)) {
if (source.version !== 'latest') {
const installed = await readInstalledPixiVersion(options.pixiBinPath)
const requested = source.version.replace(/^v/, '')
if (installed && installed === requested) {
core.info(`Pixi ${installed} already installed at ${options.pixiBinPath}, skipping download`)
return
}
core.info(
`Replacing existing pixi at ${options.pixiBinPath} (installed: ${installed ?? 'unknown'}, requested: ${requested})`
)
} else {
core.info(`Replacing existing pixi at ${options.pixiBinPath} (requested: latest)`)
}
await fs.rm(options.pixiBinPath, { force: true })
}

await downloadTool(url, options.pixiBinPath, undefined, source.headers)
await fs.chmod(options.pixiBinPath, 0o755)
core.info(`Pixi installed to ${options.pixiBinPath}`)
Expand Down
Loading