Skip to content

Commit

Permalink
Bump implementation to Go 1.18 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokiat authored Apr 4, 2022
1 parent 23d0f38 commit feb7130
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Go
uses: actions/[email protected]
with:
go-version: 1.16
go-version: 1.18

- name: Build
run: go build -o gocrane .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup Go
uses: actions/[email protected]
with:
go-version: 1.16
go-version: 1.18

- name: Build
run: go build -o gocrane .
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM golang:1.16 as builder
ENV GO111MODULE=on
FROM golang:1.18 as builder
COPY ./ /src/project
WORKDIR /src/project
RUN CGO_ENABLED=0 go build -o '/bin/gocrane' './'

FROM alpine:3.13
FROM alpine:3.15
COPY --from=builder /bin/gocrane /bin/gocrane
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The main purpose of gocrane is to be used within a `Docker` or `docker-compose`

### Using locally

To use the tool locally, you can get it as follows (Go 1.16+):
To use the tool locally, you can get it as follows (Go 1.18+):

```sh
go install github.com/mokiat/gocrane@latest
Expand Down
2 changes: 1 addition & 1 deletion example/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mokiat/gocrane:latest AS gocrane

FROM golang:1.16
FROM golang:1.18
COPY --from=gocrane /bin/gocrane /bin/gocrane
COPY . /src/project
WORKDIR /src/project
Expand Down
2 changes: 1 addition & 1 deletion example/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/mokiat/gocrane/example

go 1.15
go 1.18
18 changes: 15 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
module github.com/mokiat/gocrane

go 1.16
go 1.18

require (
github.com/fsnotify/fsnotify v1.4.9
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/onsi/ginkgo v1.15.0 // indirect
github.com/onsi/gomega v1.10.5 // indirect
github.com/onsi/ginkgo v1.15.0
github.com/onsi/gomega v1.10.5
github.com/satori/go.uuid v1.2.0
github.com/urfave/cli/v2 v2.3.0
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/nxadm/tail v1.4.4 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb // indirect
golang.org/x/sys v0.0.0-20210112080510-489259a85091 // indirect
golang.org/x/text v0.3.3 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down Expand Up @@ -58,7 +59,6 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -80,6 +80,7 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
6 changes: 3 additions & 3 deletions internal/command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func run(ctx context.Context, cfg runConfig) error {
}

log.Println("starting pipeline...")
changeEventQueue := make(pipeline.ChangeEventQueue, 1024)
batchChangeEventQueue := make(pipeline.ChangeEventQueue)
buildEventQueue := make(pipeline.BuildEventQueue)
changeEventQueue := make(pipeline.Queue[pipeline.ChangeEvent], 1024)
batchChangeEventQueue := make(pipeline.Queue[pipeline.ChangeEvent])
buildEventQueue := make(pipeline.Queue[pipeline.BuildEvent])

group, groupCtx := errgroup.WithContext(ctx)

Expand Down
4 changes: 2 additions & 2 deletions internal/pipeline/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

func Batch(
ctx context.Context,
in ChangeEventQueue,
out ChangeEventQueue,
in Queue[ChangeEvent],
out Queue[ChangeEvent],
batchDuration time.Duration,
) func() error {

Expand Down
4 changes: 2 additions & 2 deletions internal/pipeline/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func Build(
ctx context.Context,
mainDir string,
buildArgs []string,
in ChangeEventQueue,
out BuildEventQueue,
in Queue[ChangeEvent],
out Queue[BuildEvent],
rebuildFilter location.Filter,
restartFilter location.Filter,
bootstrapEvent *BuildEvent,
Expand Down
40 changes: 8 additions & 32 deletions internal/pipeline/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ package pipeline

import "context"

type ChangeEvent struct {
Paths []string
}

type ChangeEventQueue chan ChangeEvent
type Queue[T any] chan T

func (q ChangeEventQueue) Push(ctx context.Context, event ChangeEvent) bool {
func (q Queue[T]) Push(ctx context.Context, value T) bool {
select {
case <-ctx.Done():
return false
case q <- event:
case q <- value:
return true
}
}

func (q ChangeEventQueue) Pop(ctx context.Context, ptr *ChangeEvent) bool {
func (q Queue[T]) Pop(ctx context.Context, ptr *T) bool {
select {
case event, ok := <-q:
if !ok {
Expand All @@ -30,30 +26,10 @@ func (q ChangeEventQueue) Pop(ctx context.Context, ptr *ChangeEvent) bool {
}
}

type BuildEvent struct {
Path string
}

type BuildEventQueue chan BuildEvent

func (q BuildEventQueue) Push(ctx context.Context, event BuildEvent) bool {
select {
case <-ctx.Done():
return false
case q <- event:
return true
}
type ChangeEvent struct {
Paths []string
}

func (q BuildEventQueue) Pop(ctx context.Context, ptr *BuildEvent) bool {
select {
case event, ok := <-q:
if !ok {
return false
}
*ptr = event
return true
case <-ctx.Done():
return false
}
type BuildEvent struct {
Path string
}
80 changes: 10 additions & 70 deletions internal/pipeline/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ var _ = Describe("Event", func() {
closedCtx = ctx
})

Describe("ChangeEventQueue", func() {
Describe("Queue", func() {
var (
queue pipeline.ChangeEventQueue
event pipeline.ChangeEvent
queue pipeline.Queue[int]
event int
)

BeforeEach(func() {
queue = make(pipeline.ChangeEventQueue)
event = pipeline.ChangeEvent{
Paths: []string{"/path"},
}
queue = make(pipeline.Queue[int])
event = 132
})

Describe("Push", func() {
Expand All @@ -40,14 +38,14 @@ var _ = Describe("Event", func() {
})

It("accepts when there is a receiver", func() {
receivedEvents := make(chan pipeline.ChangeEvent)
receivedEvents := make(chan int)
go func() {
ev := <-queue
receivedEvents <- ev
}()
Expect(queue.Push(context.Background(), event)).To(BeTrue())

var receivedEvent pipeline.ChangeEvent
var receivedEvent int
Eventually(receivedEvents).Should(Receive(&receivedEvent))
Expect(receivedEvent).To(Equal(event))
})
Expand All @@ -59,77 +57,19 @@ var _ = Describe("Event", func() {
queue <- event
}()

var receivedEvent pipeline.ChangeEvent
var receivedEvent int
Expect(queue.Pop(context.Background(), &receivedEvent)).To(BeTrue())
Expect(receivedEvent).To(Equal(event))
})

It("returns when context is closed", func() {
var receivedEvent pipeline.ChangeEvent
var receivedEvent int
Expect(queue.Pop(closedCtx, &receivedEvent)).To(BeFalse())
})

It("returns when queue is closed", func() {
close(queue)
var receivedEvent pipeline.ChangeEvent
Expect(queue.Pop(context.Background(), &receivedEvent)).To(BeFalse())
})
})
})

Describe("BuildEventQueue", func() {
var (
queue pipeline.BuildEventQueue
event pipeline.BuildEvent
)

BeforeEach(func() {
queue = make(pipeline.BuildEventQueue)
event = pipeline.BuildEvent{
Path: "/path",
}
})

Describe("Push", func() {
It("returns when context is closed", func() {
Expect(queue.Push(closedCtx, event)).To(BeFalse())

Consistently(queue).ShouldNot(Receive())
})

It("accepts when there is a receiver", func() {
receivedEvents := make(chan pipeline.BuildEvent)
go func() {
ev := <-queue
receivedEvents <- ev
}()
Expect(queue.Push(context.Background(), event)).To(BeTrue())

var receivedEvent pipeline.BuildEvent
Eventually(receivedEvents).Should(Receive(&receivedEvent))
Expect(receivedEvent).To(Equal(event))
})
})

Describe("Pop", func() {
It("returns when there is a queued event", func() {
go func() {
queue <- event
}()

var receivedEvent pipeline.BuildEvent
Expect(queue.Pop(context.Background(), &receivedEvent)).To(BeTrue())
Expect(receivedEvent).To(Equal(event))
})

It("returns when context is closed", func() {
var receivedEvent pipeline.BuildEvent
Expect(queue.Pop(closedCtx, &receivedEvent)).To(BeFalse())
})

It("returns when queue is closed", func() {
close(queue)
var receivedEvent pipeline.BuildEvent
var receivedEvent int
Expect(queue.Pop(context.Background(), &receivedEvent)).To(BeFalse())
})
})
Expand Down
2 changes: 1 addition & 1 deletion internal/pipeline/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func Run(
ctx context.Context,
runArgs []string,
in BuildEventQueue,
in Queue[BuildEvent],
shutdownTimeout time.Duration,
) func() error {

Expand Down
2 changes: 1 addition & 1 deletion internal/pipeline/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Watch(
verbose bool,
dirs []string,
watchFilter location.Filter,
out ChangeEventQueue,
out Queue[ChangeEvent],
bootstrapEvent *ChangeEvent,

) func() error {
Expand Down

0 comments on commit feb7130

Please sign in to comment.