Skip to content

Commit

Permalink
support windows (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
nha authored Mar 29, 2021
1 parent acccd3e commit 9d44019
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Setup Babashka
uses: turtlequeue/setup-babashka@main
with:
babashka-version: 0.2.3
babashka-version: 0.3.0

- name: Check bb runs
run: bb --version
11 changes: 10 additions & 1 deletion .github/workflows/self_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, ubuntu-18.04, macos-latest]
os: [ubuntu-latest, ubuntu-18.04, macos-latest, windows-latest]
babashka-version: [0.2.3, 0.2.12, 0.3.0]
steps:
- name: Setup Babashka
Expand All @@ -18,3 +18,12 @@ jobs:

- name: Check if bb runs fine
run: bb --version

- name: Setup Babashka from cache
id: setup-babashka-2
uses: turtlequeue/setup-babashka@main
with:
babashka-version: ${{ matrix.babashka-version }}

- name: Check if bb runs fine from cache
run: bb --version
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ yarn install
yarn package
```

Handy shortcut to test in CI
```
git addm
git cia --no-edit
yarn package && git addm && git cia --no-edit && git push -f
```

# License
Copyright © 2021 Turtlequeue Ltd

Expand Down
17 changes: 7 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5346,7 +5346,7 @@ function getBabashka(version) {
return __awaiter(this, void 0, void 0, function* () {
let toolPath = tc.find('Babashka', version, os.arch());
const allBabashkaVersions = tc.findAllVersions('Babashka');
if (allBabashkaVersions.length) {
if (allBabashkaVersions.length != 0) {
core.info(`No versions of babashka are available yet`);
}
else {
Expand All @@ -5367,18 +5367,15 @@ function getBabashka(version) {
yield exec.exec('bash', [installerFile, "--dir", tmpPath, "--version", version]);
core.info(`babashka installed to ${tmpPath}`);
toolPath = yield tc.cacheDir(tmpPath, 'Babashka', version, os.arch());
core.info(`babashka setup at ${toolPath}`);
core.addPath(toolPath);
}
else {
// windows - PR welcome
// https://scoop.sh/
// https://github.com/littleli/scoop-clojure
core.info(`Windows not supported, PR welcome. Installing using https://github.com/littleli/scoop-clojure should be possible.`);
throw (new Error("Windows not supported, PR welcome. Installing using https://github.com/littleli/scoop-clojure should be possible."));
// await exec.exec('iwr', ["-useb", "get.scoop.sh", "|", "iex"])
// await exec.exec('scoop', ["install", "babashka"])
core.info(`Windows detected, setting up babashka using scoop`);
yield exec.exec('powershell', ['-command', `if (Test-Path('bb.exe')) { return } else { (New-Object Net.WebClient).DownloadFile('https://github.com/babashka/babashka/releases/download/v${version}/babashka-${version}-windows-amd64.zip', 'bb.zip') }`]);
yield exec.exec('powershell', ['-command', "if (Test-Path('bb.exe')) { return } else { Expand-Archive bb.zip . }"]);
toolPath = yield tc.cacheFile('bb.exe', 'bb.exe', 'Babashka', version, os.arch());
}
core.info(`babashka setup at ${toolPath}`);
core.addPath(toolPath);
});
}
exports.getBabashka = getBabashka;
Expand Down
81 changes: 42 additions & 39 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,63 @@ import { v4 as uuidv4 } from 'uuid';
import { ok } from 'assert'

function _getTempDirectory(): string {
const tempDirectory = process.env['RUNNER_TEMP'] || ''
ok(tempDirectory, 'Expected RUNNER_TEMP to be defined')
return tempDirectory
const tempDirectory = process.env['RUNNER_TEMP'] || ''
ok(tempDirectory, 'Expected RUNNER_TEMP to be defined')
return tempDirectory
}

export async function getBabashka(version: string): Promise<void> {
let toolPath = tc.find('Babashka', version, os.arch())
let toolPath = tc.find('Babashka', version, os.arch())


const allBabashkaVersions = tc.findAllVersions('Babashka')
const allBabashkaVersions = tc.findAllVersions('Babashka')

if (allBabashkaVersions.length) {
core.info(`No versions of babashka are available yet`)
} else {
core.info(`Versions of babashka available: ${allBabashkaVersions}`)
}
if (allBabashkaVersions.length != 0) {
core.info(`No versions of babashka are available yet`)
} else {
core.info(`Versions of babashka available: ${allBabashkaVersions}`)
}


if (toolPath) {
core.info(`Babashka found in cache ${toolPath}`)
core.addPath(toolPath)
} else if (process.platform !== 'win32') {
// Linux, osx
// rely on babashka's installer
const tmpPath = path.join(_getTempDirectory(), uuidv4())
await io.mkdirP(tmpPath)
if (toolPath) {
core.info(`Babashka found in cache ${toolPath}`)
core.addPath(toolPath)
} else if (process.platform !== 'win32') {
// Linux, osx
// rely on babashka's installer
const tmpPath = path.join(_getTempDirectory(), uuidv4())
await io.mkdirP(tmpPath)

core.info('temporary directory ' + tmpPath)
core.info('temporary directory ' + tmpPath)

const installerFile = await tc.downloadTool("https://raw.githubusercontent.com/babashka/babashka/master/install")
core.info(`Downloaded installer file ${installerFile}`)
const installerFile = await tc.downloadTool("https://raw.githubusercontent.com/babashka/babashka/master/install")
core.info(`Downloaded installer file ${installerFile}`)

await exec.exec('bash', [installerFile, "--dir", tmpPath, "--version", version])
await exec.exec('bash', [installerFile, "--dir", tmpPath, "--version", version])

core.info(`babashka installed to ${tmpPath}`)
core.info(`babashka installed to ${tmpPath}`)

toolPath = await tc.cacheDir(
tmpPath,
'Babashka',
version,
os.arch())
toolPath = await tc.cacheDir(
tmpPath,
'Babashka',
version,
os.arch())
} else {
core.info(`Windows detected, setting up babashka using scoop`)

core.info(`babashka setup at ${toolPath}`)
await exec.exec('powershell', ['-command', `if (Test-Path('bb.exe')) { return } else { (New-Object Net.WebClient).DownloadFile('https://github.com/babashka/babashka/releases/download/v${version}/babashka-${version}-windows-amd64.zip', 'bb.zip') }`]);
await exec.exec('powershell', ['-command', "if (Test-Path('bb.exe')) { return } else { Expand-Archive bb.zip . }"]);

core.addPath(toolPath)
} else {
// windows - PR welcome
// https://scoop.sh/
// https://github.com/littleli/scoop-clojure
core.info(`Windows not supported, PR welcome. Installing using https://github.com/littleli/scoop-clojure should be possible.`)
throw (new Error("Windows not supported, PR welcome. Installing using https://github.com/littleli/scoop-clojure should be possible."))
// await exec.exec('iwr', ["-useb", "get.scoop.sh", "|", "iex"])
// await exec.exec('scoop', ["install", "babashka"])
}
toolPath = await tc.cacheFile(
'bb.exe',
'bb.exe',
'Babashka',
version,
os.arch())
}

core.info(`babashka setup at ${toolPath}`)

core.addPath(toolPath)

}
5 changes: 5 additions & 0 deletions src/windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
iwr -useb get.scoop.sh | iex
scoop bucket add scoop-clojure https://github.com/littleli/scoop-clojure
scoop bucket add extras
scoop install babashka --independent
echo "$HOME\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

0 comments on commit 9d44019

Please sign in to comment.