From a5787edad6fc689f7bc34796660725bec451afb9 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Mon, 6 Apr 2026 08:41:18 +0100 Subject: [PATCH 01/20] A: made changes to Readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c2bec0368b7..5328243f080 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,5 @@ go build -o notely && ./notely *This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`. You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course! + +Dolamu's version of Boot.dev's Notely app \ No newline at end of file From 919f380d59a5b9b9c6d2e9011816428bccde3f7a Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Mon, 6 Apr 2026 09:13:06 +0100 Subject: [PATCH 02/20] B: Added workflow for CI-CD --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ README.md | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..6999c303b6c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: ci + +on: + pull_request: + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.26.0" + + - name: Force Failure + run: (exit 1) \ No newline at end of file diff --git a/README.md b/README.md index 5328243f080..8a15dc12686 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ go build -o notely && ./notely You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course! -Dolamu's version of Boot.dev's Notely app \ No newline at end of file +Dolamu's version of Boot.dev's Notely app From 8bbf9ae607b9f3a50d806238c8c5af9785f3d543 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Mon, 6 Apr 2026 09:51:42 +0100 Subject: [PATCH 03/20] C: Corrected Workflow script --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6999c303b6c..d84f0cf2a66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.26.0" - - name: Force Failure - run: (exit 1) \ No newline at end of file + - name: Check version of Go + run: go version \ No newline at end of file From 2ddf74d7e8bf894f0a7e9c952e37be8a9bed8dd1 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Mon, 6 Apr 2026 10:46:03 +0100 Subject: [PATCH 04/20] D: Added test code for auth function --- .github/workflows/ci.yml | 2 +- internal/auth/get_api_key_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 internal/auth/get_api_key_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d84f0cf2a66..d346f4288ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Check version of Go - run: go version \ No newline at end of file + run: go test ./... \ No newline at end of file diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go new file mode 100644 index 00000000000..4190d5043ce --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,29 @@ +package auth + +import ( + "testing" + "net/http" +) + +func TestGetAPIKey(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey rest-api-key") + got, err:= GetAPIKey(headers) + if got != "test-api-key" { + t.Error("Expected API key, got empty string") + } + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + if got == "my-api-key" { + t.Error("Expected API key, got a wrong string") + } +} + +func TestGetAPIKeyNoHeader(t *testing.T) { + headers := http.Header{} + _, err := GetAPIKey(headers) + if err != ErrNoAuthHeaderIncluded { + t.Errorf("Expected ErrNoAuthHeaderIncluded, got %v", err) + } +} From 9f6b0bf1cbc7cc23c70be1a81ffab2ee7d840e4c Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Mon, 6 Apr 2026 10:52:18 +0100 Subject: [PATCH 05/20] E: Corrected test code for auth function --- internal/auth/get_api_key_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go index 4190d5043ce..53a320ff28d 100644 --- a/internal/auth/get_api_key_test.go +++ b/internal/auth/get_api_key_test.go @@ -7,7 +7,7 @@ import ( func TestGetAPIKey(t *testing.T) { headers := http.Header{} - headers.Set("Authorization", "ApiKey rest-api-key") + headers.Set("Authorization", "ApiKey test-api-key") got, err:= GetAPIKey(headers) if got != "test-api-key" { t.Error("Expected API key, got empty string") From 144abeaf4a030b30be784fe26aef45a46efc31b2 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Mon, 6 Apr 2026 10:59:27 +0100 Subject: [PATCH 06/20] F: Added command to check code coverage in workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d346f4288ab..f7bbc54eee6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Check version of Go - run: go test ./... \ No newline at end of file + run: go test -cover ./... \ No newline at end of file From 3566ac499a237f6283845bf880e81aa8c8c8f500 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Mon, 6 Apr 2026 11:20:17 +0100 Subject: [PATCH 07/20] G: Added dynamic badge to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8a15dc12686..9ee3927914e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +https://github.com/Dolamu-TheDataGuy/learn-cicd-starter/actions/workflows/ci.yml/badge.svg +![test badge](https://github.com/Dolamu-TheDataGuy/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) # learn-cicd-starter (Notely) This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev). From a14120aeba13cc86816ef5c6348bf19854dbca03 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Mon, 6 Apr 2026 11:24:32 +0100 Subject: [PATCH 08/20] H: Revised README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9ee3927914e..fba58aad383 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -https://github.com/Dolamu-TheDataGuy/learn-cicd-starter/actions/workflows/ci.yml/badge.svg ![test badge](https://github.com/Dolamu-TheDataGuy/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) # learn-cicd-starter (Notely) From 56816b0ce630fb82e22dabb29d2bd0f85f47320e Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Thu, 9 Apr 2026 07:39:07 +0100 Subject: [PATCH 09/20] I: Formatted code files in repo --- internal/auth/get_api_key_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go index 53a320ff28d..b73944f8589 100644 --- a/internal/auth/get_api_key_test.go +++ b/internal/auth/get_api_key_test.go @@ -1,17 +1,17 @@ package auth import ( - "testing" "net/http" + "testing" ) func TestGetAPIKey(t *testing.T) { headers := http.Header{} headers.Set("Authorization", "ApiKey test-api-key") - got, err:= GetAPIKey(headers) + got, err := GetAPIKey(headers) if got != "test-api-key" { t.Error("Expected API key, got empty string") - } + } if err != nil { t.Errorf("Expected no error, got %v", err) } From 2aac554f25eddc5df9bd87f14c9169d6bb66018e Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Thu, 9 Apr 2026 07:52:04 +0100 Subject: [PATCH 10/20] J: Added job in workflow for code formatting --- .github/workflows/ci.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7bbc54eee6..c080785260c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,19 @@ jobs: go-version: "1.26.0" - name: Check version of Go - run: go test -cover ./... \ No newline at end of file + run: go test -cover ./... + style: + name: Style + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.26.0" + + - name: Check code style + run: test -z $(go fmt ./...) \ No newline at end of file From a776577a958ae6c54bd457c6f3011d170e3d0609 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Thu, 9 Apr 2026 08:40:55 +0100 Subject: [PATCH 11/20] K: Added steps for code linting in Style job under the CI-CD workflow --- .github/workflows/ci.yml | 2 ++ main.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c080785260c..14fec5885ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,5 +33,7 @@ jobs: with: go-version: "1.26.0" + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest - name: Check code style run: test -z $(go fmt ./...) \ No newline at end of file diff --git a/main.go b/main.go index 19d7366c5f7..e546112a05a 100644 --- a/main.go +++ b/main.go @@ -96,3 +96,8 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) } + +func unused() { + // this function does nothing + // and is called nowhere +} \ No newline at end of file From ff5b12329640b92cd277f3bbd31300eb9d2ffc7c Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Thu, 9 Apr 2026 08:43:19 +0100 Subject: [PATCH 12/20] L: Removed unused function --- .github/workflows/ci.yml | 5 ++++- main.go | 5 ----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14fec5885ca..ebf00fd4755 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,4 +36,7 @@ jobs: - name: Install staticcheck run: go install honnef.co/go/tools/cmd/staticcheck@latest - name: Check code style - run: test -z $(go fmt ./...) \ No newline at end of file + run: test -z $(go fmt ./...) + + - name: Check formatting + run: staticcheck ./... \ No newline at end of file diff --git a/main.go b/main.go index e546112a05a..19d7366c5f7 100644 --- a/main.go +++ b/main.go @@ -96,8 +96,3 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) } - -func unused() { - // this function does nothing - // and is called nowhere -} \ No newline at end of file From ce7e024c38968933e4794c7b5309a36790144559 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Fri, 10 Apr 2026 06:49:49 +0100 Subject: [PATCH 13/20] M: Added security step to style job --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebf00fd4755..7fb2b6ea741 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,4 +39,7 @@ jobs: run: test -z $(go fmt ./...) - name: Check formatting - run: staticcheck ./... \ No newline at end of file + run: staticcheck ./... + + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest \ No newline at end of file From d1afddadf6dcd4d6f48af4108e3c83d2e3bd3f3d Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Fri, 10 Apr 2026 07:30:55 +0100 Subject: [PATCH 14/20] N: Added security step to style job --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fb2b6ea741..5d3bac82556 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,4 +42,7 @@ jobs: run: staticcheck ./... - name: Install gosec - run: go install github.com/securego/gosec/v2/cmd/gosec@latest \ No newline at end of file + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Check security issues + run: gosec ./... \ No newline at end of file From 0e1b790613ee661c56b73e33e92f0352a236118a Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Fri, 10 Apr 2026 09:03:46 +0100 Subject: [PATCH 15/20] O: Corrected security flaws in code --- json.go | 6 +++--- main.go | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/json.go b/json.go index 1e6e7985e18..d5d5b88cc10 100644 --- a/json.go +++ b/json.go @@ -11,7 +11,7 @@ func respondWithError(w http.ResponseWriter, code int, msg string, logErr error) log.Println(logErr) } if code > 499 { - log.Printf("Responding with 5XX error: %s", msg) + log.Println("Responding with 5XX error:" + msg) } type errorResponse struct { Error string `json:"error"` @@ -25,10 +25,10 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { w.Header().Set("Content-Type", "application/json") dat, err := json.Marshal(payload) if err != nil { - log.Printf("Error marshalling JSON: %s", err) + log.Println("Error marshalling JSON: %s", err) w.WriteHeader(500) return } w.WriteHeader(code) - w.Write(dat) + _,err = w.Write(dat) } diff --git a/main.go b/main.go index 19d7366c5f7..813418128e3 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "embed" "io" "log" + "time" "net/http" "os" @@ -27,7 +28,7 @@ var staticFiles embed.FS func main() { err := godotenv.Load(".env") if err != nil { - log.Printf("warning: assuming default configuration. .env unreadable: %v", err) + log.Println("warning: assuming default configuration. .env unreadable:" + err.Error()) } port := os.Getenv("PORT") @@ -91,8 +92,9 @@ func main() { srv := &http.Server{ Addr: ":" + port, Handler: router, + ReadHeaderTimeout: 5 * time.Second, } - log.Printf("Serving on port: %s\n", port) + // log.Println("Serving on port:" + port) log.Fatal(srv.ListenAndServe()) } From b241d2362c18ad315adeaf7103e0ea41e03eb335 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Fri, 10 Apr 2026 09:08:35 +0100 Subject: [PATCH 16/20] P:Corrected Workflow bugs --- json.go | 6 +++++- main.go | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/json.go b/json.go index d5d5b88cc10..a9b9d081c0d 100644 --- a/json.go +++ b/json.go @@ -30,5 +30,9 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { return } w.WriteHeader(code) - _,err = w.Write(dat) + _, err = w.Write(dat) + if err != nil { + log.Printf("Critical error writing response: %s", err) + + } } diff --git a/main.go b/main.go index 813418128e3..076e53f7b6e 100644 --- a/main.go +++ b/main.go @@ -5,9 +5,9 @@ import ( "embed" "io" "log" - "time" "net/http" "os" + "time" "github.com/go-chi/chi" "github.com/go-chi/cors" @@ -90,8 +90,8 @@ func main() { router.Mount("/v1", v1Router) srv := &http.Server{ - Addr: ":" + port, - Handler: router, + Addr: ":" + port, + Handler: router, ReadHeaderTimeout: 5 * time.Second, } From 8c27f32222088c319f98df197bd5be150d6e2052 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Fri, 10 Apr 2026 09:11:21 +0100 Subject: [PATCH 17/20] Q:Corrected Workflow bugs --- json.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json.go b/json.go index a9b9d081c0d..b32c31cbdd5 100644 --- a/json.go +++ b/json.go @@ -25,7 +25,7 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { w.Header().Set("Content-Type", "application/json") dat, err := json.Marshal(payload) if err != nil { - log.Println("Error marshalling JSON: %s", err) + log.Printf("Error marshalling JSON: %s", err) w.WriteHeader(500) return } From e38ad66a73ba8a83f9ed2c4f8f732c8623ba8cd9 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Fri, 10 Apr 2026 09:17:37 +0100 Subject: [PATCH 18/20] R:Corrected Workflow bugs --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d3bac82556..4bfeef97435 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,9 @@ jobs: - name: Check version of Go run: go test -cover ./... + + - name: Check security issues + run: gosec ./... style: name: Style runs-on: ubuntu-latest @@ -44,5 +47,4 @@ jobs: - name: Install gosec run: go install github.com/securego/gosec/v2/cmd/gosec@latest - - name: Check security issues - run: gosec ./... \ No newline at end of file + \ No newline at end of file From 5a4e077f8cb6182c7ad1906c31839ca78d5a5b1e Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Fri, 10 Apr 2026 09:22:07 +0100 Subject: [PATCH 19/20] S:Corrected Workflow bugs --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bfeef97435..ba56c9df8f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,8 @@ jobs: - name: Check version of Go run: go test -cover ./... - + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest - name: Check security issues run: gosec ./... style: @@ -44,7 +45,6 @@ jobs: - name: Check formatting run: staticcheck ./... - - name: Install gosec - run: go install github.com/securego/gosec/v2/cmd/gosec@latest + \ No newline at end of file From 2ccc8527610b38a5182cbd77a8df0e14558d8478 Mon Sep 17 00:00:00 2001 From: Dolamu-TheDataGuy Date: Sat, 11 Apr 2026 12:43:20 +0100 Subject: [PATCH 20/20] T: Added workflow for continuous deployment --- .github/workflows/cd.yml | 24 ++++++++++++++++++++++++ .github/workflows/ci.yml | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000000..f9b2b077654 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,24 @@ +name: cd + +on: + push: + branches: [main] + + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.0" + + - name: Build app + run: ./scripts/buildprod.sh \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba56c9df8f7..c3b76695e61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Set up Go uses: actions/setup-go@v5