From 4826917171264029da8c07f326e13c478f69afed Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 09:52:56 -0500 Subject: [PATCH 01/18] feat: add basic CI workflow for cf-driver-go --- .github/workflows/cf-driver-go.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/cf-driver-go.yml diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml new file mode 100644 index 0000000..73d4bb3 --- /dev/null +++ b/.github/workflows/cf-driver-go.yml @@ -0,0 +1,29 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: "CF Driver: Go Build & Test" + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: "./runner/cf-driver-go/go.mod" + + - name: Format + run: go fmt ./... + + - name: Vet + run: go vet ./... + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... From 351006365deb0a0b50c2044d83d60fe4e06a1270 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 09:59:36 -0500 Subject: [PATCH 02/18] fix: using the right file path would help --- .github/workflows/cf-driver-go.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 73d4bb3..374cf33 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -17,13 +17,13 @@ jobs: go-version-file: "./runner/cf-driver-go/go.mod" - name: Format - run: go fmt ./... + run: go fmt ./runner/cf-driver-go/... - name: Vet - run: go vet ./... + run: go vet ./runner/cf-driver-go/... - name: Build - run: go build -v ./... + run: go build -v ./runner/cf-driver-go/... - name: Test - run: go test -v ./... + run: go test -v ./runner/cf-driver-go/... From 85f52fbcd8508330021081ea1870fdde0f1e8652 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:04:16 -0500 Subject: [PATCH 03/18] fix: how about setting a working directory --- .github/workflows/cf-driver-go.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 374cf33..377fc5d 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -5,6 +5,10 @@ name: "CF Driver: Go Build & Test" on: [pull_request] +defaults: + run: + working-directory: runner/cf-driver-go + jobs: build: runs-on: ubuntu-latest @@ -17,13 +21,13 @@ jobs: go-version-file: "./runner/cf-driver-go/go.mod" - name: Format - run: go fmt ./runner/cf-driver-go/... + run: go fmt ./... - name: Vet - run: go vet ./runner/cf-driver-go/... + run: go vet ./... - name: Build - run: go build -v ./runner/cf-driver-go/... + run: go build -v ./... - name: Test - run: go test -v ./runner/cf-driver-go/... + run: go test -v ./... From b1c99bd1e960d7e8c98e52d05e74e53dd5b6db8f Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:10:42 -0500 Subject: [PATCH 04/18] feat: have the go fmt step check for diffs --- .github/workflows/cf-driver-go.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 377fc5d..2efd485 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -20,8 +20,8 @@ jobs: with: go-version-file: "./runner/cf-driver-go/go.mod" - - name: Format - run: go fmt ./... + - name: Check formatting + run: test -z $(gofmt -l ./...) - name: Vet run: go vet ./... From 3c16241a0b80d9aa941b62650ff103e7bb37b609 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:13:30 -0500 Subject: [PATCH 05/18] chore: spec a go version in case GitHub likes that better --- .github/workflows/cf-driver-go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 2efd485..5501124 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version-file: "./runner/cf-driver-go/go.mod" + go-version: "1.23.x" - name: Check formatting run: test -z $(gofmt -l ./...) From 7e6c19268b19e63adcfc0ec3f5547675c6fa61a0 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:14:54 -0500 Subject: [PATCH 06/18] chore: set a specific step to install deps This isolates dependency problems, could help caching --- .github/workflows/cf-driver-go.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index 5501124..e39e4b2 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -20,6 +20,9 @@ jobs: with: go-version: "1.23.x" + - name: Install dependencies + run: go get . + - name: Check formatting run: test -z $(gofmt -l ./...) From 3c637ee7a017886150e33297e360c0875c65cff4 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:17:26 -0500 Subject: [PATCH 07/18] fix: supply setup-go w/ go.sum path It was _not_ using the default working-directory --- .github/workflows/cf-driver-go.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index e39e4b2..c9242bf 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -19,6 +19,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: "1.23.x" + cache-dependency-path: runner/cf-driver-go/go.sum - name: Install dependencies run: go get . From 6f666d1c83eda99687729205c36d86c0aa0f1a3c Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:19:53 -0500 Subject: [PATCH 08/18] chore: test failing go fmt --- runner/cf-driver-go/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/main.go b/runner/cf-driver-go/main.go index 0c7f0aa..83f2991 100644 --- a/runner/cf-driver-go/main.go +++ b/runner/cf-driver-go/main.go @@ -22,7 +22,7 @@ func main() { }() if err := godotenv.Load(); err != nil { - panic("error loading .env file") + panic("error loading .env file") } cgClient, err := cg.New(&cg.GoCFClientAdapter{}, nil) From bbdf10ef4b2879963b61b0b311144d8b48725454 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:27:35 -0500 Subject: [PATCH 09/18] fix: gofmt doesn't take the ./... style arg --- .github/workflows/cf-driver-go.yml | 2 +- runner/cf-driver-go/cg/cg.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index c9242bf..cb302b4 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -25,7 +25,7 @@ jobs: run: go get . - name: Check formatting - run: test -z $(gofmt -l ./...) + run: test -z $(gofmt -l .) - name: Vet run: go vet ./... diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 082436d..65cb974 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -2,7 +2,7 @@ package cg type App struct { Id string - Name string + Name string State string } From 67eaca6f2541e062b1bc951a4b8806aa79a23a73 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:30:55 -0500 Subject: [PATCH 10/18] fix: foiled by quoting! --- .github/workflows/cf-driver-go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index cb302b4..f035b23 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -25,7 +25,7 @@ jobs: run: go get . - name: Check formatting - run: test -z $(gofmt -l .) + run: test -z "$(gofmt -l .)" - name: Vet run: go vet ./... From ec49c7a5fffabc00dcfe25774e3e296c074b2b24 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:32:09 -0500 Subject: [PATCH 11/18] chore: fix the formatting --- runner/cf-driver-go/cg/cg.go | 2 +- runner/cf-driver-go/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 65cb974..082436d 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -2,7 +2,7 @@ package cg type App struct { Id string - Name string + Name string State string } diff --git a/runner/cf-driver-go/main.go b/runner/cf-driver-go/main.go index 83f2991..0c7f0aa 100644 --- a/runner/cf-driver-go/main.go +++ b/runner/cf-driver-go/main.go @@ -22,7 +22,7 @@ func main() { }() if err := godotenv.Load(); err != nil { - panic("error loading .env file") + panic("error loading .env file") } cgClient, err := cg.New(&cg.GoCFClientAdapter{}, nil) From 9ced4bf508b4a921484ac826b54b4a2d1cdfe400 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:37:41 -0500 Subject: [PATCH 12/18] chore: validate that go vet will fail --- runner/cf-driver-go/cg/cg.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 082436d..5002a42 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -1,5 +1,7 @@ package cg +import "fmt" + type App struct { Id string Name string @@ -46,6 +48,8 @@ func New(i CloudI, o *Opts) (*CG, error) { } cg := &CG{i, o} return cg.Connect() + + fmt.Println("I am unreachable code!!") } func (c *CG) apiRootURL() string { From 0accd99ba86bdbb363170bba99b4b2c044b2a153 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:38:29 -0500 Subject: [PATCH 13/18] chore: remove my go vet break --- runner/cf-driver-go/cg/cg.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 5002a42..082436d 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -1,7 +1,5 @@ package cg -import "fmt" - type App struct { Id string Name string @@ -48,8 +46,6 @@ func New(i CloudI, o *Opts) (*CG, error) { } cg := &CG{i, o} return cg.Connect() - - fmt.Println("I am unreachable code!!") } func (c *CG) apiRootURL() string { From 9cc8c15044137b448e8544b77377e281d5e5e94f Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:40:29 -0500 Subject: [PATCH 14/18] chore: add a bug to validate test failure --- runner/cf-driver-go/cg/cg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index 082436d..cd2a7d8 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -50,7 +50,7 @@ func New(i CloudI, o *Opts) (*CG, error) { func (c *CG) apiRootURL() string { if c.APIRootURL == "" { - return apiRootURLDefault + return "cookies" } return c.APIRootURL } From 2c63af9c0b3703053a0396fa568b205c853d0df0 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:41:58 -0500 Subject: [PATCH 15/18] Revert "chore: add a bug to validate test failure" This reverts commit 9cc8c15044137b448e8544b77377e281d5e5e94f. --- runner/cf-driver-go/cg/cg.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/cg/cg.go b/runner/cf-driver-go/cg/cg.go index cd2a7d8..082436d 100644 --- a/runner/cf-driver-go/cg/cg.go +++ b/runner/cf-driver-go/cg/cg.go @@ -50,7 +50,7 @@ func New(i CloudI, o *Opts) (*CG, error) { func (c *CG) apiRootURL() string { if c.APIRootURL == "" { - return "cookies" + return apiRootURLDefault } return c.APIRootURL } From d4171a976cd449f109bf799884a7f33dc70567c0 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 10:55:26 -0500 Subject: [PATCH 16/18] feat: upgrade setup-go to v5 --- .github/workflows/cf-driver-go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index f035b23..a17526d 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: "1.23.x" cache-dependency-path: runner/cf-driver-go/go.sum From c6be94464a1cca737f1ea1dbe5b8fd365536ab02 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 11:00:13 -0500 Subject: [PATCH 17/18] feat: get go version for action from go.mod --- .github/workflows/cf-driver-go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cf-driver-go.yml b/.github/workflows/cf-driver-go.yml index a17526d..1a147f2 100644 --- a/.github/workflows/cf-driver-go.yml +++ b/.github/workflows/cf-driver-go.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.23.x" + go-version-file: runner/cf-driver-go/go.mod cache-dependency-path: runner/cf-driver-go/go.sum - name: Install dependencies From ae11c97eb6865745f7f3de970dae3ee327abdbe5 Mon Sep 17 00:00:00 2001 From: "Zachary J. Rollyson" Date: Wed, 18 Dec 2024 11:12:50 -0500 Subject: [PATCH 18/18] chore: not necessary to pin a patch version for go --- runner/cf-driver-go/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/cf-driver-go/go.mod b/runner/cf-driver-go/go.mod index 5a6cd5a..bb6b4f1 100644 --- a/runner/cf-driver-go/go.mod +++ b/runner/cf-driver-go/go.mod @@ -1,6 +1,6 @@ module github.com/GSA-TTS/gitlab-runner-cloudgov/runner/cf-driver -go 1.23.3 +go 1.23 require ( github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.9