mirror of
https://github.com/DeLaGuardo/setup-clojure.git
synced 2025-01-14 02:18:07 +08:00
Merge pull request #55 from zharinov/cmd-exe-workaround
Install `deps.clj` as workaround for `cmd.exe`
This commit is contained in:
commit
fc73f6f88b
37
.github/workflows/smoke-tests.yml
vendored
37
.github/workflows/smoke-tests.yml
vendored
@ -3,11 +3,9 @@ name: Smoke tests
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
|
||||
# Deprecated version identifier
|
||||
# Please use `cli: version` as in job `clojure-cli`
|
||||
test-tools-deps:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, macOS-latest]
|
||||
@ -34,7 +32,6 @@ jobs:
|
||||
run: clojure -e "(+ 1 1)"
|
||||
|
||||
clojure-cli:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
@ -67,8 +64,35 @@ jobs:
|
||||
run: clojure -e "(+ 1 1)"
|
||||
shell: powershell
|
||||
|
||||
test-leiningen:
|
||||
clojure-cmd-exe:
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Prepare java
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: '8'
|
||||
|
||||
- name: Install clojure tools-deps
|
||||
# uses: DeLaGuardo/setup-clojure@master
|
||||
uses: ./
|
||||
with:
|
||||
cli: 'latest'
|
||||
cmd-exe-workaround: 'latest'
|
||||
|
||||
- name: Execute clojure from PowerShell
|
||||
run: clojure --version
|
||||
shell: powershell
|
||||
|
||||
- name: Execute clojure from cmd.exe
|
||||
run: clojure --version
|
||||
shell: cmd
|
||||
|
||||
test-leiningen:
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
@ -96,7 +120,6 @@ jobs:
|
||||
run: lein version
|
||||
|
||||
test-boot:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, macOS-latest]
|
||||
@ -124,7 +147,6 @@ jobs:
|
||||
run: boot -V
|
||||
|
||||
test-bb:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
@ -152,7 +174,6 @@ jobs:
|
||||
run: bb --version
|
||||
|
||||
test-clj-kondo:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, macOS-latest, windows-latest]
|
||||
@ -180,7 +201,6 @@ jobs:
|
||||
run: clj-kondo --version
|
||||
|
||||
test-cljstyle:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system: [ubuntu-latest, macOS-latest]
|
||||
@ -236,7 +256,6 @@ jobs:
|
||||
run: zprint --version
|
||||
|
||||
all-together:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
@ -53,6 +53,7 @@ jobs:
|
||||
bb: 0.7.8 # Babashka
|
||||
clj-kondo: 2022.05.31 # Clj-kondo
|
||||
cljstyle: 0.15.0 # cljstyle
|
||||
cmd-exe-workaround: 'latest' # Replace `clojure` with `deps.clj` on Windows
|
||||
|
||||
- name: Execute clojure code on Linux and MacOS
|
||||
if: ${{ matrix.os != 'windows-latest' }}
|
||||
|
@ -89,7 +89,7 @@ describe('setup-clojure', () => {
|
||||
|
||||
await run()
|
||||
|
||||
expect(cli.setupWindows).toHaveBeenCalledWith('1.2.3')
|
||||
expect(cli.setupWindows).toHaveBeenCalledWith('1.2.3', undefined, undefined)
|
||||
})
|
||||
|
||||
it('sets up Clojure CLI tools', async () => {
|
||||
@ -106,7 +106,7 @@ describe('setup-clojure', () => {
|
||||
|
||||
await run()
|
||||
|
||||
expect(cli.setupWindows).toHaveBeenCalledWith('1.2.3')
|
||||
expect(cli.setupWindows).toHaveBeenCalledWith('1.2.3', undefined, undefined)
|
||||
})
|
||||
|
||||
it('sets up Babashka', async () => {
|
||||
|
@ -14,6 +14,12 @@ inputs:
|
||||
deprecationMessage: 'Use the `cli` input instead'
|
||||
cli:
|
||||
description: 'Clojure CLI version to make available on the path.'
|
||||
cmd-exe-workaround:
|
||||
description: >+
|
||||
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`.
|
||||
bb:
|
||||
description: 'Babashka version to install, `latest` can be used.'
|
||||
clj-kondo:
|
||||
|
65
src/cli.ts
65
src/cli.ts
@ -2,6 +2,7 @@ import * as core from '@actions/core'
|
||||
import * as io from '@actions/io'
|
||||
import * as tc from '@actions/tool-cache'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as http from '@actions/http-client'
|
||||
import * as path from 'path'
|
||||
import * as os from 'os'
|
||||
import * as fs from './fs'
|
||||
@ -73,11 +74,71 @@ async function MacOSDeps(file: string, githubToken?: string): Promise<void> {
|
||||
await exec.exec('brew', ['install', 'coreutils'], env)
|
||||
}
|
||||
|
||||
export async function setupWindows(version: string): Promise<void> {
|
||||
export async function getLatestDepsClj(githubAuth?: string): Promise<string> {
|
||||
const client = new http.HttpClient('actions/setup-clojure', undefined, {
|
||||
allowRetries: true,
|
||||
maxRetries: 3
|
||||
})
|
||||
|
||||
const res = await client.getJson<{tag_name: string}>(
|
||||
`https://api.github.com/repos/borkdude/deps.clj/releases/latest`,
|
||||
githubAuth ? {Authorization: githubAuth} : undefined
|
||||
)
|
||||
|
||||
const result = res.result?.tag_name?.replace(/^v/, '')
|
||||
if (result) {
|
||||
return result
|
||||
}
|
||||
|
||||
throw new Error(`Can't obtain latest deps.clj version`)
|
||||
}
|
||||
|
||||
export async function setupWindows(
|
||||
version: string,
|
||||
cmdExeWorkaround: string,
|
||||
githubAuth?: string
|
||||
): Promise<void> {
|
||||
if (cmdExeWorkaround) {
|
||||
let depsCljVersion = cmdExeWorkaround
|
||||
if (depsCljVersion === 'latest') {
|
||||
depsCljVersion = await getLatestDepsClj(githubAuth)
|
||||
}
|
||||
let clojureExePath = tc.find('deps.clj', depsCljVersion)
|
||||
if (!clojureExePath) {
|
||||
const archiveUrl = `https://github.com/borkdude/deps.clj/releases/download/v${depsCljVersion}/deps.clj-${depsCljVersion}-windows-amd64.zip`
|
||||
core.info(`archiveUrl = ${archiveUrl}`)
|
||||
|
||||
const archivePath = await tc.downloadTool(
|
||||
archiveUrl,
|
||||
undefined,
|
||||
githubAuth
|
||||
)
|
||||
core.info(`archivePath = ${archivePath}`)
|
||||
|
||||
const depsExePath = await tc.extractZip(archivePath)
|
||||
const depsExe = path.join(depsExePath, 'deps.exe')
|
||||
core.info(`depsExe = ${depsExe}`)
|
||||
|
||||
clojureExePath = await tc.cacheFile(
|
||||
depsExe,
|
||||
'clojure.exe',
|
||||
'deps.clj',
|
||||
depsCljVersion
|
||||
)
|
||||
core.info(`clojureExePath = ${clojureExePath}`)
|
||||
|
||||
const clojureExe = path.join(clojureExePath, 'clojure.exe')
|
||||
await fs.chmod(clojureExe, '0755')
|
||||
}
|
||||
|
||||
core.addPath(clojureExePath)
|
||||
return
|
||||
}
|
||||
|
||||
const url = `download.clojure.org/install/win-install${
|
||||
version === 'latest' ? '' : `-${version}`
|
||||
}.ps1`
|
||||
exec.exec(`powershell -c "iwr -useb ${url} | iex"`, [], {
|
||||
await exec.exec(`powershell -c "iwr -useb ${url} | iex"`, [], {
|
||||
input: Buffer.from('1')
|
||||
})
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ export 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 CMD_EXE_WORKAROUND = core.getInput('cmd-exe-workaround')
|
||||
const BB_VERSION = core.getInput('bb')
|
||||
const CLJ_KONDO_VERSION = core.getInput('clj-kondo')
|
||||
const CLJSTYLE_VERSION = core.getInput('cljstyle')
|
||||
@ -39,7 +40,9 @@ export async function run(): Promise<void> {
|
||||
|
||||
if (CLI_VERSION) {
|
||||
if (IS_WINDOWS) {
|
||||
tools.push(cli.setupWindows(CLI_VERSION))
|
||||
tools.push(
|
||||
cli.setupWindows(CLI_VERSION, CMD_EXE_WORKAROUND, githubAuth)
|
||||
)
|
||||
} else {
|
||||
tools.push(cli.setup(CLI_VERSION))
|
||||
}
|
||||
@ -47,7 +50,9 @@ export async function run(): Promise<void> {
|
||||
|
||||
if (TDEPS_VERSION && !CLI_VERSION) {
|
||||
if (IS_WINDOWS) {
|
||||
tools.push(cli.setupWindows(TDEPS_VERSION))
|
||||
tools.push(
|
||||
cli.setupWindows(TDEPS_VERSION, CMD_EXE_WORKAROUND, githubAuth)
|
||||
)
|
||||
}
|
||||
tools.push(cli.setup(TDEPS_VERSION))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user