Skip to content

Commit 8832931

Browse files
committed
Set LEIN_JAR env
1 parent 5c0b89a commit 8832931

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

.github/workflows/lein_test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@ jobs:
1919
github-token: ${{ secrets.GITHUB_TOKEN }}
2020
- run: env
2121
- run: DEBUG=true lein -v
22-
- run: unset LEIN_JAR
23-
- run: DEBUG=true lein -v

dist/index.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10711071
};
10721072
var _a;
10731073
Object.defineProperty(exports, "__esModule", ({ value: true }));
1074-
exports.mkdir = exports.cp = exports.writeFile = exports.readFile = exports.chmod = exports.stat = void 0;
1074+
exports.readdir = exports.mkdir = exports.cp = exports.writeFile = exports.readFile = exports.chmod = exports.stat = void 0;
10751075
const fs_1 = __importDefault(__nccwpck_require__(7147));
1076-
_a = fs_1.default.promises, exports.stat = _a.stat, exports.chmod = _a.chmod, exports.readFile = _a.readFile, exports.writeFile = _a.writeFile, exports.cp = _a.cp, exports.mkdir = _a.mkdir;
1076+
_a = fs_1.default.promises, exports.stat = _a.stat, exports.chmod = _a.chmod, exports.readFile = _a.readFile, exports.writeFile = _a.writeFile, exports.cp = _a.cp, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir;
10771077

10781078

10791079
/***/ }),
@@ -1148,6 +1148,10 @@ function setup(version, githubAuth) {
11481148
core.debug(`Leiningen installed to ${leiningenDir}`);
11491149
toolPath = yield tc.cacheDir(leiningenDir, exports.identifier, utils.getCacheVersionString(version));
11501150
}
1151+
const leiningenJarPath = yield leiningenJar(toolPath);
1152+
if (leiningenJarPath !== null) {
1153+
core.exportVariable('LEIN_JAR', leiningenJarPath);
1154+
}
11511155
core.exportVariable('LEIN_HOME', toolPath);
11521156
core.addPath(path.join(toolPath, 'bin'));
11531157
});
@@ -1175,20 +1179,38 @@ function installLeiningen(binScripts, destinationFolder) {
11751179
const version_cmd = isWindows
11761180
? 'powershell .\\lein.ps1 self-install'
11771181
: './lein version';
1182+
const toolDir = path.join(destinationFolder, 'leiningen');
1183+
const leiningenJarPath = yield leiningenJar(toolDir);
11781184
const env = {
1179-
LEIN_HOME: path.join(destinationFolder, 'leiningen')
1185+
LEIN_HOME: toolDir
11801186
};
1187+
if (leiningenJarPath !== null) {
1188+
env['LEIN_JAR'] = leiningenJarPath;
1189+
}
11811190
if (process.env['PATH']) {
11821191
env['PATH'] = process.env['PATH'];
11831192
}
11841193
if (process.env['JAVA_CMD']) {
11851194
env['JAVA_CMD'] = process.env['JAVA_CMD'];
11861195
}
11871196
yield exec.exec(version_cmd, [], {
1188-
cwd: path.join(destinationFolder, 'leiningen', 'bin'),
1197+
cwd: path.join(toolDir, 'bin'),
11891198
env
11901199
});
1191-
return path.join(destinationFolder, 'leiningen');
1200+
return toolDir;
1201+
});
1202+
}
1203+
function leiningenJar(toolPath) {
1204+
return __awaiter(this, void 0, void 0, function* () {
1205+
const files = yield fs.readdir(path.join(toolPath, 'self-installs'));
1206+
if (files) {
1207+
for (const file of files) {
1208+
if (file.endsWith('.jar')) {
1209+
return path.join(toolPath, 'self-installs', file);
1210+
}
1211+
}
1212+
}
1213+
return null;
11921214
});
11931215
}
11941216

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import fs from 'fs'
22

3-
export const {stat, chmod, readFile, writeFile, cp, mkdir} = fs.promises
3+
export const {stat, chmod, readFile, writeFile, cp, mkdir, readdir} =
4+
fs.promises

src/leiningen.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ export async function setup(
6262
)
6363
}
6464

65+
const leiningenJarPath = await leiningenJar(toolPath)
66+
67+
if (leiningenJarPath !== null) {
68+
core.exportVariable('LEIN_JAR', leiningenJarPath)
69+
}
70+
6571
core.exportVariable('LEIN_HOME', toolPath)
6672
core.addPath(path.join(toolPath, 'bin'))
6773
}
@@ -96,8 +102,15 @@ async function installLeiningen(
96102
? 'powershell .\\lein.ps1 self-install'
97103
: './lein version'
98104

105+
const toolDir = path.join(destinationFolder, 'leiningen')
106+
const leiningenJarPath = await leiningenJar(toolDir)
107+
99108
const env: {[key: string]: string} = {
100-
LEIN_HOME: path.join(destinationFolder, 'leiningen')
109+
LEIN_HOME: toolDir
110+
}
111+
112+
if (leiningenJarPath !== null) {
113+
env['LEIN_JAR'] = leiningenJarPath
101114
}
102115

103116
if (process.env['PATH']) {
@@ -108,9 +121,22 @@ async function installLeiningen(
108121
}
109122

110123
await exec.exec(version_cmd, [], {
111-
cwd: path.join(destinationFolder, 'leiningen', 'bin'),
124+
cwd: path.join(toolDir, 'bin'),
112125
env
113126
})
114127

115-
return path.join(destinationFolder, 'leiningen')
128+
return toolDir
129+
}
130+
131+
async function leiningenJar(toolPath: string): Promise<string | null> {
132+
const files = await fs.readdir(path.join(toolPath, 'self-installs'))
133+
if (files) {
134+
for (const file of files) {
135+
if (file.endsWith('.jar')) {
136+
return path.join(toolPath, 'self-installs', file)
137+
}
138+
}
139+
}
140+
141+
return null
116142
}

0 commit comments

Comments
 (0)