Install deps.clj as cmd.exe workaround

This commit is contained in:
Sergei Zharinov 2022-06-28 08:48:28 +03:00
parent d3f93a4817
commit 966cb83920
4 changed files with 104 additions and 13 deletions

View File

@ -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.exe
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]
@ -208,7 +228,6 @@ jobs:
run: cljstyle version
all-together:
runs-on: ubuntu-latest
steps:

View File

@ -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:

View File

@ -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')
})
}

View File

@ -13,6 +13,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')
@ -37,7 +38,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))
}
@ -45,7 +48,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))
}