diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index bd3f75b..c504353 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -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] @@ -208,7 +228,6 @@ jobs: run: cljstyle version all-together: - runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index e4751a0..25df7ee 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,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' }} diff --git a/__tests__/entrypoint.test.ts b/__tests__/entrypoint.test.ts index 1826408..44f4001 100644 --- a/__tests__/entrypoint.test.ts +++ b/__tests__/entrypoint.test.ts @@ -85,7 +85,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 () => { @@ -102,7 +102,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 () => { diff --git a/action.yml b/action.yml index 748369c..d0e0251 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/src/cli.ts b/src/cli.ts index 794c1ca..8dc6193 100644 --- a/src/cli.ts +++ b/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 { await exec.exec('brew', ['install', 'coreutils'], env) } -export async function setupWindows(version: string): Promise { +export async function getLatestDepsClj(githubAuth?: string): Promise { + 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 { + 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') }) } diff --git a/src/entrypoint.ts b/src/entrypoint.ts index 3784b16..3756868 100644 --- a/src/entrypoint.ts +++ b/src/entrypoint.ts @@ -13,6 +13,7 @@ export async function run(): Promise { 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 { 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 { 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)) }