Skip to content

Commit

Permalink
Add support for windows (#41)
Browse files Browse the repository at this point in the history
* don't run pruner in windows
* set k6binary name according to os
* test in windows
* close always binary after download
* document pruner is not enabled in Windows

---------

Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin authored Jan 29, 2025
1 parent 995433b commit b1c598c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
platform:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{matrix.platform}}
steps:
- name: Install Go
Expand Down
6 changes: 6 additions & 0 deletions k6binary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build !windows
// +build !windows

package k6provider

const k6Binary = "k6"
6 changes: 6 additions & 0 deletions k6binary_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build windows
// +build windows

package k6provider

const k6Binary = "k6.exe"
3 changes: 3 additions & 0 deletions lock.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !windows
// +build !windows

package k6provider

import (
Expand Down
3 changes: 3 additions & 0 deletions lock_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !windows
// +build !windows

package k6provider

import (
Expand Down
9 changes: 5 additions & 4 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
)

const (
k6Binary = "k6"
k6Module = "k6"
defaultPruneInterval = time.Hour
)
Expand Down Expand Up @@ -126,7 +125,10 @@ type Config struct {
BuildServiceAuth string
// BuildServiceHeaders HTTP headers for the k6 build service
BuildServiceHeaders map[string]string
// HighWaterMark is the upper limit of cache size to trigger a prune
// HighWaterMark is the upper limit of cache size to trigger a prune.
// If 0 (default) the cache is not pruned.
// This option is ignored when running in windows systems
// See https://github.com/grafana/k6provider/issues/42
HighWaterMark int64
// PruneInterval minimum time between prune attempts. Defaults to 1h
PruneInterval time.Duration
Expand Down Expand Up @@ -324,13 +326,12 @@ func (p *Provider) GetBinary(
}

err = p.downloader.download(ctx, artifact.URL, target)
_ = target.Close()
if err != nil {
_ = os.RemoveAll(artifactDir)
return K6Binary{}, NewWrappedError(ErrDownload, err)
}

_ = target.Close()

// start pruning in background
// TODO: handle case the calling process is cancelled
go p.pruner.Prune() //nolint:errcheck
Expand Down
3 changes: 3 additions & 0 deletions pruner.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !windows
// +build !windows

package k6provider

import (
Expand Down
3 changes: 3 additions & 0 deletions pruner_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !windows
// +build !windows

package k6provider

import (
Expand Down
26 changes: 26 additions & 0 deletions prunner_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:build windows
// +build windows

package k6provider

import (
"time"
)

// Fake implementation for windows
type Pruner struct{}

// NewPruner creates a [] given its high-water-mark limit, and the
// prune interval
func NewPruner(dir string, hwm int64, pruneInterval time.Duration) *Pruner {
return &Pruner{}
}

// Touch update access time because reading the file not always updates it
func (p *Pruner) Touch(binPath string) {
}

// Prune the cache of least recently used files
func (p *Pruner) Prune() error {
return nil
}

0 comments on commit b1c598c

Please sign in to comment.