mirror of
https://github.com/jdx/mise-action.git
synced 2026-05-14 13:50:33 +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
13
dist/index.js
generated
vendored
13
dist/index.js
generated
vendored
|
|
@ -81127,9 +81127,7 @@ async function run() {
|
|||
}
|
||||
async function exportMiseEnv() {
|
||||
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();
|
||||
if (supportsRedacted) {
|
||||
|
|
@ -81356,9 +81354,7 @@ const miseInstall = async () => mise([`install ${core.getInput('install_args')}`
|
|||
const miseLs = async () => mise([`ls`]);
|
||||
const miseReshim = async () => mise([`reshim`, `-f`]);
|
||||
const mise = async (args) => 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[1] !== undefined));
|
||||
const env = core.isDebug()
|
||||
? { ...baseEnv, MISE_LOG_LEVEL: 'debug' }
|
||||
|
|
@ -81378,6 +81374,11 @@ const writeFile = async (p, body) => await core.group(`Writing ${p}`, async () =
|
|||
await fs.promises.writeFile(p, body, { encoding: 'utf8' });
|
||||
});
|
||||
run();
|
||||
function getCwd() {
|
||||
return (core.getInput('working_directory') ||
|
||||
core.getInput('install_dir') ||
|
||||
process.cwd());
|
||||
}
|
||||
function miseDir() {
|
||||
const dir = core.getState('MISE_DIR');
|
||||
if (dir)
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
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