Skip to content

Commit

Permalink
Set LEIN_JAR env
Browse files Browse the repository at this point in the history
  • Loading branch information
DeLaGuardo committed Feb 9, 2024
1 parent 5c0b89a commit 8832931
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/lein_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: env
- run: DEBUG=true lein -v
- run: unset LEIN_JAR
- run: DEBUG=true lein -v
32 changes: 27 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
var _a;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.mkdir = exports.cp = exports.writeFile = exports.readFile = exports.chmod = exports.stat = void 0;
exports.readdir = exports.mkdir = exports.cp = exports.writeFile = exports.readFile = exports.chmod = exports.stat = void 0;
const fs_1 = __importDefault(__nccwpck_require__(7147));
_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;
_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;


/***/ }),
Expand Down Expand Up @@ -1148,6 +1148,10 @@ function setup(version, githubAuth) {
core.debug(`Leiningen installed to ${leiningenDir}`);
toolPath = yield tc.cacheDir(leiningenDir, exports.identifier, utils.getCacheVersionString(version));
}
const leiningenJarPath = yield leiningenJar(toolPath);
if (leiningenJarPath !== null) {
core.exportVariable('LEIN_JAR', leiningenJarPath);
}
core.exportVariable('LEIN_HOME', toolPath);
core.addPath(path.join(toolPath, 'bin'));
});
Expand Down Expand Up @@ -1175,20 +1179,38 @@ function installLeiningen(binScripts, destinationFolder) {
const version_cmd = isWindows
? 'powershell .\\lein.ps1 self-install'
: './lein version';
const toolDir = path.join(destinationFolder, 'leiningen');
const leiningenJarPath = yield leiningenJar(toolDir);
const env = {
LEIN_HOME: path.join(destinationFolder, 'leiningen')
LEIN_HOME: toolDir
};
if (leiningenJarPath !== null) {
env['LEIN_JAR'] = leiningenJarPath;
}
if (process.env['PATH']) {
env['PATH'] = process.env['PATH'];
}
if (process.env['JAVA_CMD']) {
env['JAVA_CMD'] = process.env['JAVA_CMD'];
}
yield exec.exec(version_cmd, [], {
cwd: path.join(destinationFolder, 'leiningen', 'bin'),
cwd: path.join(toolDir, 'bin'),
env
});
return path.join(destinationFolder, 'leiningen');
return toolDir;
});
}
function leiningenJar(toolPath) {
return __awaiter(this, void 0, void 0, function* () {
const files = yield fs.readdir(path.join(toolPath, 'self-installs'));
if (files) {
for (const file of files) {
if (file.endsWith('.jar')) {
return path.join(toolPath, 'self-installs', file);
}
}
}
return null;
});
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/fs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs'

export const {stat, chmod, readFile, writeFile, cp, mkdir} = fs.promises
export const {stat, chmod, readFile, writeFile, cp, mkdir, readdir} =
fs.promises
32 changes: 29 additions & 3 deletions src/leiningen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export async function setup(
)
}

const leiningenJarPath = await leiningenJar(toolPath)

if (leiningenJarPath !== null) {
core.exportVariable('LEIN_JAR', leiningenJarPath)
}

core.exportVariable('LEIN_HOME', toolPath)
core.addPath(path.join(toolPath, 'bin'))
}
Expand Down Expand Up @@ -96,8 +102,15 @@ async function installLeiningen(
? 'powershell .\\lein.ps1 self-install'
: './lein version'

const toolDir = path.join(destinationFolder, 'leiningen')
const leiningenJarPath = await leiningenJar(toolDir)

const env: {[key: string]: string} = {
LEIN_HOME: path.join(destinationFolder, 'leiningen')
LEIN_HOME: toolDir
}

if (leiningenJarPath !== null) {
env['LEIN_JAR'] = leiningenJarPath
}

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

await exec.exec(version_cmd, [], {
cwd: path.join(destinationFolder, 'leiningen', 'bin'),
cwd: path.join(toolDir, 'bin'),
env
})

return path.join(destinationFolder, 'leiningen')
return toolDir
}

async function leiningenJar(toolPath: string): Promise<string | null> {
const files = await fs.readdir(path.join(toolPath, 'self-installs'))
if (files) {
for (const file of files) {
if (file.endsWith('.jar')) {
return path.join(toolPath, 'self-installs', file)
}
}
}

return null
}

0 comments on commit 8832931

Please sign in to comment.