Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
contents: read

jobs:
build:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.2.2
Expand All @@ -32,6 +32,23 @@ jobs:
- name: Format
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi

build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}

- name: Setup Golang with cache
uses: actions/setup-go@v5.5.0
with:
go-version-file: go.mod
cache: false

- name: Build
run: go build -v ./...

Expand All @@ -41,9 +58,11 @@ jobs:
- name: Install sqlclosecheck
# TODO revert to github.com/ryanrolds/sqlclosecheck when https://github.com/ryanrolds/sqlclosecheck/pull/47 is merged
run: go install github.com/LeMikaelF/sqlclosecheck@b53ecaccb94623dfa6050e4ada4eeecd3a130829
env:
GOBIN: ${{ runner.temp }}/sqlclosecheck-bin

- name: sqlclosecheck
run: go vet -vettool=${HOME}/go/bin/sqlclosecheck ./...
run: go vet "-vettool=${{ runner.temp }}/sqlclosecheck-bin/sqlclosecheck" ./...

- name: Staticcheck
uses: dominikh/staticcheck-action@v1.4.1
Expand All @@ -56,4 +75,4 @@ jobs:
run: go test -v ./...

- name: Build Turso binary
run: go build -o turso cmd/turso/main.go
run: go build ./cmd/turso
15 changes: 14 additions & 1 deletion .goreleaser-self.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ before:
- go generate --tags=prod ./...
- ./script/completions.sh
builds:
- env:
- id: unix
env:
- CGO_ENABLED=0
goos:
- linux
Expand All @@ -18,6 +19,18 @@ builds:
main: ./cmd/turso
flags:
- -tags=prod
- id: windows
env:
- CGO_ENABLED=0
goos:
- windows
goarch:
- amd64
- arm64
binary: turso
main: ./cmd/turso
flags:
- -tags=prod

release:
github:
Expand Down
15 changes: 14 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ before:
- go generate --tags=prod ./...
- ./script/completions.sh
builds:
- env:
- id: unix
env:
- CGO_ENABLED=0
goos:
- linux
Expand All @@ -18,6 +19,18 @@ builds:
main: ./cmd/turso
flags:
- -tags=prod
- id: windows
env:
- CGO_ENABLED=0
goos:
- windows
goarch:
- amd64
- arm64
binary: turso
main: ./cmd/turso
flags:
- -tags=prod

release:
github:
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ turso db destroy <database name>
The `turso` program keeps settings in your local machine in the following base
directory in `turso/settings.json` file:

| OS | Config directory |
| ----- | ----------------------------------------- |
| Linux | `$XDG_CONFIG_HOME` or `$HOME/.config` |
| macOS | `$HOME/Library/Application Support/turso` |
| OS | Config directory |
| ------- | ----------------------------------------- |
| Linux | `$XDG_CONFIG_HOME` or `$HOME/.config` |
| macOS | `$HOME/Library/Application Support/turso` |
| Windows | `%APPDATA%\turso` |
18 changes: 0 additions & 18 deletions internal/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,3 @@ var updateCmd = &cobra.Command{
return Update()
},
}

func Update() error {
var updateCmd string

if IsUnderHomebrew() {
updateCmd = "brew update && brew upgrade turso"
} else {
updateCmd = "curl -sSfL \"https://get.tur.so/install.sh\" | sh"
}
command := exec.Command("sh", "-c", updateCmd)
command.Stdout = os.Stdout
command.Stderr = os.Stderr
err := command.Run()
if err != nil {
return fmt.Errorf("failed to execute update command: %w", err)
}
return nil
}
26 changes: 26 additions & 0 deletions internal/cmd/update_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:build !windows

package cmd

import (
"fmt"
"os"
"os/exec"
)

func Update() error {
var updateCmd string

if IsUnderHomebrew() {
updateCmd = "brew update && brew upgrade turso"
} else {
updateCmd = "curl -sSfL \"https://get.tur.so/install.sh\" | sh"
}
command := exec.Command("sh", "-c", updateCmd)
command.Stdout = os.Stdout
command.Stderr = os.Stderr
if err := command.Run(); err != nil {
return fmt.Errorf("failed to execute update command: %w", err)
}
return nil
}
13 changes: 13 additions & 0 deletions internal/cmd/update_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build windows

package cmd

import "errors"

func Update() error {
return errors.New(
"automatic updates are not available on Windows; " +
"download the latest Windows ZIP and replace turso.exe: " +
"https://github.com/tursodatabase/turso-cli/releases/latest",
)
}
3 changes: 1 addition & 2 deletions internal/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package settings
import (
"fmt"
"os"
"path"
"path/filepath"
"sync"

Expand Down Expand Up @@ -55,7 +54,7 @@ func ReadSettings() (*Settings, error) {
viper.SetConfigType("json")
viper.AddConfigPath(configPath)
viper.SetConfigPermissions(settingsFileMode)
configFile := path.Join(configPath, "settings.json")
configFile := filepath.Join(configPath, "settings.json")
if abs, err := filepath.Abs(configFile); err == nil {
configFile = abs
}
Expand Down
21 changes: 13 additions & 8 deletions internal/settings/settings_perm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package settings
import (
"os"
"path/filepath"
"runtime"
"testing"
)

Expand All @@ -20,12 +21,14 @@ func TestPersistTightensFilePermissions(t *testing.T) {
if err != nil {
t.Fatalf("stat after create: %v", err)
}
if got := st.Mode().Perm(); got != 0o600 {
t.Errorf("fresh file mode = %o, want 600", got)
}
stDir, _ := os.Stat(dir)
if got := stDir.Mode().Perm(); got != 0o700 {
t.Errorf("fresh dir mode = %o, want 700", got)
if runtime.GOOS != "windows" {
if got := st.Mode().Perm(); got != 0o600 {
t.Errorf("fresh file mode = %o, want 600", got)
}
stDir, _ := os.Stat(dir)
if got := stDir.Mode().Perm(); got != 0o700 {
t.Errorf("fresh dir mode = %o, want 700", got)
}
}

if err := os.Chmod(file, 0o644); err != nil {
Expand All @@ -39,7 +42,9 @@ func TestPersistTightensFilePermissions(t *testing.T) {
if err != nil {
t.Fatalf("stat after persist: %v", err)
}
if got := st.Mode().Perm(); got != 0o600 {
t.Errorf("file mode after persist = %o, want 600", got)
if runtime.GOOS != "windows" {
if got := st.Mode().Perm(); got != 0o600 {
t.Errorf("file mode after persist = %o, want 600", got)
}
}
}
Loading