mirror of
https://github.com/DeLaGuardo/setup-clojure.git
synced 2025-01-14 02:18:07 +08:00
Add support for Babashka
This commit is contained in:
parent
f71ef226d2
commit
ba9f215e21
28
.github/workflows/smoke-tests.yml
vendored
28
.github/workflows/smoke-tests.yml
vendored
@ -122,3 +122,31 @@ jobs:
|
||||
|
||||
- name: Check boot version
|
||||
run: boot -V
|
||||
|
||||
test-bb:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Prepare java
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '8'
|
||||
|
||||
- name: Install babashka
|
||||
# uses: DeLaGuardo/setup-clojure@master
|
||||
uses: ./
|
||||
with:
|
||||
bb: latest
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Check babashka version
|
||||
run: bb --version
|
||||
|
@ -13,6 +13,8 @@ inputs:
|
||||
description: '[DEPRECATED] The tools deps version to make available on the path.'
|
||||
cli:
|
||||
description: 'Clojure CLI version to make available on the path.'
|
||||
bb:
|
||||
description: 'Babashka version to install, `latest` can be used. '
|
||||
github-token:
|
||||
description: >+
|
||||
To fix rate limit errors, provide `secrets.GITHUB_TOKEN` value to this field.
|
||||
|
1
package-lock.json
generated
1
package-lock.json
generated
@ -11,6 +11,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.6.0",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"@actions/http-client": "^1.0.11",
|
||||
"@actions/io": "^1.1.1",
|
||||
"@actions/tool-cache": "^1.7.1"
|
||||
},
|
||||
|
@ -27,6 +27,7 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.6.0",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"@actions/http-client": "^1.0.11",
|
||||
"@actions/io": "^1.1.1",
|
||||
"@actions/tool-cache": "^1.7.1"
|
||||
},
|
||||
|
63
src/babashka.ts
Normal file
63
src/babashka.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as tc from '@actions/tool-cache'
|
||||
import * as http from '@actions/http-client'
|
||||
|
||||
import * as os from 'os'
|
||||
|
||||
export async function getLatestBabashka(githubToken?: string): Promise<string> {
|
||||
const client = new http.HttpClient('actions/setup-clojure', undefined, {
|
||||
allowRetries: true,
|
||||
maxRetries: 3
|
||||
})
|
||||
|
||||
const res = await client.getJson<{tag_name: string}>(
|
||||
`/repos/babashka/babashka/releases/latest`,
|
||||
githubToken ? {Authorization: `bearer ${githubToken}`} : undefined
|
||||
)
|
||||
|
||||
const result = res.result?.tag_name?.replace(/^v/, '')
|
||||
if (result) {
|
||||
return result
|
||||
}
|
||||
|
||||
throw new Error(`Can't obtain latest Babashka version`)
|
||||
}
|
||||
|
||||
export function getArtifactName(version: string): string {
|
||||
const platform = os.platform()
|
||||
switch (platform) {
|
||||
case 'win32':
|
||||
return `babashka-${version}-windows-amd64.zip`
|
||||
case 'darwin':
|
||||
return `babashka-${version}-macos-amd64.tar.gz`
|
||||
default:
|
||||
return `babashka-${version}-linux-amd64-static.tar.gz`
|
||||
}
|
||||
}
|
||||
|
||||
export function getArtifactUrl(version: string): string {
|
||||
const archiveName = getArtifactName(version)
|
||||
return `https://github.com/babashka/babashka/releases/download/v${version}/${archiveName}`
|
||||
}
|
||||
|
||||
export async function extract(source: string): Promise<string> {
|
||||
return source.endsWith('.zip') ? tc.extractZip(source) : tc.extractTar(source)
|
||||
}
|
||||
|
||||
export async function setup(
|
||||
version: string,
|
||||
githubToken?: string
|
||||
): Promise<void> {
|
||||
const ver =
|
||||
version === 'latest' ? await getLatestBabashka(githubToken) : version
|
||||
|
||||
let toolDir = tc.find('Babashka', ver)
|
||||
if (!toolDir) {
|
||||
const archiveUrl = getArtifactUrl(ver)
|
||||
const archiveDir = await tc.downloadTool(archiveUrl)
|
||||
toolDir = await extract(archiveDir)
|
||||
await tc.cacheDir(toolDir, 'Babashka', ver)
|
||||
}
|
||||
|
||||
core.addPath(toolDir)
|
||||
}
|
@ -2,6 +2,7 @@ import * as core from '@actions/core'
|
||||
import * as lein from './leiningen'
|
||||
import * as boot from './boot'
|
||||
import * as cli from './cli'
|
||||
import * as bb from './babashka'
|
||||
import * as utils from './utils'
|
||||
|
||||
const IS_WINDOWS = utils.isWindows()
|
||||
@ -12,6 +13,7 @@ async function run(): Promise<void> {
|
||||
const BOOT_VERSION = core.getInput('boot')
|
||||
const TDEPS_VERSION = core.getInput('tools-deps')
|
||||
const CLI_VERSION = core.getInput('cli')
|
||||
const BB_VERSION = core.getInput('bb')
|
||||
|
||||
const githubToken = core.getInput('github-token')
|
||||
const githubAuth = githubToken ? `token ${githubToken}` : undefined
|
||||
@ -42,7 +44,17 @@ async function run(): Promise<void> {
|
||||
cli.setup(TDEPS_VERSION)
|
||||
}
|
||||
|
||||
if (!BOOT_VERSION && !LEIN_VERSION && !TDEPS_VERSION && !CLI_VERSION) {
|
||||
if (BB_VERSION) {
|
||||
bb.setup(BB_VERSION, githubToken)
|
||||
}
|
||||
|
||||
if (
|
||||
!BOOT_VERSION &&
|
||||
!LEIN_VERSION &&
|
||||
!TDEPS_VERSION &&
|
||||
!CLI_VERSION &&
|
||||
!BB_VERSION
|
||||
) {
|
||||
throw new Error('You must specify at least one clojure tool.')
|
||||
}
|
||||
} catch (error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user