Skip to content
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
# - `vendor/bin/deployer.phar`
# - `vendor/bin/dep`
# - `deployer.phar`
# If the binary not found, phar version will be downloaded from
# - `vendor/bin/dep` in Composer's global home
# If the binary is not found, phar version will be downloaded from
# deployer.org.
# Optional.
deployer-version: '7.0.0'
Expand Down
35 changes: 26 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36630,6 +36630,21 @@ var import_build = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((expo
})))(), 1);
var { VERSION, YAML, argv, dotenv, echo, expBackoff, fetch, fs, glob, globby, minimist, nothrow, parseArgv, question, quiet, retry, sleep, spinner, stdin, tempdir, tempfile, tmpdir, tmpfile, updateArgv, version, versions, $, Fail, ProcessOutput, ProcessPromise, bus, cd, chalk, defaults, kill, log, os: os$1, path, ps, quote, quotePowerShell, resolveDefaults, syncProcessCwd, useBash, usePowerShell, usePwsh, which, within } = globalThis.Deno ? globalThis.require("./index.cjs") : import_build;
//#endregion
//#region src/deployerBinary.ts
var PROJECT_LOCAL_DEPLOYER_BINARIES = [
"vendor/bin/deployer.phar",
"vendor/bin/dep",
"deployer.phar"
];
async function findLocalDeployerBinary({ fs, getComposerGlobalHome }) {
for (const candidate of PROJECT_LOCAL_DEPLOYER_BINARIES) if (fs.existsSync(candidate)) return candidate;
const composerGlobalHome = (await getComposerGlobalHome?.())?.trim();
if (composerGlobalHome === void 0 || composerGlobalHome === "") return "";
const composerGlobalDep = `${composerGlobalHome.replace(/\/+$/, "")}/vendor/bin/dep`;
if (fs.existsSync(composerGlobalDep)) return composerGlobalDep;
return "";
}
//#endregion
//#region src/index.ts
$.verbose = true;
(async function main() {
Expand Down Expand Up @@ -36674,15 +36689,17 @@ async function dep() {
const subDirectory = getInput("sub-directory").trim();
if (subDirectory !== "") cd(subDirectory);
if (bin === "") {
for (const c of [
"vendor/bin/deployer.phar",
"vendor/bin/dep",
"deployer.phar"
]) if (fs.existsSync(c)) {
bin = c;
console.log(`Using "${c}".`);
break;
}
bin = await findLocalDeployerBinary({
fs,
getComposerGlobalHome: async () => {
try {
return (await $`composer -n config --global home`).stdout.trim();
} catch {
return;
}
}
});
if (bin !== "") console.log(`Using "${bin}".`);
}
if (bin === "") {
let version = getInput("deployer-version");
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"scripts": {
"build": "vite build",
"test": "node --test test/*.test.mjs",
"typecheck": "tsc --noEmit",
"format": "prettier --write .",
"format:check": "prettier --check ."
Expand Down
37 changes: 37 additions & 0 deletions src/deployerBinary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
interface FileSystemLike {
existsSync(path: string): boolean
}

export interface FindLocalDeployerBinaryOptions {
fs: FileSystemLike
getComposerGlobalHome?: () => Promise<string | undefined>
}

const PROJECT_LOCAL_DEPLOYER_BINARIES = [
'vendor/bin/deployer.phar',
'vendor/bin/dep',
'deployer.phar',
]

export async function findLocalDeployerBinary({
fs,
getComposerGlobalHome,
}: FindLocalDeployerBinaryOptions): Promise<string> {
for (const candidate of PROJECT_LOCAL_DEPLOYER_BINARIES) {
if (fs.existsSync(candidate)) {
return candidate
}
}

const composerGlobalHome = (await getComposerGlobalHome?.())?.trim()
if (composerGlobalHome === undefined || composerGlobalHome === '') {
return ''
}

const composerGlobalDep = `${composerGlobalHome.replace(/\/+$/, '')}/vendor/bin/dep`
if (fs.existsSync(composerGlobalDep)) {
return composerGlobalDep
}
Comment on lines +26 to +34

return ''
}
23 changes: 13 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core'
import { $, fs, cd } from 'zx'
import { findLocalDeployerBinary } from './deployerBinary'

$.verbose = true

Expand Down Expand Up @@ -71,16 +72,18 @@ async function dep(): Promise<void> {
}

if (bin === '') {
for (const c of [
'vendor/bin/deployer.phar',
'vendor/bin/dep',
'deployer.phar',
]) {
if (fs.existsSync(c)) {
bin = c
console.log(`Using "${c}".`)
break
}
bin = await findLocalDeployerBinary({
fs,
getComposerGlobalHome: async () => {
try {
return (await $`composer -n config --global home`).stdout.trim()
} catch {
return undefined
}
},
})
if (bin !== '') {
console.log(`Using "${bin}".`)
}
}

Expand Down
53 changes: 53 additions & 0 deletions test/deployer-binary.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { findLocalDeployerBinary } from '../src/deployerBinary.ts'
Comment on lines +1 to +3

function fakeFs(existingPaths) {
const existing = new Set(existingPaths)
return {
existsSync(path) {
return existing.has(path)
},
}
}

test('finds composer global dep when no project-local deployer binary exists', async () => {
const bin = await findLocalDeployerBinary({
fs: fakeFs(['/tmp/composer-home/vendor/bin/dep']),
getComposerGlobalHome: async () => '/tmp/composer-home',
})

assert.equal(bin, '/tmp/composer-home/vendor/bin/dep')
})

test('prefers project-local deployer binary over composer global dep', async () => {
const bin = await findLocalDeployerBinary({
fs: fakeFs(['vendor/bin/dep', '/tmp/composer-home/vendor/bin/dep']),
getComposerGlobalHome: async () => '/tmp/composer-home',
})

assert.equal(bin, 'vendor/bin/dep')
})

test('trims trailing slashes from composer global home before checking dep path', async () => {
const bin = await findLocalDeployerBinary({
fs: fakeFs(['/tmp/composer-home/vendor/bin/dep']),
getComposerGlobalHome: async () => '/tmp/composer-home///',
})

assert.equal(bin, '/tmp/composer-home/vendor/bin/dep')
})

test('ignores missing or empty composer global home', async () => {
const missingHome = await findLocalDeployerBinary({
fs: fakeFs([]),
getComposerGlobalHome: async () => '',
})
const failedCommand = await findLocalDeployerBinary({
fs: fakeFs([]),
getComposerGlobalHome: async () => undefined,
})

assert.equal(missingHome, '')
assert.equal(failedCommand, '')
})