From f744996556604f5de0d6113257f7807bb084337a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tanguy=20=E2=A7=93=20Herrmann?= Date: Wed, 13 Apr 2022 16:30:28 +0200 Subject: [PATCH 1/4] docs: add simple Go guide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tanguy ⧓ Herrmann --- docs/guides/1228-go-ci.md | 33 +++++++++++++++++++ docs/plans/go-ci/hello/go.mod | 3 ++ docs/plans/go-ci/hello/greeting/greeting.go | 7 ++++ .../go-ci/hello/greeting/greeting_test.go | 13 ++++++++ docs/plans/go-ci/hello/main.go | 16 +++++++++ docs/plans/go-ci/plan.cue | 24 ++++++++++++++ 6 files changed, 96 insertions(+) create mode 100644 docs/guides/1228-go-ci.md create mode 100644 docs/plans/go-ci/hello/go.mod create mode 100644 docs/plans/go-ci/hello/greeting/greeting.go create mode 100644 docs/plans/go-ci/hello/greeting/greeting_test.go create mode 100644 docs/plans/go-ci/hello/main.go create mode 100644 docs/plans/go-ci/plan.cue diff --git a/docs/guides/1228-go-ci.md b/docs/guides/1228-go-ci.md new file mode 100644 index 00000000..2ee0d624 --- /dev/null +++ b/docs/guides/1228-go-ci.md @@ -0,0 +1,33 @@ +--- +slug: /1227/go-ci +displayed_sidebar: europa +--- + +# Go project CI + +We want to run some tests and build a Go project with the `go` cue package. + +## Plan + +The plan consist of 2 actions: + +- `test` for `go test` +- `build` for `go build` + +both use the [Go dagger package](https://github.com/dagger/dagger/tree/main/pkg/universe.dagger.io/go) + +```cue file=../plans/go-ci/plan.cue +``` + +## Go project + +The project is a simple program that takes `$NAME` environment variable, use the [Go greeting package](https://github.com/dagger/dagger/tree/main/docs/plans/go-ci/hello/greeting) to print the `greeting.Greet()` out. + +```go file=../plans/go-ci/hello/main.go +``` + +```go file=../plans/go-ci/hello/greeting/greeting.go +``` + +```go file=../plans/go-ci/hello/greeting/greeting_test.go +``` diff --git a/docs/plans/go-ci/hello/go.mod b/docs/plans/go-ci/hello/go.mod new file mode 100644 index 00000000..58103bd2 --- /dev/null +++ b/docs/plans/go-ci/hello/go.mod @@ -0,0 +1,3 @@ +module dagger.io/testgreetci + +go 1.17 diff --git a/docs/plans/go-ci/hello/greeting/greeting.go b/docs/plans/go-ci/hello/greeting/greeting.go new file mode 100644 index 00000000..b830aabf --- /dev/null +++ b/docs/plans/go-ci/hello/greeting/greeting.go @@ -0,0 +1,7 @@ +package greeting + +import "fmt" + +func Greeting(name string) string { + return fmt.Sprintf("Hi %s!", name) +} diff --git a/docs/plans/go-ci/hello/greeting/greeting_test.go b/docs/plans/go-ci/hello/greeting/greeting_test.go new file mode 100644 index 00000000..f2f2d812 --- /dev/null +++ b/docs/plans/go-ci/hello/greeting/greeting_test.go @@ -0,0 +1,13 @@ +package greeting + +import "testing" + +func TestGreeting(t *testing.T) { + name := "Dagger Test" + expect := "Hi Dagger Test!" + value := Greeting(name) + + if expect != value { + t.Fatalf("Hello(%s) = '%s', expected '%s'", name, value, expect) + } +} diff --git a/docs/plans/go-ci/hello/main.go b/docs/plans/go-ci/hello/main.go new file mode 100644 index 00000000..a18f5487 --- /dev/null +++ b/docs/plans/go-ci/hello/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "os" + + "dagger.io/testgreetci/greeting" +) + +func main() { + name := os.Getenv("NAME") + if name == "" { + name = "John Doe" + } + fmt.Printf(greeting.Greeting(name)) +} diff --git a/docs/plans/go-ci/plan.cue b/docs/plans/go-ci/plan.cue new file mode 100644 index 00000000..25c394ce --- /dev/null +++ b/docs/plans/go-ci/plan.cue @@ -0,0 +1,24 @@ +package main + +import ( + "dagger.io/dagger" + + "universe.dagger.io/go" + //"universe.dagger.io/bash" +) + +dagger.#Plan & { + client: filesystem: "./hello": read: contents: dagger.#FS + + actions: { + test: go.#Test & { + source: client.filesystem."./hello".read.contents + package: "./..." + } + + build: go.#Build & { + source: client.filesystem."./hello".read.contents + } + } + +} From d87c6430e31a56481d6fdf6af1b776ffb4c1c49c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tanguy=20=E2=A7=93=20Herrmann?= Date: Wed, 13 Apr 2022 17:36:27 +0200 Subject: [PATCH 2/4] docs: fix go-ci guide slug and add file title MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tanguy ⧓ Herrmann --- docs/guides/1228-go-ci.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/guides/1228-go-ci.md b/docs/guides/1228-go-ci.md index 2ee0d624..56e15711 100644 --- a/docs/guides/1228-go-ci.md +++ b/docs/guides/1228-go-ci.md @@ -1,5 +1,5 @@ --- -slug: /1227/go-ci +slug: /1228/go-ci displayed_sidebar: europa --- @@ -21,13 +21,13 @@ both use the [Go dagger package](https://github.com/dagger/dagger/tree/main/pkg/ ## Go project -The project is a simple program that takes `$NAME` environment variable, use the [Go greeting package](https://github.com/dagger/dagger/tree/main/docs/plans/go-ci/hello/greeting) to print the `greeting.Greet()` out. +The project is a simple program that takes `$NAME` environment variable, use the [Go greeting package](https://github.com/dagger/dagger/tree/main/docs/plans/go-ci/hello/greeting) to print the `greeting.Greeting()` out. -```go file=../plans/go-ci/hello/main.go +```go file=../plans/go-ci/hello/main.go title=hello/main.go ``` -```go file=../plans/go-ci/hello/greeting/greeting.go +```go file=../plans/go-ci/hello/greeting/greeting.go title=hello/greeting/greeting.go ``` -```go file=../plans/go-ci/hello/greeting/greeting_test.go +```go file=../plans/go-ci/hello/greeting/greeting_test.go title=hello/greeting/greeting_test.go ``` From ebec01e8e68251212cb5d23bdae2fa827162c86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tanguy=20=E2=A7=93=20Herrmann?= Date: Thu, 14 Apr 2022 13:06:23 +0200 Subject: [PATCH 3/4] docs: fix some PR suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tanguy ⧓ Herrmann --- docs/guides/1228-go-ci.md | 6 +++--- docs/plans/go-ci/plan.cue | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/guides/1228-go-ci.md b/docs/guides/1228-go-ci.md index 56e15711..c74082f6 100644 --- a/docs/guides/1228-go-ci.md +++ b/docs/guides/1228-go-ci.md @@ -1,11 +1,11 @@ --- slug: /1228/go-ci -displayed_sidebar: europa +displayed_sidebar: '0.2' --- -# Go project CI +# Testing and building a Go project -We want to run some tests and build a Go project with the `go` cue package. +This guide explains how to run some tests and build a Go project with the `go` cue package. ## Plan diff --git a/docs/plans/go-ci/plan.cue b/docs/plans/go-ci/plan.cue index 25c394ce..df33ab00 100644 --- a/docs/plans/go-ci/plan.cue +++ b/docs/plans/go-ci/plan.cue @@ -4,7 +4,6 @@ import ( "dagger.io/dagger" "universe.dagger.io/go" - //"universe.dagger.io/bash" ) dagger.#Plan & { From ab21b1b7bed633d8cb47d618aec626bc0657d4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tanguy=20=E2=A7=93=20Herrmann?= Date: Thu, 14 Apr 2022 16:20:39 +0200 Subject: [PATCH 4/4] docs: add to the sidebar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tanguy ⧓ Herrmann --- docs/guides/{1228-go-ci.md => 1229-go-ci.md} | 2 +- website/sidebars.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) rename docs/guides/{1228-go-ci.md => 1229-go-ci.md} (98%) diff --git a/docs/guides/1228-go-ci.md b/docs/guides/1229-go-ci.md similarity index 98% rename from docs/guides/1228-go-ci.md rename to docs/guides/1229-go-ci.md index c74082f6..f130e96a 100644 --- a/docs/guides/1228-go-ci.md +++ b/docs/guides/1229-go-ci.md @@ -1,5 +1,5 @@ --- -slug: /1228/go-ci +slug: /1229/go-ci displayed_sidebar: '0.2' --- diff --git a/website/sidebars.js b/website/sidebars.js index 764842af..eed893fb 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -55,6 +55,7 @@ module.exports = { "guides/pushing-plan-dependencies", "guides/handling-outputs", "guides/migrate-from-dagger-0.1", + "guides/go-ci", ], }, {