mirror of
https://github.com/jdx/mise-action.git
synced 2026-05-19 07:51:53 +00:00
refactor: extract getCwd() helper to deduplicate working directory resolution (#403)
## Summary
- Extracts the duplicated working-directory resolution expression
(`core.getInput('working_directory') || core.getInput('install_dir') ||
process.cwd()`) into a `getCwd()` helper function.
- Replaces the 2 identical inline expressions in `exportMiseEnv()` and
`mise()` with calls to `getCwd()`.
## Motivation
Separated from #402 to allow independent review. This is a pure refactor
with no behavioral change, intended to simplify the diff in #402 by
providing a smaller, self-contained improvement.
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
c5b2043e51
commit
abadabdb1f
3 changed files with 18 additions and 15 deletions
18
src/index.ts
18
src/index.ts
|
|
@ -82,10 +82,7 @@ async function run(): Promise<void> {
|
|||
async function exportMiseEnv(): Promise<void> {
|
||||
core.startGroup('Exporting mise environment variables')
|
||||
|
||||
const cwd =
|
||||
core.getInput('working_directory') ||
|
||||
core.getInput('install_dir') ||
|
||||
process.cwd()
|
||||
const cwd = getCwd()
|
||||
|
||||
// Check if mise supports --redacted flags based on version input
|
||||
const supportsRedacted = checkMiseSupportsRedacted()
|
||||
|
|
@ -356,10 +353,7 @@ const miseLs = async (): Promise<number> => mise([`ls`])
|
|||
const miseReshim = async (): Promise<number> => mise([`reshim`, `-f`])
|
||||
const mise = async (args: string[]): Promise<number> =>
|
||||
await core.group(`Running mise ${args.join(' ')}`, async () => {
|
||||
const cwd =
|
||||
core.getInput('working_directory') ||
|
||||
core.getInput('install_dir') ||
|
||||
process.cwd()
|
||||
const cwd = getCwd()
|
||||
const baseEnv = Object.fromEntries(
|
||||
Object.entries(process.env).filter(
|
||||
(entry): entry is [string, string] => entry[1] !== undefined
|
||||
|
|
@ -387,6 +381,14 @@ const writeFile = async (p: fs.PathLike, body: string): Promise<void> =>
|
|||
|
||||
run()
|
||||
|
||||
function getCwd(): string {
|
||||
return (
|
||||
core.getInput('working_directory') ||
|
||||
core.getInput('install_dir') ||
|
||||
process.cwd()
|
||||
)
|
||||
}
|
||||
|
||||
function miseDir(): string {
|
||||
const dir = core.getState('MISE_DIR')
|
||||
if (dir) return dir
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue