Skip to content

Commit

Permalink
Merge branch 'gmitch215-pr'
Browse files Browse the repository at this point in the history
Closes #443
  • Loading branch information
fwilhe2 committed Oct 30, 2024
2 parents e129053 + ea2c4b8 commit a06ccb4
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
exit 1
fi
env:
INPUT_VERSION: 1.8.10
INPUT_VERSION: 2.0.21
INPUT_INSTALL-NATIVE: false
test:
Expand All @@ -48,14 +48,14 @@ jobs:
- uses: actions/checkout@v4
- uses: ./
with:
version: 1.8.10
version: 2.0.21
script: |
#!/usr/bin/env kotlin
fun getInput(name: String): String {
return System.getenv("INPUT_${name.replace(" ", "_").toUpperCase()}")
}
if (getInput("version") != "1.8.10") {
throw RuntimeException("Expected version 1.8.10")
if (getInput("version") != "2.0.21") {
throw RuntimeException("Expected version 2.0.21")
}
test-with-arg-default-version:
Expand All @@ -72,8 +72,8 @@ jobs:
fun getInput(name: String): String {
return System.getenv("INPUT_${name.replace(" ", "_").toUpperCase()}")
}
if (getInput("version") != "1.8.10") {
throw RuntimeException("Expected version 1.8.10")
if (getInput("version") != "2.0.21") {
throw RuntimeException("Expected version 2.0.21")
}
test-with-native:
Expand All @@ -85,7 +85,7 @@ jobs:
- uses: actions/checkout@v4
- uses: ./
with:
version: 1.8.10
version: 2.0.21
install-native: true
- run: kotlinc -version
- run: kotlinc-native -version
Expand Down
2 changes: 1 addition & 1 deletion DEVEL.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Example for running the action manually inside a dev container:

```
INPUT_VERSION=1.8.10 node dist/index.js
INPUT_VERSION=2.0.21 node dist/index.js
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ If you provide a string-argument `script`, the action will execute it via [`kotl
```yaml
- uses: fwilhe2/setup-kotlin@main
with:
version: 1.8.10
version: 2.0.21
- run: |
java.io.File(".").listFiles().forEach {it -> println(it.getName().toString())}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ test('getInputInstallNative string empty', async () => {
// shows how the runner will run a javascript action with env / stdout protocol
test('test runs with explicit version', () => {
process.env['INPUT_SCRIPT'] = 'println(234234)'
process.env['INPUT_VERSION'] = '1.8.10'
process.env['INPUT_VERSION'] = '2.0.21'
process.env['INPUT_install-native'] = 'false'
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
env: process.env
}
const output = cp.execSync(`node ${ip}`, options).toString()
expect(output).toMatch(/kotlinc-jvm 1.8.10/)
expect(output).toMatch(/kotlinc-jvm 2.0.21/)
})
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
version:
required: true
description: 'Version of the compiler to download, if not provided a default value is used.'
default: '1.8.10'
default: '2.0.21'
install-native:
required: false
description: 'Install Kotlin/Native tool chain (not needed for compiling jvm programs).'
Expand Down
13 changes: 11 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions src/main.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 exec from '@actions/exec'
import * as fs from 'fs'
import * as tc from '@actions/tool-cache'
import * as os from 'os'

const IS_WINDOWS = process.platform === 'win32'
const IS_DARWIN = process.platform === 'darwin'
Expand Down Expand Up @@ -39,7 +40,7 @@ async function run(): Promise<void> {
The order of addPath call here matter because both archives have a "kotlinc" binary.
*/
if (installNative) {
core.addPath(`${nativeCachedPath}/kotlin-native-${osName()}-x86_64-${version}/bin`)
core.addPath(`${nativeCachedPath}/kotlin-native-prebuilt-${osName()}-${osArch()}-${version}/bin`)
await exec.exec('kotlinc-native', ['-version'])
}
core.addPath(`${cachedPath}/kotlinc/bin`)
Expand All @@ -64,7 +65,7 @@ export function getInputInstallNative(skipNative: string): boolean {

function nativeDownloadUrl(version: string): string {
const fileEnding = IS_WINDOWS ? 'zip' : 'tar.gz'
return `https://github.com/JetBrains/kotlin/releases/download/v${version}/kotlin-native-${osName()}-x86_64-${version}.${fileEnding}`
return `https://github.com/JetBrains/kotlin/releases/download/v${version}/kotlin-native-prebuilt-${osName()}-${osArch()}-${version}.${fileEnding}`
}

function osName(): string {
Expand All @@ -77,6 +78,16 @@ function osName(): string {
}
}

function osArch(): string {
switch (os.arch()) {
case 'arm':
case 'arm64':
return 'aarch64'
}

return 'x86_64'
}

async function extractNativeArchive(ktNativePath: string): Promise<string> {
if (IS_WINDOWS) {
return tc.extractZip(ktNativePath)
Expand Down

0 comments on commit a06ccb4

Please sign in to comment.