mirror of
https://github.com/jeessy2/ddns-go.git
synced 2025-10-20 23:43:45 +08:00
fix(open_explorer): don't execute command on Termux (#718)
* fix(open_explorer): don't execute command on Termux * fix: build arm64 in the `test` CI
This commit is contained in:
14
.github/workflows/test.yml
vendored
14
.github/workflows/test.yml
vendored
@ -7,6 +7,9 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
goarch: [amd64, arm64]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@ -17,10 +20,15 @@ jobs:
|
|||||||
go-version-file: 'go.mod'
|
go-version-file: 'go.mod'
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make build test
|
run: |
|
||||||
|
# Run tests only when GOARCH is amd64, otherwize run builds only.
|
||||||
|
if [ "${{ matrix.goarch }}" = "amd64" ]; then
|
||||||
|
make build test
|
||||||
|
else
|
||||||
|
GOARCH=${{ matrix.goarch }} make build
|
||||||
|
fi
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ddns-go
|
name: ddns-go_${{ matrix.goarch }}
|
||||||
path: ddns-go
|
path: ddns-go
|
||||||
|
|||||||
@ -15,6 +15,12 @@ func OpenExplorer(url string) {
|
|||||||
case "darwin": // macOS
|
case "darwin": // macOS
|
||||||
cmd = exec.Command("open", url)
|
cmd = exec.Command("open", url)
|
||||||
default: // Linux
|
default: // Linux
|
||||||
|
// 如果在 Termux 中运行则停止,因为 exec.Command 可能会触发 SIGSYS: bad system call
|
||||||
|
// https://github.com/docker/compose/issues/10511#issuecomment-1531453435
|
||||||
|
if isTermux() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
cmd = exec.Command("xdg-open", url)
|
cmd = exec.Command("xdg-open", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
util/termux.go
Normal file
10
util/termux.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
// isTermux 是否在 Termux 中运行
|
||||||
|
//
|
||||||
|
// https://wiki.termux.com/wiki/Getting_started
|
||||||
|
func isTermux() bool {
|
||||||
|
return os.Getenv("PREFIX") == "/data/data/com.termux/files/usr"
|
||||||
|
}
|
||||||
23
util/termux_test.go
Normal file
23
util/termux_test.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestIsTermux 测试在或不在 Termux 中运行都能正确判断
|
||||||
|
func TestIsTermux(t *testing.T) {
|
||||||
|
// 模拟在 Termux 中运行
|
||||||
|
os.Setenv("PREFIX", "/data/data/com.termux/files/usr")
|
||||||
|
|
||||||
|
if !isTermux() {
|
||||||
|
t.Error("期待 isTermux 返回 true,但得到 false。")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清除 PREFIX 变量,模拟不在 Termux 中运行
|
||||||
|
os.Unsetenv("PREFIX")
|
||||||
|
|
||||||
|
if isTermux() {
|
||||||
|
t.Error("期待 isTermux 返回 false,但得到 true。")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user