Skip to content

Commit c8050e4

Browse files
authored
Merge pull request #76 from DeLaGuardo/cli/resolve-latest-version
Use stable ClojureCLI version if requested latest
2 parents 05cb4bf + 0a8c186 commit c8050e4

File tree

4 files changed

+63
-26
lines changed

4 files changed

+63
-26
lines changed

__tests__/tdeps.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as _core from '@actions/core'
22
import * as _exec from '@actions/exec'
33
import * as _io from '@actions/io'
44
import * as _tc from '@actions/tool-cache'
5+
import * as _http from '@actions/http-client'
56
import * as _os from 'os'
67
import * as _fs from '../src/fs'
78
import {join} from 'path'
@@ -32,6 +33,20 @@ const fs: jest.Mocked<typeof _fs> = _fs as never
3233
jest.mock('os')
3334
const os: jest.Mocked<typeof _os> = _os as never
3435

36+
jest.mock('@actions/http-client', () => {
37+
return {
38+
HttpClient: jest.fn().mockImplementation(() => {
39+
return {
40+
get: jest.fn().mockImplementation(() => {
41+
return {
42+
readBody: jest.fn().mockResolvedValue('1.2.3 123qwe')
43+
}
44+
})
45+
}
46+
})
47+
}
48+
})
49+
3550
describe('tdeps tests', () => {
3651
beforeAll(async () => {
3752
process.env['RUNNER_TOOL_CACHE'] = toolPath
@@ -90,7 +105,7 @@ describe('tdeps tests', () => {
90105
await tdeps.setup('latest')
91106

92107
expect(tc.downloadTool).toHaveBeenCalledWith(
93-
'https://download.clojure.org/install/linux-install.sh'
108+
'https://download.clojure.org/install/linux-install-1.2.3.sh'
94109
)
95110
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
96111
expect(exec.exec).toHaveBeenCalledWith('bash', [
@@ -101,7 +116,7 @@ describe('tdeps tests', () => {
101116
expect(tc.cacheDir).toHaveBeenCalledWith(
102117
'/tmp/usr/local/opt/ClojureTools',
103118
'ClojureToolsDeps',
104-
`latest.0.0-${VERSION}`
119+
`1.2.3-${VERSION}`
105120
)
106121
expect(core.exportVariable).toHaveBeenCalledWith(
107122
'CLOJURE_INSTALL_DIR',
@@ -124,7 +139,7 @@ describe('tdeps tests', () => {
124139
await tdeps.setup('latest')
125140

126141
expect(tc.downloadTool).toHaveBeenCalledWith(
127-
'https://download.clojure.org/install/linux-install.sh'
142+
'https://download.clojure.org/install/linux-install-1.2.3.sh'
128143
)
129144
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
130145
expect(fs.writeFile).toHaveBeenCalledWith(
@@ -140,7 +155,7 @@ describe('tdeps tests', () => {
140155
expect(tc.cacheDir).toHaveBeenCalledWith(
141156
'/tmp/usr/local/opt/ClojureTools',
142157
'ClojureToolsDeps',
143-
`latest.0.0-${VERSION}`
158+
`1.2.3-${VERSION}`
144159
)
145160
expect(core.exportVariable).toHaveBeenCalledWith(
146161
'CLOJURE_INSTALL_DIR',

dist/index.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,30 @@ const os = __importStar(__nccwpck_require__(2037));
394394
const fs = __importStar(__nccwpck_require__(6078));
395395
const utils = __importStar(__nccwpck_require__(918));
396396
exports.identifier = 'ClojureToolsDeps';
397-
function setup(version, githubToken) {
397+
const client = new http.HttpClient('actions/setup-clojure', undefined, {
398+
allowRetries: true,
399+
maxRetries: 3
400+
});
401+
function toolVersion(version) {
402+
return __awaiter(this, void 0, void 0, function* () {
403+
if (version === 'latest') {
404+
const res = yield client.get('https://download.clojure.org/install/stable.properties');
405+
const versionString = yield res.readBody();
406+
return versionString.split(' ')[0];
407+
}
408+
else {
409+
return version;
410+
}
411+
});
412+
}
413+
function setup(requestedVersion, githubToken) {
398414
return __awaiter(this, void 0, void 0, function* () {
415+
const version = yield toolVersion(requestedVersion);
399416
const installDir = utils.isWindows()
400417
? 'C:\\Program Files\\WindowsPowerShell\\Modules'
401418
: '/tmp/usr/local/opt';
402419
const toolPath = tc.find(exports.identifier, utils.getCacheVersionString(version), os.arch());
403-
if (toolPath && version !== 'latest') {
420+
if (toolPath) {
404421
core.info(`Clojure CLI found in cache ${toolPath}`);
405422
yield fs.mkdir(installDir, { recursive: true });
406423
yield fs.cp(toolPath, path.join(installDir, 'ClojureTools'), {
@@ -409,7 +426,7 @@ function setup(version, githubToken) {
409426
}
410427
else {
411428
if (utils.isWindows()) {
412-
const url = `download.clojure.org/install/win-install${version === 'latest' ? '' : `-${version}`}.ps1`;
429+
const url = `download.clojure.org/install/win-install-${version}.ps1`;
413430
yield exec.exec(`powershell -c "iwr -useb ${url} | iex"`, [], {
414431
// Install to a modules location common to powershell/pwsh
415432
env: { PSModulePath: installDir },
@@ -419,7 +436,7 @@ function setup(version, githubToken) {
419436
yield tc.cacheDir(path.join(installDir, 'ClojureTools'), exports.identifier, utils.getCacheVersionString(version));
420437
}
421438
else {
422-
const clojureInstallScript = yield tc.downloadTool(`https://download.clojure.org/install/linux-install${version === 'latest' ? '' : `-${version}`}.sh`);
439+
const clojureInstallScript = yield tc.downloadTool(`https://download.clojure.org/install/linux-install-${version}.sh`);
423440
if (utils.isMacOS()) {
424441
yield MacOSDeps(clojureInstallScript, githubToken);
425442
}
@@ -457,10 +474,6 @@ function MacOSDeps(file, githubToken) {
457474
function getLatestDepsClj(githubAuth) {
458475
var _a, _b;
459476
return __awaiter(this, void 0, void 0, function* () {
460-
const client = new http.HttpClient('actions/setup-clojure', undefined, {
461-
allowRetries: true,
462-
maxRetries: 3
463-
});
464477
const res = yield client.getJson(`https://api.github.com/repos/borkdude/deps.clj/releases/latest`, githubAuth ? { Authorization: githubAuth } : undefined);
465478
const result = (_b = (_a = res.result) === null || _a === void 0 ? void 0 : _a.tag_name) === null || _b === void 0 ? void 0 : _b.replace(/^v/, '');
466479
if (result) {

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/cli.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,28 @@ import * as utils from './utils'
1010

1111
export const identifier = 'ClojureToolsDeps'
1212

13+
const client = new http.HttpClient('actions/setup-clojure', undefined, {
14+
allowRetries: true,
15+
maxRetries: 3
16+
})
17+
18+
async function toolVersion(version: string): Promise<string> {
19+
if (version === 'latest') {
20+
const res = await client.get(
21+
'https://download.clojure.org/install/stable.properties'
22+
)
23+
const versionString = await res.readBody()
24+
return versionString.split(' ')[0]
25+
} else {
26+
return version
27+
}
28+
}
29+
1330
export async function setup(
14-
version: string,
31+
requestedVersion: string,
1532
githubToken?: string
1633
): Promise<void> {
34+
const version = await toolVersion(requestedVersion)
1735
const installDir = utils.isWindows()
1836
? 'C:\\Program Files\\WindowsPowerShell\\Modules'
1937
: '/tmp/usr/local/opt'
@@ -23,17 +41,15 @@ export async function setup(
2341
os.arch()
2442
)
2543

26-
if (toolPath && version !== 'latest') {
44+
if (toolPath) {
2745
core.info(`Clojure CLI found in cache ${toolPath}`)
2846
await fs.mkdir(installDir, {recursive: true})
2947
await fs.cp(toolPath, path.join(installDir, 'ClojureTools'), {
3048
recursive: true
3149
})
3250
} else {
3351
if (utils.isWindows()) {
34-
const url = `download.clojure.org/install/win-install${
35-
version === 'latest' ? '' : `-${version}`
36-
}.ps1`
52+
const url = `download.clojure.org/install/win-install-${version}.ps1`
3753

3854
await exec.exec(`powershell -c "iwr -useb ${url} | iex"`, [], {
3955
// Install to a modules location common to powershell/pwsh
@@ -54,9 +70,7 @@ export async function setup(
5470
)
5571
} else {
5672
const clojureInstallScript = await tc.downloadTool(
57-
`https://download.clojure.org/install/linux-install${
58-
version === 'latest' ? '' : `-${version}`
59-
}.sh`
73+
`https://download.clojure.org/install/linux-install-${version}.sh`
6074
)
6175

6276
if (utils.isMacOS()) {
@@ -111,11 +125,6 @@ async function MacOSDeps(file: string, githubToken?: string): Promise<void> {
111125
}
112126

113127
export async function getLatestDepsClj(githubAuth?: string): Promise<string> {
114-
const client = new http.HttpClient('actions/setup-clojure', undefined, {
115-
allowRetries: true,
116-
maxRetries: 3
117-
})
118-
119128
const res = await client.getJson<{tag_name: string}>(
120129
`https://api.github.com/repos/borkdude/deps.clj/releases/latest`,
121130
githubAuth ? {Authorization: githubAuth} : undefined

0 commit comments

Comments
 (0)