Skip to content

Commit

Permalink
Enable CI on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
aahlenst authored and cilki committed Nov 7, 2020
1 parent 3f12137 commit 31321e3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ on:

jobs:
build:
name: "Build and Test"
runs-on: ubuntu-latest
name: "Build and Test on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
steps:

- name: Set up Go
Expand Down
33 changes: 21 additions & 12 deletions jlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"time"
Expand All @@ -41,7 +42,7 @@ var (
MAVEN_CENTRAL = false

// The platform for local runtimes
LOCAL_PLATFORM = "linux"
LOCAL_PLATFORM = determineLocalPlatform()

// The architecture for local runtimes
LOCAL_ARCH = "x64"
Expand Down Expand Up @@ -97,17 +98,6 @@ func main() {
log.Fatal("Invalid value for MAVEN_CENTRAL flag")
}
}
if platform, exists := os.LookupEnv("TRAVIS_OS_NAME"); exists {
switch platform {
case "osx":
LOCAL_PLATFORM = "mac"
default:
LOCAL_PLATFORM = platform
}
}
if platform, exists := os.LookupEnv("LOCAL_PLATFORM"); exists {
LOCAL_PLATFORM = platform
}
if arch, exists := os.LookupEnv("LOCAL_ARCH"); exists {
LOCAL_ARCH = arch
}
Expand Down Expand Up @@ -414,3 +404,22 @@ func jlink(jdk, mavenCentral, runtime, endian, version, platform, filename strin

return &buffer, nil
}

func determineLocalPlatform() string {
var localPlatform string
if platform, exists := os.LookupEnv("LOCAL_PLATFORM"); exists {
localPlatform = platform
} else {
// For a list of possible values, run: go tool dist list
localPlatform = runtime.GOOS
}

// See https://api.adoptopenjdk.net/swagger-ui/#/Binary/get_v3_binary_latest__feature_version___release_type___os___arch___image_type___jvm_impl___heap_size___vendor_
// for a list of accepted platforms by AdoptOpenJDK.
switch localPlatform {
case "darwin":
return "mac"
default:
return localPlatform
}
}
20 changes: 20 additions & 0 deletions jlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -136,3 +137,22 @@ func TestVersionRegex(t *testing.T) {
assert.False(t, versionCheck.MatchString(".9"))
assert.False(t, versionCheck.MatchString("09"))
}

func TestDetermineLocalPlatform(t *testing.T) {
expectedPlatform := runtime.GOOS
if expectedPlatform == "darwin" {
expectedPlatform = "mac"
}

assert.Equal(t, "", os.Getenv("LOCAL_PLATFORM"))
assert.Equal(t, expectedPlatform, determineLocalPlatform())

os.Setenv("LOCAL_PLATFORM", "darwin")
assert.Equal(t, "mac", determineLocalPlatform())

os.Setenv("LOCAL_PLATFORM", "windows")
assert.Equal(t, "windows", determineLocalPlatform())

os.Setenv("LOCAL_PLATFORM", "mydiyos")
assert.Equal(t, "mydiyos", determineLocalPlatform())
}

0 comments on commit 31321e3

Please sign in to comment.