Skip to content

Add optional no-auth #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ jobs:
cljstyle: 0.16.626 # cljstyle
cmd-exe-workaround: 'latest' # Replaces `clojure` with `deps.clj` on Windows
zprint: 1.2.3 # zprint
# In case you don't want to use built in authentication using github token
# Useful in case this action is used outside of github.com context
# `false` by default
no-auth: 'true'

# Optional step:
- name: Cache clojure dependencies
Expand Down
43 changes: 24 additions & 19 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
name: 'Setup Clojure'
description: 'Setup your runner with Clojure build tools'
author: 'DeLaGuardo'
name: "Setup Clojure"
description: "Setup your runner with Clojure build tools"
author: "DeLaGuardo"
branding:
icon: 'gift'
color: 'blue'
icon: "gift"
color: "blue"
inputs:
lein:
description: 'The Leiningen version to make available on the path.'
description: "The Leiningen version to make available on the path."
boot:
description: 'The boot-clj version to make available on the path.'
description: "The boot-clj version to make available on the path."
tools-deps:
description: '[DEPRECATED] The tools deps version to make available on the path.'
deprecationMessage: 'Use the `cli` input instead'
description: "[DEPRECATED] The tools deps version to make available on the path."
deprecationMessage: "Use the `cli` input instead"
cli:
description: 'Clojure CLI version to make available on the path.'
description: "Clojure CLI version to make available on the path."
cmd-exe-workaround:
description: >+
[DEPRECATED]
On Windows platform, it will replace official Clojure CLI
with the `deps.clj` of its specific version, `latest` can be used.

Useful for running `clojure` command from `cmd.exe`.
deprecationMessage: 'No longer needed. Please remove and use unified `cli` input instead'
deprecationMessage: "No longer needed. Please remove and use unified `cli` input instead"
bb:
description: 'Babashka version to install, `latest` can be used.'
description: "Babashka version to install, `latest` can be used."
clj-kondo:
description: 'Clj-kondo version to install, `latest` can be used.'
description: "Clj-kondo version to install, `latest` can be used."
cljfmt:
description: 'cljfmt version to install, `latest` can be used.'
description: "cljfmt version to install, `latest` can be used."
cljstyle:
description: 'cljstyle version to install, `latest` can be used.'
description: "cljstyle version to install, `latest` can be used."
zprint:
description: 'zprint version to install, `latest` can be used.'
description: "zprint version to install, `latest` can be used."
github-token:
description: >+
To fix rate limit errors, provide `secrets.GITHUB_TOKEN` value to this field.
Expand All @@ -41,8 +41,13 @@ inputs:
invalidate-cache:
description: >+
Set to `true` to fix problems related to wrongly populated tool cache
default: 'false'
default: "false"
required: false
no-auth:
description: >+
Set to `true` to avoid using github-token as an Authentication header
default: "false"
required: false
runs:
using: 'node20'
main: 'dist/index.js'
using: "node20"
main: "dist/index.js"
14 changes: 6 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ function toolVersion(version, githubAuth) {
var _a;
core.debug('=== Check tool version');
if (version === 'latest') {
const res = yield client.getJson('https://api.github.com/repos/clojure/brew-install/releases/latest', { Authorization: githubAuth });
const res = yield client.getJson('https://api.github.com/repos/clojure/brew-install/releases/latest', githubAuth ? { Authorization: githubAuth } : {});
const versionString = (_a = res.result) === null || _a === void 0 ? void 0 : _a.tag_name;
if (versionString) {
return versionString;
Expand All @@ -428,9 +428,7 @@ function getUrls(tag, githubAuth) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
core.debug('=== Get download URLs');
const res = yield client.getJson(`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`, {
Authorization: githubAuth
});
const res = yield client.getJson(`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`, githubAuth ? { 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)) {
Expand Down Expand Up @@ -516,7 +514,7 @@ function MacOSDeps(file, githubAuth) {
yield fs.writeFile(file, newValue, 'utf-8');
yield exec.exec('brew', ['install', 'coreutils'], {
env: {
HOMEBREW_GITHUB_API_TOKEN: githubAuth.substring(7),
HOMEBREW_GITHUB_API_TOKEN: githubAuth ? githubAuth.substring(7) : '',
HOMEBREW_NO_INSTALL_CLEANUP: 'true',
HOME: process.env['HOME'] || ''
}
Expand All @@ -527,7 +525,7 @@ function getLatestDepsClj(githubAuth) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
core.debug('=== Fetch latest version of deps clj');
const res = yield client.getJson(`https://api.github.com/repos/borkdude/deps.clj/releases/latest`, { Authorization: githubAuth });
const res = yield client.getJson(`https://api.github.com/repos/borkdude/deps.clj/releases/latest`, githubAuth ? { 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;
Expand Down Expand Up @@ -908,8 +906,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', { required: true });
const githubAuth = `Bearer ${githubToken}`;
const noAuth = core.getBooleanInput('no-auth');
const githubAuth = noAuth ? undefined : `Bearer ${core.getInput('github-token', { required: true })}`;
const IS_WINDOWS = utils.isWindows();
if (LEIN_VERSION) {
tools.push(lein.setup(LEIN_VERSION, githubAuth));
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{Authorization: githubAuth}
githubAuth ? {Authorization: githubAuth} : {}
)
const versionString = res.result?.tag_name
if (versionString) {
Expand All @@ -50,14 +50,15 @@ 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}`, {
Authorization: githubAuth
})
}>(
`https://api.github.com/repos/clojure/brew-install/releases/tags/${tag}`,
githubAuth ? {Authorization: githubAuth} : {}
)
const posix_install_url = `https://github.com/clojure/brew-install/releases/download/${tag}/posix-install.sh`

const assets = res.result?.assets
Expand All @@ -77,7 +78,7 @@ async function getUrls(

export async function setup(
requestedVersion: string,
githubAuth: string
githubAuth?: string
): Promise<void> {
core.debug('=== Run setup')
const version = await toolVersion(requestedVersion, githubAuth)
Expand Down Expand Up @@ -178,7 +179,7 @@ async function runLinuxInstall(
return destinationFolder
}

async function MacOSDeps(file: string, githubAuth: 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(
Expand All @@ -188,18 +189,18 @@ async function MacOSDeps(file: string, githubAuth: string): Promise<void> {
await fs.writeFile(file, newValue, 'utf-8')
await exec.exec('brew', ['install', 'coreutils'], {
env: {
HOMEBREW_GITHUB_API_TOKEN: githubAuth.substring(7),
HOMEBREW_GITHUB_API_TOKEN: githubAuth ? 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`,
{Authorization: githubAuth}
githubAuth ? {Authorization: githubAuth} : {}
)

const result = res.result?.tag_name?.replace(/^v/, '')
Expand Down
7 changes: 5 additions & 2 deletions src/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export async function main(): Promise<void> {

const tools = []

const githubToken = core.getInput('github-token', {required: true})
const githubAuth = `Bearer ${githubToken}`
const noAuth = core.getBooleanInput('no-auth')

const githubAuth = noAuth
? undefined
: `Bearer ${core.getInput('github-token', {required: true})}`
const IS_WINDOWS = utils.isWindows()

if (LEIN_VERSION) {
Expand Down
Loading