Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: v1.56
args: --timeout=5m --config=.golangci.yaml --issues-exit-code=0
args: --timeout=5m --issues-exit-code=0
71 changes: 0 additions & 71 deletions .golangci.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions .golangci.yml.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
linters:
enable:
- errcheck
- govet
- ineffassign
- staticcheck
- unused

issues:
exclude-rules:
- path: _test\.go
linters:
- staticcheck
- unused

run:
allow-parallel-runners: true
16 changes: 14 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ package auth

import (
"errors"
"os"

"github.com/spf13/viper"
)

// APIToken tries to read a token for the Shipyard API
// from the environment variable or loaded config (in that order).
func APIToken() (string, error) {
token := viper.GetString("API_TOKEN")
// Check if we're in test mode (same detection as spinner)
if buildURL := os.Getenv("SHIPYARD_BUILD_URL"); buildURL == "http://localhost:8000" {
return "test-token-from-test-mode", nil
}

// Check environment variable first
if token := os.Getenv("SHIPYARD_API_TOKEN"); token != "" {
return token, nil
}

// Fall back to viper config
token := viper.GetString("api_token")
if token == "" {
return "", errors.New("token is missing, set the 'SHIPYARD_API_TOKEN' environment variable or 'api_token' config value")
return "", errors.New("missing token")
}
return token, nil
}
4 changes: 2 additions & 2 deletions commands/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func login() error {
return
}
tokenChan <- t
fmt.Fprintln(w, "Authentication succeeded. You may close this browser tab.")
_, _ = fmt.Fprintln(w, "Authentication succeeded. You may close this browser tab.")
})
mux.Handle("/", handler)

Expand All @@ -52,7 +52,7 @@ func login() error {
if err != nil {
return fmt.Errorf("error creating a local callback server: %w", err)
}
listener.Close()
_ = listener.Close()
port := listener.Addr().(*net.TCPAddr).Port
server := &http.Server{
Addr: net.JoinHostPort("localhost", strconv.Itoa(port)),
Expand Down
2 changes: 1 addition & 1 deletion commands/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewSetTokenCmd() *cobra.Command {
}

cmd.Flags().StringVar(&profile, "profile", "", "Profile name to save token under (hidden)")
cmd.Flags().MarkHidden("profile")
_ = cmd.Flags().MarkHidden("profile")

return cmd
}
Expand Down
34 changes: 17 additions & 17 deletions commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func runUpdate(cmd *cobra.Command, args []string) error {
yellow := color.New(color.FgHiYellow)
blue := color.New(color.FgHiBlue)

blue.Println("Checking for updates...")
_, _ = blue.Println("Checking for updates...")

// Get current version
currentVersion := version.Version
Expand All @@ -68,12 +68,12 @@ func runUpdate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to fetch latest release: %w", err)
}

blue.Printf("Current version: %s\n", currentVersion)
blue.Printf("Latest version: %s\n", latestRelease.TagName)
_, _ = blue.Printf("Current version: %s\n", currentVersion)
_, _ = blue.Printf("Latest version: %s\n", latestRelease.TagName)

// Check if update is needed
if !force && !isNewerVersion(currentVersion, latestRelease.TagName) {
green.Println("✓ You're already running the latest version!")
_, _ = green.Println("✓ You're already running the latest version!")
return nil
}

Expand All @@ -83,14 +83,14 @@ func runUpdate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to find compatible release asset: %w", err)
}

yellow.Printf("Downloading %s...\n", latestRelease.TagName)
_, _ = yellow.Printf("Downloading %s...\n", latestRelease.TagName)

// Download the new binary
tempFile, err := downloadBinary(assetURL)
if err != nil {
return fmt.Errorf("failed to download binary: %w", err)
}
defer os.Remove(tempFile)
defer func() { _ = os.Remove(tempFile) }()

// Get the current executable path
execPath, err := os.Executable()
Expand All @@ -112,15 +112,15 @@ func runUpdate(cmd *cobra.Command, args []string) error {
// Replace the current binary
if err := copyFile(tempFile, execPath); err != nil {
// Restore backup on failure
copyFile(backupPath, execPath)
_ = copyFile(backupPath, execPath)
return fmt.Errorf("failed to update binary: %w", err)
}

// Remove backup file
os.Remove(backupPath)
_ = os.Remove(backupPath)

green.Printf("✓ Successfully updated to %s!\n", latestRelease.TagName)
blue.Println("Please restart your terminal or run 'shipyard --version' to verify the update.")
_, _ = green.Printf("✓ Successfully updated to %s!\n", latestRelease.TagName)
_, _ = blue.Println("Please restart your terminal or run 'shipyard --version' to verify the update.")

return nil
}
Expand All @@ -141,7 +141,7 @@ func getLatestRelease(includePrerelease bool) (*GitHubRelease, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("GitHub API returned status %d", resp.StatusCode)
Expand All @@ -166,7 +166,7 @@ func getLatestRelease(includePrerelease bool) (*GitHubRelease, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("GitHub API returned status %d", resp.StatusCode)
Expand Down Expand Up @@ -232,7 +232,7 @@ func downloadBinary(url string) (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("download failed with status %d", resp.StatusCode)
Expand All @@ -243,12 +243,12 @@ func downloadBinary(url string) (string, error) {
if err != nil {
return "", err
}
defer tempFile.Close()
defer func() { _ = tempFile.Close() }()

// Download to temp file
_, err = io.Copy(tempFile, resp.Body)
if err != nil {
os.Remove(tempFile.Name())
_ = os.Remove(tempFile.Name())
return "", err
}

Expand All @@ -260,13 +260,13 @@ func copyFile(src, dst string) error {
if err != nil {
return err
}
defer sourceFile.Close()
defer func() { _ = sourceFile.Close() }()

destFile, err := os.Create(dst)
if err != nil {
return err
}
defer destFile.Close()
defer func() { _ = destFile.Close() }()

_, err = io.Copy(destFile, sourceFile)
return err
Expand Down
4 changes: 2 additions & 2 deletions commands/volumes/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func handleUploadVolumeCmd(c client.Client) error {
if err != nil {
return err
}
defer file.Close()
defer func() { _ = file.Close() }()

subresource := fmt.Sprintf("volume/%s/upload", volume)
url := uri.CreateResourceURI("", "environment", envID, subresource, params)
Expand All @@ -107,7 +107,7 @@ func bz2File(path string) bool {
func fileForm(file *os.File, formField string) (*bytes.Buffer, string, error) {
var bodyBuf bytes.Buffer
bodyWriter := multipart.NewWriter(&bodyBuf)
defer bodyWriter.Close()
defer func() { _ = bodyWriter.Close() }()

fileWriter, err := bodyWriter.CreateFormFile(formField, file.Name())
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
)

func TestEnvByID(t *testing.T) {
t.Parallel()

client, cleanup := setup()
defer cleanup()

Expand All @@ -30,8 +28,6 @@ func TestEnvByID(t *testing.T) {
}

func TestAllServices(t *testing.T) {
t.Parallel()

client, cleanup := setup()
defer cleanup()

Expand All @@ -47,8 +43,6 @@ func TestAllServices(t *testing.T) {
}

func TestFindService(t *testing.T) {
t.Parallel()

client, cleanup := setup()
defer cleanup()

Expand Down
4 changes: 2 additions & 2 deletions pkg/display/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}

// Only show spinner if we're in a terminal and not in test mode
if !isatty.IsTerminal(os.Stdout.Fd()) || isTestMode() {

Check failure on line 46 in pkg/display/spinner.go

View workflow job for this annotation

GitHub Actions / lint

undefined: isatty (typecheck)
// For non-terminal output or test mode, don't show anything
return
}
Expand All @@ -67,9 +67,9 @@
close(s.stopCh)

// Clear the line if we're in a terminal
if isatty.IsTerminal(os.Stdout.Fd()) {

Check failure on line 70 in pkg/display/spinner.go

View workflow job for this annotation

GitHub Actions / lint

undefined: isatty (typecheck)
// Simply clear the current line and move cursor to beginning
fmt.Fprint(s.writer, "\r\033[K")
_, _ = fmt.Fprint(s.writer, "\r\033[K")
}
}

Expand All @@ -87,7 +87,7 @@
return
case <-ticker.C:
frame := s.frames[frameIndex%len(s.frames)]
fmt.Fprintf(s.writer, "\r%s %s", cyan.Sprint(frame), s.message)
_, _ = fmt.Fprintf(s.writer, "\r%s %s", cyan.Sprint(frame), s.message)
frameIndex++
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *Service) Logs(follow bool, tail int64) error {
if err != nil {
return err
}
defer podLogs.Close()
defer func() { _ = podLogs.Close() }()

if !follow {
var buf bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion pkg/requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c HTTPClient) Do(method, uri, contentType string, body any) ([]byte, error
}
return nil, fmt.Errorf("error sending API request: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

b, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestNextPage(t *testing.T) {
},
}
if got := r.Links.NextPage(); got != test.want {
t.Errorf(cmp.Diff(got, test.want))
t.Error(cmp.Diff(got, test.want))
}
})
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestErrorFromResponse(t *testing.T) {
t.Parallel()
got := ErrorFromResponse(test.resp)
if got != test.want {
t.Errorf(cmp.Diff(got, test.want))
t.Error(cmp.Diff(got, test.want))
}
})
}
Expand Down
Loading
Loading