Fix wrong use of auth token

This commit is contained in:
Kirill Chernyshov 2024-02-11 19:11:08 +01:00
parent 9d39ec9ed1
commit f688ff1e1e
No known key found for this signature in database
GPG Key ID: 83C196363AF97C4C
8 changed files with 65 additions and 56 deletions

View File

@ -46,7 +46,7 @@ jobs:
java-version: '8'
- name: Install clojure tools
uses: DeLaGuardo/setup-clojure@12.4
uses: DeLaGuardo/setup-clojure@12.5
with:
# Install just one or all simultaneously
# The value must indicate a particular version of the tool, or use 'latest'

View File

@ -70,18 +70,20 @@ describe('setup-clojure', () => {
it('sets up Clojure CLI tools from deprecated `tools-deps` option', async () => {
inputs['tools-deps'] = '1.2.3'
inputs['github-token'] = 'auth token'
await main()
expect(cli.setup).toHaveBeenCalledWith('1.2.3')
expect(cli.setup).toHaveBeenCalledWith('1.2.3', 'Bearer auth token')
})
it('sets up Clojure CLI tools', async () => {
inputs['cli'] = '1.2.3'
inputs['github-token'] = 'auth token'
await main()
expect(cli.setup).toHaveBeenCalledWith('1.2.3')
expect(cli.setup).toHaveBeenCalledWith('1.2.3', 'Bearer auth token')
})
it('sets up Babashka', async () => {

View File

@ -68,19 +68,19 @@ describe('tdeps tests', () => {
it('Throws if invalid version', async () => {
const msg = 'Unexpected HTTP response: 403'
tc.downloadTool.mockRejectedValueOnce(new Error(msg))
await expect(tdeps.setup('1000')).rejects.toThrow(msg)
await expect(tdeps.setup('1000', 'auth token')).rejects.toThrow(msg)
})
it('Install clojure tools deps with normal version', async () => {
tc.downloadTool.mockResolvedValueOnce(downloadPath)
tc.cacheDir.mockResolvedValueOnce(cachePath)
await tdeps.setup('1.10.1.469')
await tdeps.setup('1.10.1.469', 'auth token')
expect(tc.downloadTool).toHaveBeenCalledWith(
'https://download.clojure.org/install/linux-install-1.10.1.469.sh',
undefined,
undefined
'auth token'
)
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
expect(exec.exec).toHaveBeenCalledWith('bash', [
@ -106,12 +106,12 @@ describe('tdeps tests', () => {
tc.downloadTool.mockResolvedValueOnce(downloadPath)
tc.cacheDir.mockResolvedValueOnce(cachePath)
await tdeps.setup('latest')
await tdeps.setup('latest', 'auth token')
expect(tc.downloadTool).toHaveBeenCalledWith(
'https://download.clojure.org/install/linux-install-1.2.3.sh',
undefined,
undefined
'auth token'
)
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
expect(exec.exec).toHaveBeenCalledWith('bash', [
@ -177,7 +177,7 @@ describe('tdeps tests', () => {
it('Uses version of clojure tools-deps installed in cache', async () => {
tc.find.mockReturnValue(cachePath)
await tdeps.setup('1.10.1.469')
await tdeps.setup('1.10.1.469', 'auth token')
expect(core.exportVariable).toHaveBeenCalledWith(
'CLOJURE_INSTALL_DIR',

45
dist/index.js vendored
View File

@ -403,7 +403,7 @@ function toolVersion(version, githubAuth) {
return __awaiter(this, void 0, void 0, function* () {
core.debug('=== Check tool version');
if (version === 'latest') {
const res = yield client.getJson('https://api.github.com/repos/clojure/brew-install/releases/latest', githubAuth ? { Authorization: githubAuth } : undefined);
const res = yield client.getJson('https://api.github.com/repos/clojure/brew-install/releases/latest', { Authorization: githubAuth });
const versionString = (_a = res.result) === null || _a === void 0 ? void 0 : _a.tag_name;
if (versionString) {
return versionString;
@ -427,7 +427,9 @@ function getUrls(tag, githubAuth) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
core.debug('=== Get download URLs');
const res = yield client.getJson(`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`, githubAuth ? { Authorization: githubAuth } : undefined);
const res = yield client.getJson(`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`, {
Authorization: githubAuth
});
const posix_install_url = `https://github.com/clojure/brew-install/releases/download/${tag}/posix-install.sh`;
const assets = (_a = res.result) === null || _a === void 0 ? void 0 : _a.assets;
if (assets && isResourceProvided(posix_install_url, assets)) {
@ -445,10 +447,10 @@ function getUrls(tag, githubAuth) {
}
});
}
function setup(requestedVersion, githubToken) {
function setup(requestedVersion, githubAuth) {
return __awaiter(this, void 0, void 0, function* () {
core.debug('=== Run setup');
const version = yield toolVersion(requestedVersion, githubToken);
const version = yield toolVersion(requestedVersion, githubAuth);
const installDir = utils.isWindows()
? 'C:\\Program Files\\WindowsPowerShell\\Modules'
: '/tmp/usr/local/opt';
@ -461,7 +463,7 @@ function setup(requestedVersion, githubToken) {
});
}
else {
const { linux, posix, windows } = yield getUrls(version, githubToken);
const { linux, posix, windows } = yield getUrls(version, githubAuth);
if (utils.isWindows()) {
yield exec.exec(`powershell -c "iwr -useb ${windows} | iex"`, [], {
// Install to a modules location common to powershell/pwsh
@ -475,15 +477,15 @@ function setup(requestedVersion, githubToken) {
let clojureInstallScript;
if (utils.isMacOS()) {
if (posix) {
clojureInstallScript = yield tc.downloadTool(posix, undefined, githubToken);
clojureInstallScript = yield tc.downloadTool(posix, undefined, githubAuth);
}
else {
clojureInstallScript = yield tc.downloadTool(linux, undefined, githubToken);
yield MacOSDeps(clojureInstallScript, githubToken);
clojureInstallScript = yield tc.downloadTool(linux, undefined, githubAuth);
yield MacOSDeps(clojureInstallScript, githubAuth);
}
}
else {
clojureInstallScript = yield tc.downloadTool(linux, undefined, githubToken);
clojureInstallScript = yield tc.downloadTool(linux, undefined, githubAuth);
}
const clojureToolsDir = yield runLinuxInstall(clojureInstallScript, path.join(installDir, 'ClojureTools'));
core.debug(`clojure tools deps installed to ${clojureToolsDir}`);
@ -506,23 +508,26 @@ function runLinuxInstall(installScript, destinationFolder) {
return destinationFolder;
});
}
function MacOSDeps(file, githubToken) {
function MacOSDeps(file, githubAuth) {
return __awaiter(this, void 0, void 0, function* () {
core.debug('=== Install extra deps for MacOS');
const data = yield fs.readFile(file, 'utf-8');
const newValue = data.replace(/install -D/gim, '$(brew --prefix coreutils)/bin/ginstall -D');
yield fs.writeFile(file, newValue, 'utf-8');
const env = githubToken
? { env: { HOMEBREW_GITHUB_API_TOKEN: githubToken.substring(7) } }
: undefined;
yield exec.exec('brew', ['install', 'coreutils'], env);
yield exec.exec('brew', ['install', 'coreutils'], {
env: {
HOMEBREW_GITHUB_API_TOKEN: githubAuth.substring(7),
HOMEBREW_NO_INSTALL_CLEANUP: 'true',
HOME: process.env['HOME'] || ''
}
});
});
}
function getLatestDepsClj(githubAuth) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
core.debug('=== Fetch latest version of deps clj');
const res = yield client.getJson(`https://api.github.com/repos/borkdude/deps.clj/releases/latest`, githubAuth ? { Authorization: githubAuth } : undefined);
const res = yield client.getJson(`https://api.github.com/repos/borkdude/deps.clj/releases/latest`, { Authorization: githubAuth });
const result = (_b = (_a = res.result) === null || _a === void 0 ? void 0 : _a.tag_name) === null || _b === void 0 ? void 0 : _b.replace(/^v/, '');
if (result) {
return result;
@ -898,8 +903,8 @@ function main() {
try {
const { LEIN_VERSION, BOOT_VERSION, TDEPS_VERSION, CLI_VERSION, BB_VERSION, CLJ_KONDO_VERSION, CLJFMT_VERSION, CLJSTYLE_VERSION, ZPRINT_VERSION } = getTools();
const tools = [];
const githubToken = core.getInput('github-token');
const githubAuth = githubToken ? `Bearer ${githubToken}` : undefined;
const githubToken = core.getInput('github-token', { required: true });
const githubAuth = `Bearer ${githubToken}`;
const IS_WINDOWS = utils.isWindows();
if (LEIN_VERSION) {
tools.push(lein.setup(LEIN_VERSION, githubAuth));
@ -908,10 +913,10 @@ function main() {
tools.push(boot.setup(BOOT_VERSION, githubAuth));
}
if (CLI_VERSION) {
tools.push(cli.setup(CLI_VERSION));
tools.push(cli.setup(CLI_VERSION, githubAuth));
}
if (TDEPS_VERSION && !CLI_VERSION) {
tools.push(cli.setup(TDEPS_VERSION));
tools.push(cli.setup(TDEPS_VERSION, githubAuth));
}
if (BB_VERSION) {
tools.push(bb.setup(BB_VERSION, githubAuth));
@ -1327,7 +1332,7 @@ exports.isMacOS = isMacOS;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.VERSION = void 0;
exports.VERSION = '12-4';
exports.VERSION = '12-5';
/***/ }),

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -17,13 +17,13 @@ const client = new http.HttpClient('actions/setup-clojure', undefined, {
async function toolVersion(
version: string,
githubAuth?: string
githubAuth: string
): Promise<string> {
core.debug('=== Check tool version')
if (version === 'latest') {
const res = await client.getJson<{tag_name: string}>(
'https://api.github.com/repos/clojure/brew-install/releases/latest',
githubAuth ? {Authorization: githubAuth} : undefined
{Authorization: githubAuth}
)
const versionString = res.result?.tag_name
if (versionString) {
@ -50,15 +50,14 @@ function isResourceProvided(
async function getUrls(
tag: string,
githubAuth?: string
githubAuth: string
): Promise<{posix?: string; linux: string; windows: string}> {
core.debug('=== Get download URLs')
const res = await client.getJson<{
assets: {browser_download_url: string}[]
}>(
`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`,
githubAuth ? {Authorization: githubAuth} : undefined
)
}>(`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`, {
Authorization: githubAuth
})
const posix_install_url = `https://github.com/clojure/brew-install/releases/download/${tag}/posix-install.sh`
const assets = res.result?.assets
@ -78,10 +77,10 @@ async function getUrls(
export async function setup(
requestedVersion: string,
githubToken?: string
githubAuth: string
): Promise<void> {
core.debug('=== Run setup')
const version = await toolVersion(requestedVersion, githubToken)
const version = await toolVersion(requestedVersion, githubAuth)
const installDir = utils.isWindows()
? 'C:\\Program Files\\WindowsPowerShell\\Modules'
: '/tmp/usr/local/opt'
@ -98,7 +97,7 @@ export async function setup(
recursive: true
})
} else {
const {linux, posix, windows} = await getUrls(version, githubToken)
const {linux, posix, windows} = await getUrls(version, githubAuth)
if (utils.isWindows()) {
await exec.exec(`powershell -c "iwr -useb ${windows} | iex"`, [], {
@ -126,21 +125,21 @@ export async function setup(
clojureInstallScript = await tc.downloadTool(
posix,
undefined,
githubToken
githubAuth
)
} else {
clojureInstallScript = await tc.downloadTool(
linux,
undefined,
githubToken
githubAuth
)
await MacOSDeps(clojureInstallScript, githubToken)
await MacOSDeps(clojureInstallScript, githubAuth)
}
} else {
clojureInstallScript = await tc.downloadTool(
linux,
undefined,
githubToken
githubAuth
)
}
@ -179,7 +178,7 @@ async function runLinuxInstall(
return destinationFolder
}
async function MacOSDeps(file: string, githubToken?: string): Promise<void> {
async function MacOSDeps(file: string, githubAuth: string): Promise<void> {
core.debug('=== Install extra deps for MacOS')
const data = await fs.readFile(file, 'utf-8')
const newValue = data.replace(
@ -187,17 +186,20 @@ async function MacOSDeps(file: string, githubToken?: string): Promise<void> {
'$(brew --prefix coreutils)/bin/ginstall -D'
)
await fs.writeFile(file, newValue, 'utf-8')
const env = githubToken
? {env: {HOMEBREW_GITHUB_API_TOKEN: githubToken.substring(7)}}
: undefined
await exec.exec('brew', ['install', 'coreutils'], env)
await exec.exec('brew', ['install', 'coreutils'], {
env: {
HOMEBREW_GITHUB_API_TOKEN: githubAuth.substring(7),
HOMEBREW_NO_INSTALL_CLEANUP: 'true',
HOME: process.env['HOME'] || ''
}
})
}
export async function getLatestDepsClj(githubAuth?: string): Promise<string> {
export async function getLatestDepsClj(githubAuth: string): Promise<string> {
core.debug('=== Fetch latest version of deps clj')
const res = await client.getJson<{tag_name: string}>(
`https://api.github.com/repos/borkdude/deps.clj/releases/latest`,
githubAuth ? {Authorization: githubAuth} : undefined
{Authorization: githubAuth}
)
const result = res.result?.tag_name?.replace(/^v/, '')

View File

@ -26,8 +26,8 @@ export async function main(): Promise<void> {
const tools = []
const githubToken = core.getInput('github-token')
const githubAuth = githubToken ? `Bearer ${githubToken}` : undefined
const githubToken = core.getInput('github-token', {required: true})
const githubAuth = `Bearer ${githubToken}`
const IS_WINDOWS = utils.isWindows()
if (LEIN_VERSION) {
@ -39,11 +39,11 @@ export async function main(): Promise<void> {
}
if (CLI_VERSION) {
tools.push(cli.setup(CLI_VERSION))
tools.push(cli.setup(CLI_VERSION, githubAuth))
}
if (TDEPS_VERSION && !CLI_VERSION) {
tools.push(cli.setup(TDEPS_VERSION))
tools.push(cli.setup(TDEPS_VERSION, githubAuth))
}
if (BB_VERSION) {

View File

@ -1 +1 @@
export const VERSION = '12-4'
export const VERSION = '12-5'