From d1610573f43117313c770d8f44200666cc61004f Mon Sep 17 00:00:00 2001 From: Marun Date: Mon, 24 Aug 2026 11:01:31 +0200 Subject: [PATCH 01/21] little change --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c2bec0368b7..f79507e8e32 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! + +Marun's version of Boot.dev's Notely app. \ No newline at end of file From beb5e05691603e548d50989945cecc488127e1f8 Mon Sep 17 00:00:00 2001 From: Marun Date: Mon, 24 Aug 2026 11:11:32 +0200 Subject: [PATCH 02/21] ci file and github dir to repo --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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..664032071d1 --- /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: 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 37dafb94bf81cd2f6c2fe3c79bbb790bdffe040b Mon Sep 17 00:00:00 2001 From: Marun Date: Mon, 24 Aug 2026 11:15:50 +0200 Subject: [PATCH 03/21] changed the force failure --- .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 664032071d1..ebc93c76621 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: Get Go version + run: go version \ No newline at end of file From b432aba333b7251072633aff89016ba4de39e6a9 Mon Sep 17 00:00:00 2001 From: Marun Date: Tue, 25 Aug 2026 12:10:26 +0200 Subject: [PATCH 04/21] tests and ci test --- .github/workflows/ci.yml | 2 +- internal/auth/auth.go | 2 +- internal/auth/get_api_key_test.go | 62 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 internal/auth/get_api_key_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebc93c76621..d1f46976dc2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Get Go version - run: go version \ No newline at end of file + run: go test ./... \ No newline at end of file diff --git a/internal/auth/auth.go b/internal/auth/auth.go index f969aacf638..117eec66452 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -19,5 +19,5 @@ func GetAPIKey(headers http.Header) (string, error) { return "", errors.New("malformed authorization header") } - return splitAuth[1], nil + return splitAuth[0], nil } diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go new file mode 100644 index 00000000000..03ffdae7aea --- /dev/null +++ b/internal/auth/get_api_key_test.go @@ -0,0 +1,62 @@ +package auth + +import ( + "fmt" + "net/http" + "strings" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + key string + value string + expect string + expectErr string + }{ + { + expectErr: "no authorization header", + }, + { + key: "Authorization", + expectErr: "no authorization header", + }, + { + key: "Authorization", + value: "-", + expectErr: "malformed authorization header", + }, + { + key: "Authorization", + value: "Bearer xxxxxx", + expectErr: "malformed authorization header", + }, + { + key: "Authorization", + value: "ApiKey xxxxxx", + expect: "xxxxxx", + expectErr: "not expecting an error", + }, + } + + for i, test := range tests { + t.Run(fmt.Sprintf("TestGetAPIKey Case #%v:", i), func(t *testing.T){ + header := http.Header{} + header.Add(test.key, test.value) + + output, err := GetAPIKey(header) + if err != nil { + if strings.Contains(err.Error(), test.expectErr) { + return + } + t.Errorf("Unexpected: TestGetAPIKey:%v\n", err) + return + } + + if output != test.expect { + t.Errorf("Unexpected: TestGetAPIKey:%s", output) + return + } + }) + } +} \ No newline at end of file From 7301f6f6e2f173c2a170d82339a10a75d7c66a52 Mon Sep 17 00:00:00 2001 From: Marun Date: Tue, 25 Aug 2026 12:12:19 +0200 Subject: [PATCH 05/21] fixed the failed tests --- internal/auth/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 117eec66452..f969aacf638 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -19,5 +19,5 @@ func GetAPIKey(headers http.Header) (string, error) { return "", errors.New("malformed authorization header") } - return splitAuth[0], nil + return splitAuth[1], nil } From e11f46df4a5f20a5b702c32d0b2383a189847a90 Mon Sep 17 00:00:00 2001 From: Marun Date: Tue, 25 Aug 2026 14:32:04 +0200 Subject: [PATCH 06/21] added coverage to ci --- .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 d1f46976dc2..e6548f75541 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.26.0" - name: Get Go version - run: go test ./... \ No newline at end of file + run: go test -cover ./... \ No newline at end of file From bd250f35e0c2e1a41a915a206fc8a4b15b3d3937 Mon Sep 17 00:00:00 2001 From: Marun Date: Tue, 25 Aug 2026 14:42:21 +0200 Subject: [PATCH 07/21] add badge for tests status --- .github/workflows/ci.yml | 2 +- README.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6548f75541..bc50742d9b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.26.0" - - name: Get Go version + - name: Test Go code with coverage run: go test -cover ./... \ No newline at end of file diff --git a/README.md b/README.md index f79507e8e32..8ced62c4e4f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![Test badge](https://github.com/MarunDArbaumont/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 ca92b39405938813308ba9b4ce4f0c185f951ae6 Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 27 Aug 2026 12:01:21 +0200 Subject: [PATCH 08/21] added formatting check on ci --- .github/workflows/ci.yml | 18 +++++++++++++++++- internal/auth/get_api_key_test.go | 28 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc50742d9b8..740d3eaea38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,20 @@ jobs: go-version: "1.26.0" - name: Test Go code with coverage - 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: Check code formatting + run: test -z $(go fmt ./...) \ No newline at end of file diff --git a/internal/auth/get_api_key_test.go b/internal/auth/get_api_key_test.go index 03ffdae7aea..5ac1cd99d36 100644 --- a/internal/auth/get_api_key_test.go +++ b/internal/auth/get_api_key_test.go @@ -9,38 +9,38 @@ import ( func TestGetAPIKey(t *testing.T) { tests := []struct { - key string - value string - expect string - expectErr string + key string + value string + expect string + expectErr string }{ { expectErr: "no authorization header", }, { - key: "Authorization", + key: "Authorization", expectErr: "no authorization header", }, { - key: "Authorization", - value: "-", + key: "Authorization", + value: "-", expectErr: "malformed authorization header", }, { - key: "Authorization", - value: "Bearer xxxxxx", + key: "Authorization", + value: "Bearer xxxxxx", expectErr: "malformed authorization header", }, { - key: "Authorization", - value: "ApiKey xxxxxx", - expect: "xxxxxx", + key: "Authorization", + value: "ApiKey xxxxxx", + expect: "xxxxxx", expectErr: "not expecting an error", }, } for i, test := range tests { - t.Run(fmt.Sprintf("TestGetAPIKey Case #%v:", i), func(t *testing.T){ + t.Run(fmt.Sprintf("TestGetAPIKey Case #%v:", i), func(t *testing.T) { header := http.Header{} header.Add(test.key, test.value) @@ -59,4 +59,4 @@ func TestGetAPIKey(t *testing.T) { } }) } -} \ No newline at end of file +} From 474055c267bafa307125017f616674158dafddd6 Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 27 Aug 2026 12:54:30 +0200 Subject: [PATCH 09/21] linting check with error to test --- .github/workflows/ci.yml | 8 +++++++- main.go | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 740d3eaea38..60bb2d4aad6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,4 +35,10 @@ jobs: go-version: "1.26.0" - name: Check code formatting - 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 + + - name: Check code for linting errors + run: staticcheck ./... \ 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 a8b8d224b094be654e52b9bb35f71f80c26b4ad3 Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 27 Aug 2026 12:56:48 +0200 Subject: [PATCH 10/21] forgot white space --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index e546112a05a..a621713c2bd 100644 --- a/main.go +++ b/main.go @@ -98,6 +98,6 @@ func main() { } func unused() { - // this function does nothing - // and is called nowhere -} \ No newline at end of file + // this function does nothing + // and is called nowhere +} From 43c0195f20a3847249e09a9f772b5aa29a4f6c46 Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 27 Aug 2026 12:58:15 +0200 Subject: [PATCH 11/21] fixed the error --- main.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.go b/main.go index a621713c2bd..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 -} From 8075287dfb5abb190bba780da112dc0751cdeafd Mon Sep 17 00:00:00 2001 From: Marun Date: Tue, 1 Sep 2026 09:37:55 +0200 Subject: [PATCH 12/21] add gosec check to ci --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60bb2d4aad6..f7193d7e497 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,12 @@ jobs: - name: Test Go code with coverage run: go test -cover ./... + + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Security check + run: gosec ./... style: name: Style From db26eccb98e304d8e7553045fa6f026269d45194 Mon Sep 17 00:00:00 2001 From: Marun Date: Tue, 1 Sep 2026 09:47:52 +0200 Subject: [PATCH 13/21] fixed the securtiy errors --- json.go | 7 ++++++- main.go | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/json.go b/json.go index 1e6e7985e18..3e0cd76a11a 100644 --- a/json.go +++ b/json.go @@ -30,5 +30,10 @@ 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 data: %s", err) + w.WriteHeader(500) + return + } } diff --git a/main.go b/main.go index 19d7366c5f7..ad57b5727a0 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "time" "github.com/go-chi/chi" "github.com/go-chi/cors" @@ -89,10 +90,10 @@ func main() { router.Mount("/v1", v1Router) srv := &http.Server{ - Addr: ":" + port, - Handler: router, + Addr: ":" + port, + Handler: router, + ReadTimeout: 15 * time.Second, } - log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) } From 7ec0c9f855a40277e324771b89538a27506a6154 Mon Sep 17 00:00:00 2001 From: Marun Date: Tue, 1 Sep 2026 11:05:16 +0200 Subject: [PATCH 14/21] added cd --- .github/workflows/cd.yml | 20 ++++++++++++++++++++ json.go | 4 +--- main.go | 3 ++- 3 files changed, 23 insertions(+), 4 deletions(-) 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..ba1bd923f04 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,20 @@ +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 diff --git a/json.go b/json.go index 3e0cd76a11a..c529c90c124 100644 --- a/json.go +++ b/json.go @@ -32,8 +32,6 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { w.WriteHeader(code) _, err = w.Write(dat) if err != nil { - log.Printf("Error writing data: %s", err) - w.WriteHeader(500) - return + log.Printf("Critical error writing response: %s", err) } } diff --git a/main.go b/main.go index ad57b5727a0..2471bb07bc3 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "os" + "strconv" "time" "github.com/go-chi/chi" @@ -94,6 +95,6 @@ func main() { Handler: router, ReadTimeout: 15 * time.Second, } - + log.Printf("Serving on port: %s", strconv.Quote(port)) log.Fatal(srv.ListenAndServe()) } From 14a9384339348d8a637ef085759d298870dd5c9e Mon Sep 17 00:00:00 2001 From: Marun Date: Tue, 1 Sep 2026 11:09:16 +0200 Subject: [PATCH 15/21] forgot to tab --- .github/workflows/cd.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ba1bd923f04..ba8a3db6d8b 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -7,14 +7,14 @@ jobs: name: Deploy runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v6 + 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 + - 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 f390d60cca156dffb348b48712a79d9a5f400ce4 Mon Sep 17 00:00:00 2001 From: Marun Date: Wed, 2 Sep 2026 14:33:21 +0200 Subject: [PATCH 16/21] added build to gcloud --- .github/workflows/cd.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ba8a3db6d8b..aacf64db80d 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,3 +1,5 @@ +name: cd + on: push: branches: [main] @@ -17,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: + run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-507309/notely-ar-repo/notely:latest . \ No newline at end of file From 5b47863e8ed05921534998da3ec402524380b20e Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 3 Sep 2026 12:17:56 +0200 Subject: [PATCH 17/21] changes to auto deploy --- .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 aacf64db80d..b42266cf405 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -33,4 +33,7 @@ jobs: run: 'gcloud info' - name: - run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-507309/notely-ar-repo/notely:latest . \ No newline at end of file + run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-507309/notely-ar-repo/notely:latest . + + - name: Deploy to Cloud Run + run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-507309/notely-ar-repo/notely:latest --region us-central1 --allow-unauthenticated --project notely-507309 --max-instances=4 \ No newline at end of file diff --git a/static/index.html b/static/index.html index 00a891ddd80..a56ade52284 100644 --- a/static/index.html +++ b/static/index.html @@ -7,7 +7,7 @@ -

Notely

+

Welcome to Notely

From 13c699a1f42bde54340cc8ecfd2b7437c533b023 Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 3 Sep 2026 13:39:43 +0200 Subject: [PATCH 18/21] connecting to database and automate migrations --- .github/workflows/cd.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index b42266cf405..6574d40472f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -9,6 +9,10 @@ jobs: name: Deploy runs-on: ubuntu-latest + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} + + steps: - name: Check out code uses: actions/checkout@v6 @@ -32,8 +36,17 @@ jobs: - name: 'Use gcloud CLI' run: 'gcloud info' - - name: + - name: Build to gcloud run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-507309/notely-ar-repo/notely:latest . + - name: Install goose + run: go install github.com/pressly/goose/v3/cmd/goose@latest + + - name: Migrations to database + run: ./scripts/migrateup.sh + + - name: Git diff + run: git diff + - name: Deploy to Cloud Run run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-507309/notely-ar-repo/notely:latest --region us-central1 --allow-unauthenticated --project notely-507309 --max-instances=4 \ No newline at end of file From 088aa67bfefbf77d95c7c11e546cf37680112889 Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 3 Sep 2026 13:51:00 +0200 Subject: [PATCH 19/21] small change to retriger ci and cd --- .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 6574d40472f..1d247860f31 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,4 +1,4 @@ -name: cd +name: Deploy on: push: From b7c3aa75473bcbae286b1b990d0f9de77cba6989 Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 3 Sep 2026 14:01:58 +0200 Subject: [PATCH 20/21] reverted changes --- .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 1d247860f31..6574d40472f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,4 +1,4 @@ -name: Deploy +name: cd on: push: From de5dcdfc6e655799b28fe6e7e8a96dd3a5e16042 Mon Sep 17 00:00:00 2001 From: Marun Date: Thu, 3 Sep 2026 14:07:48 +0200 Subject: [PATCH 21/21] change the go version of cd --- .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 6574d40472f..874dbcbe83f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v6 with: - go-version: "1.26.0" + go-version: "1.27.1" - name: Build app run: ./scripts/buildprod.sh