Skip to content
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

Install deps.clj as workaround for cmd.exe #55

Merged
merged 4 commits into from
Jul 1, 2022
Merged
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
37 changes: 28 additions & 9 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ name: Smoke tests
on: [push]

jobs:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for these. Can we stick to this yml formatting convention, which is forced by Prettier?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I don't mind sticking with some convention if it improves readability. In addition - is it possible to configure prettier for the project? I think it is worth adding it as a command to run in package.json and include it into "run all" command as well. That way it will be clear for all contributors why yaml files are structured one way or another. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's definitely possible, and by the way Prettier will cover quite all the codebase here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But let's do this in separate PR, though

# Deprecated version identifier
# Please use `cli: version` as in job `clojure-cli`
test-tools-deps:

strategy:
matrix:
operating-system: [ubuntu-latest, macOS-latest]
Expand All @@ -34,7 +32,6 @@ jobs:
run: clojure -e "(+ 1 1)"

clojure-cli:

strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -96,7 +120,6 @@ jobs:
run: lein version

test-boot:

strategy:
matrix:
operating-system: [ubuntu-latest, macOS-latest]
Expand Down Expand Up @@ -124,7 +147,6 @@ jobs:
run: boot -V

test-bb:

strategy:
matrix:
operating-system: [ubuntu-latest, macOS-latest, windows-latest]
Expand Down Expand Up @@ -152,7 +174,6 @@ jobs:
run: bb --version

test-clj-kondo:

strategy:
matrix:
operating-system: [ubuntu-latest, macOS-latest, windows-latest]
Expand Down Expand Up @@ -180,7 +201,6 @@ jobs:
run: clj-kondo --version

test-cljstyle:

strategy:
matrix:
operating-system: [ubuntu-latest, macOS-latest]
Expand Down Expand Up @@ -208,7 +228,6 @@ jobs:
run: cljstyle version

all-together:

runs-on: ubuntu-latest

steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/entrypoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
65 changes: 63 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
})
}
9 changes: 7 additions & 2 deletions src/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -37,15 +38,19 @@ 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))
}
}

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))
}
Expand Down