Skip to content

Commit 7b86ce8

Browse files
committed
Fix UUID for Darwin hosts
- Addresses rs#100 based on fix suggested by @rpendleton - Adds multi-platform matrix run strategy to actions
1 parent 9d8d29f commit 7b86ce8

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

.github/workflows/go.yml

+18-12
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,30 @@ on:
1010

1111
jobs:
1212
test:
13-
name: Test
14-
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
platform: [ubuntu-latest, windows-latest, macos-13, macos-latest]
16+
name: Test - ${{ matrix.platform }}
17+
runs-on: ${{ matrix.platform }}
1518
steps:
16-
- uses: actions/checkout@v3
17-
- uses: actions/setup-go@v3
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-go@v5
1821
with:
19-
go-version: "1.18"
22+
go-version-file: "go.mod"
2023
check-latest: true
21-
- run: go test -race -failfast ./...
24+
- run: go vet ./... && go test -race -failfast ./...
2225
golangci-lint:
23-
name: golangci-lint
24-
runs-on: ubuntu-latest
26+
strategy:
27+
matrix:
28+
platform: [ ubuntu-latest, windows-latest, macos-13, macos-latest ]
29+
name: golangci-lint - ${{ matrix.platform }}
30+
runs-on: ${{ matrix.platform }}
2531
steps:
26-
- uses: actions/checkout@v3
27-
- uses: actions/setup-go@v3
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-go@v5
2834
with:
29-
go-version: "1.18"
35+
go-version-file: "go.mod"
3036
check-latest: true
31-
- uses: golangci/golangci-lint-action@v3
37+
- uses: golangci/golangci-lint-action@v6
3238
with:
3339
version: latest

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea
2+
/.vscode
3+
.DS_Store

hostid_darwin.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
1-
// +build darwin
1+
//go:build darwin
22

33
package xid
44

5-
import "syscall"
5+
import (
6+
"errors"
7+
"os/exec"
8+
"strings"
9+
)
610

711
func readPlatformMachineID() (string, error) {
8-
return syscall.Sysctl("kern.uuid")
12+
ioreg, err := exec.LookPath("ioreg")
13+
if err != nil {
14+
return "", err
15+
}
16+
17+
cmd := exec.Command(ioreg, "-rd1", "-c", "IOPlatformExpertDevice")
18+
out, err := cmd.CombinedOutput()
19+
if err != nil {
20+
return "", err
21+
}
22+
23+
for _, line := range strings.Split(string(out), "\n") {
24+
if strings.Contains(line, "IOPlatformUUID") {
25+
parts := strings.SplitAfter(line, `" = "`)
26+
if len(parts) == 2 {
27+
uuid := strings.TrimRight(parts[1], `"`)
28+
return strings.ToLower(uuid), nil
29+
}
30+
}
31+
}
32+
33+
return "", errors.New("cannot find host id")
934
}

0 commit comments

Comments
 (0)