From 82c8a19c5439083fcfe5acbcc1fe79b49cbc5ea9 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Wed, 22 Jul 2026 08:49:08 +0300 Subject: [PATCH 01/19] chnaged README.md --- .idea/.gitignore | 10 ++++++++++ .idea/go.imports.xml | 10 ++++++++++ .idea/learn-cicd-starter.iml | 9 +++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ README.md | 2 ++ 6 files changed, 45 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/go.imports.xml create mode 100644 .idea/learn-cicd-starter.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..30cf57ed7c --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/go.imports.xml b/.idea/go.imports.xml new file mode 100644 index 0000000000..644cdf0bd2 --- /dev/null +++ b/.idea/go.imports.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/learn-cicd-starter.iml b/.idea/learn-cicd-starter.iml new file mode 100644 index 0000000000..5e764c4f0b --- /dev/null +++ b/.idea/learn-cicd-starter.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..d0adac68cd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..35eb1ddfbb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index c2bec0368b..ff0a2f7624 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! + +Anthony Tobi's version of Boot.dev's Notely app. \ No newline at end of file From 3678a6dfe54c91a3a980c70f16bb9d07dc9e46fe Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Thu, 23 Jul 2026 07:31:32 +0300 Subject: [PATCH 02/19] ADD: github/ci.yml --- .github/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/ci.yml diff --git a/.github/ci.yml b/.github/ci.yml new file mode 100644 index 0000000000..664032071d --- /dev/null +++ b/.github/ci.yml @@ -0,0 +1,22 @@ +name: ci + +on: + pull_request: + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.26.0" + + - name: Force Failure + run: (exit 1) \ No newline at end of file From 62a97bfb2d051501ecf512958ef8d62adfe1a142 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Thu, 23 Jul 2026 07:52:43 +0300 Subject: [PATCH 03/19] ADD: github/workflows/ci.yml --- .github/{ => workflows}/ci.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/ci.yml (100%) diff --git a/.github/ci.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/ci.yml rename to .github/workflows/ci.yml From 9e4fa985beea62b772037be00e44891de1a0a373 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Thu, 23 Jul 2026 07:59:06 +0300 Subject: [PATCH 04/19] FIX: github/workflows/ci.yml --- .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 664032071d..2942aa6a3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Force Failure - run: (exit 1) \ No newline at end of file + run: (exit 0) \ No newline at end of file From 90b7f4d27222284d26f0a670338d621ac01c078d Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Sat, 25 Jul 2026 17:11:58 +0300 Subject: [PATCH 05/19] test ci for failing unit tests --- .github/workflows/ci.yml | 2 +- internal/auth/get_api_key_test.go | 67 +++++++++++++++++++++++++++++++ 2 files changed, 68 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 2942aa6a3a..26587862b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Force Failure - run: (exit 0) \ 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 0000000000..99fba8241c --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,67 @@ +package auth + +import ( + "errors" + "net/http" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + headers http.Header + expectedKey string + expectedError error + }{ + { + name: "Valid header", + headers: http.Header{"Authorization": []string{"ApiKey my-secret-key"}}, + expectedKey: "my-secret-key", + expectedError: nil, + }, + { + name: "Missing Authorization header", + headers: http.Header{}, + expectedKey: "my-secret-key", + expectedError: ErrNoAuthHeaderIncluded, + }, + { + name: "Empty Authorization header", + headers: http.Header{"Authorization": []string{""}}, + expectedKey: "", + expectedError: ErrNoAuthHeaderIncluded, + }, + { + name: "Malformed Authorization header - no space separator", + headers: http.Header{"Authorization": []string{"ApiKey-my-secret-key"}}, + expectedKey: "", + expectedError: errors.New("malformed authorization header"), + }, + { + name: "Malformed Authorization header - no ApiKey keyword", + headers: http.Header{"Authorization": []string{"Bearer my-secret-key"}}, + expectedKey: "", + expectedError: errors.New("malformed authorization header"), + }, + { + name: "Malformed Authorization header - no key provided", + headers: http.Header{"Authorization": []string{"ApiKey"}}, + expectedKey: "", + expectedError: errors.New("malformed authorization header"), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + key, err := GetAPIKey(tt.headers) + + if key != tt.expectedKey { + t.Errorf("expected key: %v, got: %v", tt.expectedKey, key) + } + + if (err != nil && tt.expectedError == nil) || (err == nil && tt.expectedError != nil) || (err != nil && tt.expectedError != nil && err.Error() != tt.expectedError.Error()) { + t.Errorf("expected error: %v, got: %v", tt.expectedError, err) + } + }) + } +} From 79c37152e095f5ca9fe46ca3cc61965763eae51f Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Sat, 25 Jul 2026 17:14:25 +0300 Subject: [PATCH 06/19] TEST: unit tests for get api key func --- 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 99fba8241c..4b102474e1 100644 --- a/internal/auth/get_api_key_test.go +++ b/internal/auth/get_api_key_test.go @@ -22,7 +22,7 @@ func TestGetAPIKey(t *testing.T) { { name: "Missing Authorization header", headers: http.Header{}, - expectedKey: "my-secret-key", + expectedKey: "", expectedError: ErrNoAuthHeaderIncluded, }, { From e1f5117bc2a6af876fd31d36a85d07ecc25302f0 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Sat, 25 Jul 2026 17:26:18 +0300 Subject: [PATCH 07/19] REFACTOR: CI to run go test -cover ./... --- .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 26587862b4..98a1b1e27b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Force Failure - run: go test ./... \ No newline at end of file + run: go test -cover ./... \ No newline at end of file From 22abb43313dbfeedaf2cf78f25c2831dd481e82e Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Sat, 25 Jul 2026 17:41:49 +0300 Subject: [PATCH 08/19] ADD: CI badge to read.ME on github --- .github/workflows/ci.yml | 2 +- README.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98a1b1e27b..82c4ea8674 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 + - name: Run Unit tests run: go test -cover ./... \ No newline at end of file diff --git a/README.md b/README.md index ff0a2f7624..af9cba268b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # learn-cicd-starter (Notely) +![CI](https://github.com/anthonytobiesq/learn-cicd-starter/actions/workflows/ci.yml/badge.svg) This repo contains the starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev). @@ -22,4 +23,5 @@ 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! -Anthony Tobi's version of Boot.dev's Notely app. \ No newline at end of file +Anthony Tobi's version of Boot.dev's Notely app. + From 09769d87d9db27eefe8751d9b08ee379255bb980 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Sun, 26 Jul 2026 09:53:11 +0300 Subject: [PATCH 09/19] ADD: style job in CI --- .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 82c4ea8674..e181a453ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,19 @@ jobs: go-version: "1.26.0" - name: Run Unit tests - run: go test -cover ./... \ No newline at end of file + run: go test -cover ./... + style: + name: Style + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.26.0" + + - name: Run Style checks + run: test -z $(go fmt ./...) \ No newline at end of file From c26cd6e7d011a052bca50a3801cc7a4a232b643b Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Sun, 26 Jul 2026 10:11:46 +0300 Subject: [PATCH 10/19] ADD: linter support with staticheck in CI --- .github/workflows/ci.yml | 5 ++++- main.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e181a453ac..98e6d86ea1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,4 +34,7 @@ jobs: go-version: "1.26.0" - name: Run Style checks - run: test -z $(go fmt ./...) \ No newline at end of file + run: test -z $(go fmt ./...) + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest \ No newline at end of file diff --git a/main.go b/main.go index 19d7366c5f..a621713c2b 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 +} From 2399430eb2b6878978a369cf3e48a8cfa98f2e8e Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Sun, 26 Jul 2026 10:24:17 +0300 Subject: [PATCH 11/19] FIX: linter support with staticheck in CI --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98e6d86ea1..2803880246 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,8 +33,13 @@ jobs: with: go-version: "1.26.0" + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + - name: Run Style checks run: test -z $(go fmt ./...) - - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@latest \ No newline at end of file + - name: Run Static checks + run: staticcheck ./... + + From 9f7851a8d4092baa60b6c44d5cbc7470cd98e116 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Sun, 26 Jul 2026 10:27:37 +0300 Subject: [PATCH 12/19] FIX: remove unused func in main.go caught by staticheck --- main.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.go b/main.go index a621713c2b..19d7366c5f 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 -} From d8eb146bb248bb0d46a377a542e416a222cce39f Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Mon, 3 Aug 2026 05:54:06 +0300 Subject: [PATCH 13/19] ADD: gosec to ci --- .github/workflows/ci.yml | 7 +++++++ .idea/learn-cicd-starter.iml | 1 + 2 files changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2803880246..a5057f985d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,13 @@ jobs: - name: Run Unit tests run: go test -cover ./... + + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Run Security checks + run: gosec ./... + style: name: Style runs-on: ubuntu-latest diff --git a/.idea/learn-cicd-starter.iml b/.idea/learn-cicd-starter.iml index 5e764c4f0b..9c408ccfbd 100644 --- a/.idea/learn-cicd-starter.iml +++ b/.idea/learn-cicd-starter.iml @@ -1,6 +1,7 @@ + From 1d7a41aa32ed04b8730989a18f4270c90c728358 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Mon, 3 Aug 2026 06:15:09 +0300 Subject: [PATCH 14/19] FIX: gosec ERRORS: main.go, json.go --- json.go | 6 +++++- main.go | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/json.go b/json.go index 1e6e7985e1..81a66b64c3 100644 --- a/json.go +++ b/json.go @@ -30,5 +30,9 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { return } w.WriteHeader(code) - w.Write(dat) + _, err = w.Write(dat) + if err != nil { + log.Printf("Error writing response: %s", err) + return + } } diff --git a/main.go b/main.go index 19d7366c5f..6b59c2cc5b 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,8 @@ import ( "log" "net/http" "os" + "strconv" + "time" "github.com/go-chi/chi" "github.com/go-chi/cors" @@ -89,10 +91,18 @@ func main() { router.Mount("/v1", v1Router) srv := &http.Server{ - Addr: ":" + port, - Handler: router, + Addr: ":" + port, + Handler: router, + ReadHeaderTimeout: 5 * time.Second, // Fixes G112: Prevents Slowloris attacks + ReadTimeout: 10 * time.Second, // Recommended production hygiene + WriteTimeout: 10 * time.Second, + IdleTimeout: 120 * time.Second, } - log.Printf("Serving on port: %s\n", port) + portNum, err := strconv.Atoi(port) + if err != nil { + log.Fatalf("Invalid PORT: %v", err) + } + log.Printf("Serving on port: %d\n", portNum) log.Fatal(srv.ListenAndServe()) } From 6d8319984cce9b3b393d4a60a8f94949a8eea111 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Mon, 3 Aug 2026 06:44:19 +0300 Subject: [PATCH 15/19] ADD: cd.yaml --- .github/workflows/cd.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000000..a38161216e --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,22 @@ +name: cd + +on: + push: + branches: [ main ] + +jobs: + deploy: + name: deploy + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v6 + + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: "1.26.0" + + - name: Build app + run: ./scripts/buildprod.sh \ No newline at end of file From 6618570a9ed2060637954c82833c2343ce005027 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Mon, 3 Aug 2026 06:58:07 +0300 Subject: [PATCH 16/19] Refactor: cd.yaml chnage job name to Deploy --- .github/workflows/cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a38161216e..12bff1ab16 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -6,7 +6,7 @@ on: jobs: deploy: - name: deploy + name: Deploy runs-on: ubuntu-latest steps: From cd0719509969c727bf7187fcdd991e61b567b75a Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Mon, 3 Aug 2026 15:13:56 +0300 Subject: [PATCH 17/19] ADD: gcloud cli support, push docker image, artifact registry --- .github/workflows/cd.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 12bff1ab16..a106cc2175 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -19,4 +19,18 @@ jobs: go-version: "1.26.0" - name: Build app - run: ./scripts/buildprod.sh \ No newline at end of file + run: ./scripts/buildprod.sh + + - id: 'auth' + uses: 'google-github-actions/auth@v2' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + + - name: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v3' + + - name: 'Use gcloud CLI' + run: 'gcloud info' + + - name: Build and push Docker image + run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-504410/notely-ar-repo/anthonytobiesqdev/notely:latest . \ No newline at end of file From 148ebf2f31051e26d13ef96423ab88d9d0fc7f44 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Tue, 4 Aug 2026 07:56:52 +0300 Subject: [PATCH 18/19] CHANGE H1 TO TEST CD --- .github/workflows/cd.yml | 5 ++++- static/index.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a106cc2175..5c23c3e258 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -33,4 +33,7 @@ jobs: run: 'gcloud info' - name: Build and push Docker image - run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-504410/notely-ar-repo/anthonytobiesqdev/notely:latest . \ No newline at end of file + run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-504410/notely-ar-repo/anthonytobiesqdev/notely:latest . + + - name: Deploy to Cloud Run + run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-504410/notely-ar-repo/anthonytobiesqdev/notely:latest --region us-central1 --allow-unauthenticated --project notely-504410 --max-instances=4 \ No newline at end of file diff --git a/static/index.html b/static/index.html index 72be101028..5d4ad73c09 100644 --- a/static/index.html +++ b/static/index.html @@ -7,7 +7,7 @@ -

Notely

+

Welcome to Notely

From b1b574f1570aacfabe3b4254d5af8f49806c9017 Mon Sep 17 00:00:00 2001 From: anthonytobiesq Date: Tue, 4 Aug 2026 11:05:22 +0300 Subject: [PATCH 19/19] ADD: persistence with Turbo, add tables via goose migrations script, add steps to CD yaml --- .github/workflows/cd.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 5c23c3e258..013d242156 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -8,6 +8,8 @@ jobs: deploy: name: Deploy runs-on: ubuntu-latest + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} steps: - name: Check out code @@ -32,8 +34,17 @@ jobs: - name: 'Use gcloud CLI' run: 'gcloud info' + + - name: Install goose + run: go install github.com/pressly/goose/v3/cmd/goose@latest + + - name: Run migrations + run: ./scripts/migrateup.sh + + - name: Build and push Docker image run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-504410/notely-ar-repo/anthonytobiesqdev/notely:latest . - name: Deploy to Cloud Run - run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-504410/notely-ar-repo/anthonytobiesqdev/notely:latest --region us-central1 --allow-unauthenticated --project notely-504410 --max-instances=4 \ No newline at end of file + run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-504410/notely-ar-repo/anthonytobiesqdev/notely:latest --region us-central1 --allow-unauthenticated --project notely-504410 --max-instances=4 +