Skip to content

Commit bc7570e

Browse files
authored
Merge pull request #105 from DeLaGuardo/rate-limit-cli-fix
Fix wrong use of auth token
2 parents 9d39ec9 + f688ff1 commit bc7570e

File tree

8 files changed

+65
-56
lines changed

8 files changed

+65
-56
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
java-version: '8'
4747

4848
- name: Install clojure tools
49-
uses: DeLaGuardo/setup-clojure@12.4
49+
uses: DeLaGuardo/setup-clojure@12.5
5050
with:
5151
# Install just one or all simultaneously
5252
# The value must indicate a particular version of the tool, or use 'latest'

__tests__/entrypoint.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,20 @@ describe('setup-clojure', () => {
7070

7171
it('sets up Clojure CLI tools from deprecated `tools-deps` option', async () => {
7272
inputs['tools-deps'] = '1.2.3'
73+
inputs['github-token'] = 'auth token'
7374

7475
await main()
7576

76-
expect(cli.setup).toHaveBeenCalledWith('1.2.3')
77+
expect(cli.setup).toHaveBeenCalledWith('1.2.3', 'Bearer auth token')
7778
})
7879

7980
it('sets up Clojure CLI tools', async () => {
8081
inputs['cli'] = '1.2.3'
82+
inputs['github-token'] = 'auth token'
8183

8284
await main()
8385

84-
expect(cli.setup).toHaveBeenCalledWith('1.2.3')
86+
expect(cli.setup).toHaveBeenCalledWith('1.2.3', 'Bearer auth token')
8587
})
8688

8789
it('sets up Babashka', async () => {

__tests__/tdeps.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ describe('tdeps tests', () => {
6868
it('Throws if invalid version', async () => {
6969
const msg = 'Unexpected HTTP response: 403'
7070
tc.downloadTool.mockRejectedValueOnce(new Error(msg))
71-
await expect(tdeps.setup('1000')).rejects.toThrow(msg)
71+
await expect(tdeps.setup('1000', 'auth token')).rejects.toThrow(msg)
7272
})
7373

7474
it('Install clojure tools deps with normal version', async () => {
7575
tc.downloadTool.mockResolvedValueOnce(downloadPath)
7676
tc.cacheDir.mockResolvedValueOnce(cachePath)
7777

78-
await tdeps.setup('1.10.1.469')
78+
await tdeps.setup('1.10.1.469', 'auth token')
7979

8080
expect(tc.downloadTool).toHaveBeenCalledWith(
8181
'https://download.clojure.org/install/linux-install-1.10.1.469.sh',
8282
undefined,
83-
undefined
83+
'auth token'
8484
)
8585
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
8686
expect(exec.exec).toHaveBeenCalledWith('bash', [
@@ -106,12 +106,12 @@ describe('tdeps tests', () => {
106106
tc.downloadTool.mockResolvedValueOnce(downloadPath)
107107
tc.cacheDir.mockResolvedValueOnce(cachePath)
108108

109-
await tdeps.setup('latest')
109+
await tdeps.setup('latest', 'auth token')
110110

111111
expect(tc.downloadTool).toHaveBeenCalledWith(
112112
'https://download.clojure.org/install/linux-install-1.2.3.sh',
113113
undefined,
114-
undefined
114+
'auth token'
115115
)
116116
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
117117
expect(exec.exec).toHaveBeenCalledWith('bash', [
@@ -177,7 +177,7 @@ describe('tdeps tests', () => {
177177
it('Uses version of clojure tools-deps installed in cache', async () => {
178178
tc.find.mockReturnValue(cachePath)
179179

180-
await tdeps.setup('1.10.1.469')
180+
await tdeps.setup('1.10.1.469', 'auth token')
181181

182182
expect(core.exportVariable).toHaveBeenCalledWith(
183183
'CLOJURE_INSTALL_DIR',

dist/index.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function toolVersion(version, githubAuth) {
403403
return __awaiter(this, void 0, void 0, function* () {
404404
core.debug('=== Check tool version');
405405
if (version === 'latest') {
406-
const res = yield client.getJson('https://api.github.com/repos/clojure/brew-install/releases/latest', githubAuth ? { Authorization: githubAuth } : undefined);
406+
const res = yield client.getJson('https://api.github.com/repos/clojure/brew-install/releases/latest', { Authorization: githubAuth });
407407
const versionString = (_a = res.result) === null || _a === void 0 ? void 0 : _a.tag_name;
408408
if (versionString) {
409409
return versionString;
@@ -427,7 +427,9 @@ function getUrls(tag, githubAuth) {
427427
var _a;
428428
return __awaiter(this, void 0, void 0, function* () {
429429
core.debug('=== Get download URLs');
430-
const res = yield client.getJson(`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`, githubAuth ? { Authorization: githubAuth } : undefined);
430+
const res = yield client.getJson(`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`, {
431+
Authorization: githubAuth
432+
});
431433
const posix_install_url = `https://github.com/clojure/brew-install/releases/download/${tag}/posix-install.sh`;
432434
const assets = (_a = res.result) === null || _a === void 0 ? void 0 : _a.assets;
433435
if (assets && isResourceProvided(posix_install_url, assets)) {
@@ -445,10 +447,10 @@ function getUrls(tag, githubAuth) {
445447
}
446448
});
447449
}
448-
function setup(requestedVersion, githubToken) {
450+
function setup(requestedVersion, githubAuth) {
449451
return __awaiter(this, void 0, void 0, function* () {
450452
core.debug('=== Run setup');
451-
const version = yield toolVersion(requestedVersion, githubToken);
453+
const version = yield toolVersion(requestedVersion, githubAuth);
452454
const installDir = utils.isWindows()
453455
? 'C:\\Program Files\\WindowsPowerShell\\Modules'
454456
: '/tmp/usr/local/opt';
@@ -461,7 +463,7 @@ function setup(requestedVersion, githubToken) {
461463
});
462464
}
463465
else {
464-
const { linux, posix, windows } = yield getUrls(version, githubToken);
466+
const { linux, posix, windows } = yield getUrls(version, githubAuth);
465467
if (utils.isWindows()) {
466468
yield exec.exec(`powershell -c "iwr -useb ${windows} | iex"`, [], {
467469
// Install to a modules location common to powershell/pwsh
@@ -475,15 +477,15 @@ function setup(requestedVersion, githubToken) {
475477
let clojureInstallScript;
476478
if (utils.isMacOS()) {
477479
if (posix) {
478-
clojureInstallScript = yield tc.downloadTool(posix, undefined, githubToken);
480+
clojureInstallScript = yield tc.downloadTool(posix, undefined, githubAuth);
479481
}
480482
else {
481-
clojureInstallScript = yield tc.downloadTool(linux, undefined, githubToken);
482-
yield MacOSDeps(clojureInstallScript, githubToken);
483+
clojureInstallScript = yield tc.downloadTool(linux, undefined, githubAuth);
484+
yield MacOSDeps(clojureInstallScript, githubAuth);
483485
}
484486
}
485487
else {
486-
clojureInstallScript = yield tc.downloadTool(linux, undefined, githubToken);
488+
clojureInstallScript = yield tc.downloadTool(linux, undefined, githubAuth);
487489
}
488490
const clojureToolsDir = yield runLinuxInstall(clojureInstallScript, path.join(installDir, 'ClojureTools'));
489491
core.debug(`clojure tools deps installed to ${clojureToolsDir}`);
@@ -506,23 +508,26 @@ function runLinuxInstall(installScript, destinationFolder) {
506508
return destinationFolder;
507509
});
508510
}
509-
function MacOSDeps(file, githubToken) {
511+
function MacOSDeps(file, githubAuth) {
510512
return __awaiter(this, void 0, void 0, function* () {
511513
core.debug('=== Install extra deps for MacOS');
512514
const data = yield fs.readFile(file, 'utf-8');
513515
const newValue = data.replace(/install -D/gim, '$(brew --prefix coreutils)/bin/ginstall -D');
514516
yield fs.writeFile(file, newValue, 'utf-8');
515-
const env = githubToken
516-
? { env: { HOMEBREW_GITHUB_API_TOKEN: githubToken.substring(7) } }
517-
: undefined;
518-
yield exec.exec('brew', ['install', 'coreutils'], env);
517+
yield exec.exec('brew', ['install', 'coreutils'], {
518+
env: {
519+
HOMEBREW_GITHUB_API_TOKEN: githubAuth.substring(7),
520+
HOMEBREW_NO_INSTALL_CLEANUP: 'true',
521+
HOME: process.env['HOME'] || ''
522+
}
523+
});
519524
});
520525
}
521526
function getLatestDepsClj(githubAuth) {
522527
var _a, _b;
523528
return __awaiter(this, void 0, void 0, function* () {
524529
core.debug('=== Fetch latest version of deps clj');
525-
const res = yield client.getJson(`https://api.github.com/repos/borkdude/deps.clj/releases/latest`, githubAuth ? { Authorization: githubAuth } : undefined);
530+
const res = yield client.getJson(`https://api.github.com/repos/borkdude/deps.clj/releases/latest`, { Authorization: githubAuth });
526531
const result = (_b = (_a = res.result) === null || _a === void 0 ? void 0 : _a.tag_name) === null || _b === void 0 ? void 0 : _b.replace(/^v/, '');
527532
if (result) {
528533
return result;
@@ -898,8 +903,8 @@ function main() {
898903
try {
899904
const { LEIN_VERSION, BOOT_VERSION, TDEPS_VERSION, CLI_VERSION, BB_VERSION, CLJ_KONDO_VERSION, CLJFMT_VERSION, CLJSTYLE_VERSION, ZPRINT_VERSION } = getTools();
900905
const tools = [];
901-
const githubToken = core.getInput('github-token');
902-
const githubAuth = githubToken ? `Bearer ${githubToken}` : undefined;
906+
const githubToken = core.getInput('github-token', { required: true });
907+
const githubAuth = `Bearer ${githubToken}`;
903908
const IS_WINDOWS = utils.isWindows();
904909
if (LEIN_VERSION) {
905910
tools.push(lein.setup(LEIN_VERSION, githubAuth));
@@ -908,10 +913,10 @@ function main() {
908913
tools.push(boot.setup(BOOT_VERSION, githubAuth));
909914
}
910915
if (CLI_VERSION) {
911-
tools.push(cli.setup(CLI_VERSION));
916+
tools.push(cli.setup(CLI_VERSION, githubAuth));
912917
}
913918
if (TDEPS_VERSION && !CLI_VERSION) {
914-
tools.push(cli.setup(TDEPS_VERSION));
919+
tools.push(cli.setup(TDEPS_VERSION, githubAuth));
915920
}
916921
if (BB_VERSION) {
917922
tools.push(bb.setup(BB_VERSION, githubAuth));
@@ -1327,7 +1332,7 @@ exports.isMacOS = isMacOS;
13271332

13281333
Object.defineProperty(exports, "__esModule", ({ value: true }));
13291334
exports.VERSION = void 0;
1330-
exports.VERSION = '12-4';
1335+
exports.VERSION = '12-5';
13311336

13321337

13331338
/***/ }),

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: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ const client = new http.HttpClient('actions/setup-clojure', undefined, {
1717

1818
async function toolVersion(
1919
version: string,
20-
githubAuth?: string
20+
githubAuth: string
2121
): Promise<string> {
2222
core.debug('=== Check tool version')
2323
if (version === 'latest') {
2424
const res = await client.getJson<{tag_name: string}>(
2525
'https://api.github.com/repos/clojure/brew-install/releases/latest',
26-
githubAuth ? {Authorization: githubAuth} : undefined
26+
{Authorization: githubAuth}
2727
)
2828
const versionString = res.result?.tag_name
2929
if (versionString) {
@@ -50,15 +50,14 @@ function isResourceProvided(
5050

5151
async function getUrls(
5252
tag: string,
53-
githubAuth?: string
53+
githubAuth: string
5454
): Promise<{posix?: string; linux: string; windows: string}> {
5555
core.debug('=== Get download URLs')
5656
const res = await client.getJson<{
5757
assets: {browser_download_url: string}[]
58-
}>(
59-
`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`,
60-
githubAuth ? {Authorization: githubAuth} : undefined
61-
)
58+
}>(`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`, {
59+
Authorization: githubAuth
60+
})
6261
const posix_install_url = `https://github.com/clojure/brew-install/releases/download/${tag}/posix-install.sh`
6362

6463
const assets = res.result?.assets
@@ -78,10 +77,10 @@ async function getUrls(
7877

7978
export async function setup(
8079
requestedVersion: string,
81-
githubToken?: string
80+
githubAuth: string
8281
): Promise<void> {
8382
core.debug('=== Run setup')
84-
const version = await toolVersion(requestedVersion, githubToken)
83+
const version = await toolVersion(requestedVersion, githubAuth)
8584
const installDir = utils.isWindows()
8685
? 'C:\\Program Files\\WindowsPowerShell\\Modules'
8786
: '/tmp/usr/local/opt'
@@ -98,7 +97,7 @@ export async function setup(
9897
recursive: true
9998
})
10099
} else {
101-
const {linux, posix, windows} = await getUrls(version, githubToken)
100+
const {linux, posix, windows} = await getUrls(version, githubAuth)
102101

103102
if (utils.isWindows()) {
104103
await exec.exec(`powershell -c "iwr -useb ${windows} | iex"`, [], {
@@ -126,21 +125,21 @@ export async function setup(
126125
clojureInstallScript = await tc.downloadTool(
127126
posix,
128127
undefined,
129-
githubToken
128+
githubAuth
130129
)
131130
} else {
132131
clojureInstallScript = await tc.downloadTool(
133132
linux,
134133
undefined,
135-
githubToken
134+
githubAuth
136135
)
137-
await MacOSDeps(clojureInstallScript, githubToken)
136+
await MacOSDeps(clojureInstallScript, githubAuth)
138137
}
139138
} else {
140139
clojureInstallScript = await tc.downloadTool(
141140
linux,
142141
undefined,
143-
githubToken
142+
githubAuth
144143
)
145144
}
146145

@@ -179,25 +178,28 @@ async function runLinuxInstall(
179178
return destinationFolder
180179
}
181180

182-
async function MacOSDeps(file: string, githubToken?: string): Promise<void> {
181+
async function MacOSDeps(file: string, githubAuth: string): Promise<void> {
183182
core.debug('=== Install extra deps for MacOS')
184183
const data = await fs.readFile(file, 'utf-8')
185184
const newValue = data.replace(
186185
/install -D/gim,
187186
'$(brew --prefix coreutils)/bin/ginstall -D'
188187
)
189188
await fs.writeFile(file, newValue, 'utf-8')
190-
const env = githubToken
191-
? {env: {HOMEBREW_GITHUB_API_TOKEN: githubToken.substring(7)}}
192-
: undefined
193-
await exec.exec('brew', ['install', 'coreutils'], env)
189+
await exec.exec('brew', ['install', 'coreutils'], {
190+
env: {
191+
HOMEBREW_GITHUB_API_TOKEN: githubAuth.substring(7),
192+
HOMEBREW_NO_INSTALL_CLEANUP: 'true',
193+
HOME: process.env['HOME'] || ''
194+
}
195+
})
194196
}
195197

196-
export async function getLatestDepsClj(githubAuth?: string): Promise<string> {
198+
export async function getLatestDepsClj(githubAuth: string): Promise<string> {
197199
core.debug('=== Fetch latest version of deps clj')
198200
const res = await client.getJson<{tag_name: string}>(
199201
`https://api.github.com/repos/borkdude/deps.clj/releases/latest`,
200-
githubAuth ? {Authorization: githubAuth} : undefined
202+
{Authorization: githubAuth}
201203
)
202204

203205
const result = res.result?.tag_name?.replace(/^v/, '')

src/entrypoint.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export async function main(): Promise<void> {
2626

2727
const tools = []
2828

29-
const githubToken = core.getInput('github-token')
30-
const githubAuth = githubToken ? `Bearer ${githubToken}` : undefined
29+
const githubToken = core.getInput('github-token', {required: true})
30+
const githubAuth = `Bearer ${githubToken}`
3131
const IS_WINDOWS = utils.isWindows()
3232

3333
if (LEIN_VERSION) {
@@ -39,11 +39,11 @@ export async function main(): Promise<void> {
3939
}
4040

4141
if (CLI_VERSION) {
42-
tools.push(cli.setup(CLI_VERSION))
42+
tools.push(cli.setup(CLI_VERSION, githubAuth))
4343
}
4444

4545
if (TDEPS_VERSION && !CLI_VERSION) {
46-
tools.push(cli.setup(TDEPS_VERSION))
46+
tools.push(cli.setup(TDEPS_VERSION, githubAuth))
4747
}
4848

4949
if (BB_VERSION) {

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = '12-4'
1+
export const VERSION = '12-5'

0 commit comments

Comments
 (0)