Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Commit 7b9c49b

Browse files
committed
refactor getChocoPath
1 parent 0ab446a commit 7b9c49b

File tree

2 files changed

+34
-42
lines changed

2 files changed

+34
-42
lines changed

dist/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11078,12 +11078,7 @@ async function isInstalled(tool, version, os) {
1107811078
const ghcupPath = `${process.env.HOME}/.ghcup${tool === 'ghc' ? `/ghc/${version}` : ''}/bin`;
1107911079
const v = tool === 'cabal' ? version.slice(0, 3) : version;
1108011080
const aptPath = `/opt/${tool}/${v}/bin`;
11081-
const chocoPathArray = version.split('.');
11082-
const chocoPathVersion = chocoPathArray.length > 3
11083-
? chocoPathArray.slice(0, chocoPathArray.length - 1).join('.')
11084-
: chocoPathArray.join('.');
11085-
const chocoPath = path_1.join(`${process.env.ChocolateyInstall}`, 'lib', `${tool}.${version}`, 'tools', tool === 'ghc' ? `${tool}-${chocoPathVersion}` : `${tool}-${version}`, // choco trims the ghc version here
11086-
tool === 'ghc' ? 'bin' : '');
11081+
const chocoPath = getChocoPath(tool, version);
1108711082
const locations = {
1108811083
stack: [],
1108911084
cabal: {
@@ -11188,14 +11183,8 @@ async function choco(tool, version) {
1118811183
], {
1118911184
ignoreReturnCode: true
1119011185
});
11191-
// Manually add the path because it won't happen until the end of the step normally
11192-
const pathArray = version.split('.');
11193-
const pathVersion = pathArray.length > 3
11194-
? pathArray.slice(0, pathArray.length - 1).join('.')
11195-
: pathArray.join('.');
11196-
const chocoPath = path_1.join(`${process.env.ChocolateyInstall}`, 'lib', `${tool}.${version}`, 'tools', tool === 'ghc' ? `${tool}-${pathVersion}` : `${tool}-${version}`, // choco trims the ghc version here
11197-
tool === 'ghc' ? 'bin' : '');
11198-
core.addPath(chocoPath);
11186+
// Add to path automatically because it does not add until the end of the step.
11187+
core.addPath(getChocoPath(tool, version));
1119911188
}
1120011189
async function ghcupBin(os) {
1120111190
const v = '0.1.8';
@@ -11215,6 +11204,16 @@ async function ghcup(tool, version, os) {
1121511204
if (returnCode === 0 && tool === 'ghc')
1121611205
await exec_1.exec(bin, ['set', version]);
1121711206
}
11207+
function getChocoPath(tool, version) {
11208+
// Manually add the path because it won't happen until the end of the step normally
11209+
const pathArray = version.split('.');
11210+
const pathVersion = pathArray.length > 3
11211+
? pathArray.slice(0, pathArray.length - 1).join('.')
11212+
: pathArray.join('.');
11213+
const chocoPath = path_1.join(`${process.env.ChocolateyInstall}`, 'lib', `${tool}.${version}`, 'tools', tool === 'ghc' ? `${tool}-${pathVersion}` : `${tool}-${version}`, // choco trims the ghc version here
11214+
tool === 'ghc' ? 'bin' : '');
11215+
return chocoPath;
11216+
}
1121811217

1121911218

1122011219
/***/ }),

src/installer.ts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,7 @@ async function isInstalled(
5656
const v = tool === 'cabal' ? version.slice(0, 3) : version;
5757
const aptPath = `/opt/${tool}/${v}/bin`;
5858

59-
const chocoPathArray = version.split('.');
60-
const chocoPathVersion =
61-
chocoPathArray.length > 3
62-
? chocoPathArray.slice(0, chocoPathArray.length - 1).join('.')
63-
: chocoPathArray.join('.');
64-
const chocoPath = join(
65-
`${process.env.ChocolateyInstall}`,
66-
'lib',
67-
`${tool}.${version}`,
68-
'tools',
69-
tool === 'ghc' ? `${tool}-${chocoPathVersion}` : `${tool}-${version}`, // choco trims the ghc version here
70-
tool === 'ghc' ? 'bin' : ''
71-
);
59+
const chocoPath = getChocoPath(tool, version);
7260

7361
const locations = {
7462
stack: [], // Always installed into the tool cache
@@ -191,21 +179,8 @@ async function choco(tool: Tool, version: string): Promise<void> {
191179
ignoreReturnCode: true
192180
}
193181
);
194-
// Manually add the path because it won't happen until the end of the step normally
195-
const pathArray = version.split('.');
196-
const pathVersion =
197-
pathArray.length > 3
198-
? pathArray.slice(0, pathArray.length - 1).join('.')
199-
: pathArray.join('.');
200-
const chocoPath = join(
201-
`${process.env.ChocolateyInstall}`,
202-
'lib',
203-
`${tool}.${version}`,
204-
'tools',
205-
tool === 'ghc' ? `${tool}-${pathVersion}` : `${tool}-${version}`, // choco trims the ghc version here
206-
tool === 'ghc' ? 'bin' : ''
207-
);
208-
core.addPath(chocoPath);
182+
// Add to path automatically because it does not add until the end of the step.
183+
core.addPath(getChocoPath(tool, version));
209184
}
210185

211186
async function ghcupBin(os: OS): Promise<string> {
@@ -234,3 +209,21 @@ async function ghcup(tool: Tool, version: string, os: OS): Promise<void> {
234209
);
235210
if (returnCode === 0 && tool === 'ghc') await exec(bin, ['set', version]);
236211
}
212+
213+
function getChocoPath(tool: Tool, version: string): string {
214+
// Manually add the path because it won't happen until the end of the step normally
215+
const pathArray = version.split('.');
216+
const pathVersion =
217+
pathArray.length > 3
218+
? pathArray.slice(0, pathArray.length - 1).join('.')
219+
: pathArray.join('.');
220+
const chocoPath = join(
221+
`${process.env.ChocolateyInstall}`,
222+
'lib',
223+
`${tool}.${version}`,
224+
'tools',
225+
tool === 'ghc' ? `${tool}-${pathVersion}` : `${tool}-${version}`, // choco trims the ghc version here
226+
tool === 'ghc' ? 'bin' : ''
227+
);
228+
return chocoPath;
229+
}

0 commit comments

Comments
 (0)