From 8ff49e5c56a4d96db0c13ae2879357a1f9544205 Mon Sep 17 00:00:00 2001 From: janrusell Date: Sun, 2 Nov 2025 13:31:33 +0800 Subject: [PATCH 01/18] update : readme file --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c2bec0368b..174f717225 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Run the server: go build -o notely && ./notely ``` -*This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`. +_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! +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! + +janruselldev's version of Boot.dev's Notely app. From 7fb03020a5aaea2564adfb47b46c81cd2c5a23cd Mon Sep 17 00:00:00 2001 From: janrusell Date: Sun, 2 Nov 2025 13:44:31 +0800 Subject: [PATCH 02/18] update - readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 174f717225..de81d53187 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ _This starts the server in non-database mode._ It will serve a simple webpage at 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! -janruselldev's version of Boot.dev's Notely app. +janruselldev's version of Boot.dev's Notely app From d701a18afeaa9a31a1294677b0ad5b92cb6dedae Mon Sep 17 00:00:00 2001 From: janrusell Date: Sun, 2 Nov 2025 13:56:24 +0800 Subject: [PATCH 03/18] chore - added ci pipelines --- .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 0000000000..f517ac5efb --- /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@v4 + + - name: Set up Go + uses: actins/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Force Failure + run: (exit 1) From 9108d375f111512d7b4f7190295fc961f3c72dae Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 00:20:31 +0800 Subject: [PATCH 04/18] update - yml config --- .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 f517ac5efb..6a1d9c924f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.25.1" - - name: Force Failure - run: (exit 1) + - name: Check Go version + run: go version From b374fa2f032523f51b582a68646c2f6bb4b9d6bd Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 00:22:40 +0800 Subject: [PATCH 05/18] fix - ci typo --- .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 6a1d9c924f..2a8e2b332a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Go - uses: actins/setup-go@v5 + uses: actions/setup-go@v5 with: go-version: "1.25.1" From 96c4325d1c4d5dd203fa55e8f43c2903c03ca7a3 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 00:42:45 +0800 Subject: [PATCH 06/18] update - yml file --- .github/workflows/ci.yml | 2 +- internal/auth/auth.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a8e2b332a..4d62ecc598 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.25.1" - name: Check Go version - run: go version + run: go test ./... diff --git a/internal/auth/auth.go b/internal/auth/auth.go index f969aacf63..68decaa558 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -4,6 +4,7 @@ import ( "errors" "net/http" "strings" + "testing" ) var ErrNoAuthHeaderIncluded = errors.New("no authorization header included") @@ -21,3 +22,19 @@ func GetAPIKey(headers http.Header) (string, error) { return splitAuth[1], nil } + +func TestGetAPIKey(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey my-secret-key") + got, err := GetAPIKey(headers) + + if err != nil { + t.Errorf("unexpected error: %v", err) + } + + want := "my-secret-key" + + if got != want { + t.Errorf("expected %q, got %q", want, got) + } +} From 3ebf328970564f716a59fb6d8ed8e53f3643e0f6 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 00:44:51 +0800 Subject: [PATCH 07/18] update to fail 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 4d62ecc598..f98f5bc9a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: "1.25.1" - - name: Check Go version + - run: go test ./... From 1616fe8177e2b94bfdd53b634fbb39de24d637de Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 00:46:37 +0800 Subject: [PATCH 08/18] update to fail ci --- .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 f98f5bc9a2..a871468caa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,9 +14,9 @@ jobs: uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/set-go@v5 with: go-version: "1.25.1" - - + - name: Check Go version run: go test ./... From e90dd39070f452bc000287e56131a31265ebc29e Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 00:47:59 +0800 Subject: [PATCH 09/18] fix ci fail --- .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 a871468caa..4d62ecc598 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Go - uses: actions/set-go@v5 + uses: actions/setup-go@v5 with: go-version: "1.25.1" From 3e0f733269463dcdaeb1eab033ace1b450f97fd5 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 00:53:03 +0800 Subject: [PATCH 10/18] add logs for running a tests --- .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 4d62ecc598..e8294636da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: "1.25.1" - name: Check Go version - run: go test ./... + run: go test ./... -cover From ff683cd7e0322168ff3cb47ffd4df349b05d41b7 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 01:00:43 +0800 Subject: [PATCH 11/18] added badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index de81d53187..2e3b975cc3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![test status image](https://github.com/janrusell-dev/learn-cicd-starter/actions/workflows/.github/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 b29839961466727f374ebe5bdaea5397b7bb144b Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 01:14:13 +0800 Subject: [PATCH 12/18] added style jobs --- .github/workflows/ci.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8294636da..9e830705eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,3 +20,17 @@ jobs: - name: Check Go version run: go test ./... -cover + + style: + name: Style + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + From f86bad7ed8e7efb2d1ba24c52dde3849ae8f6246 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 01:17:27 +0800 Subject: [PATCH 13/18] update style run command --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e830705eb..fbb784aad6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,3 +34,6 @@ jobs: with: go-version: "1.25.1" + - name: Check formatting issue + run: test -z $(go fmt ./...) + From 9e97c05a86a88a0f849b5270caa50aa167e41a97 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 01:21:59 +0800 Subject: [PATCH 14/18] added linter installation --- .github/workflows/ci.yml | 3 +++ main.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbb784aad6..931ea1220f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,3 +37,6 @@ jobs: - name: Check formatting issue run: test -z $(go fmt ./...) + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + 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 d5dad4ff01e52bc5273b55b6d34c91c5e6867a87 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 01:25:48 +0800 Subject: [PATCH 15/18] added gosec --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 931ea1220f..84bc5f633f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,12 @@ jobs: - name: Check Go version run: go test ./... -cover + + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Check gosec + run: go sec ./... style: name: Style @@ -40,3 +46,4 @@ jobs: - name: Install staticcheck run: go install honnef.co/go/tools/cmd/staticcheck@latest + \ No newline at end of file From 2e27908d1ff4b16a1804c5f880d7c729c904cc92 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 01:32:56 +0800 Subject: [PATCH 16/18] fix gosec errors --- json.go | 4 +++- main.go | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/json.go b/json.go index 1e6e7985e1..8d4f9d6c93 100644 --- a/json.go +++ b/json.go @@ -30,5 +30,7 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) { return } w.WriteHeader(code) - w.Write(dat) + if _, err := w.Write(dat); err != nil { + log.Printf("failed to write response: %v", err) + } } diff --git a/main.go b/main.go index a621713c2b..3299ec20c0 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,15 +90,14 @@ func main() { router.Mount("/v1", v1Router) srv := &http.Server{ - Addr: ":" + port, - Handler: router, + Addr: ":" + port, + Handler: router, + ReadHeaderTimeout: 5 * time.Second, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + IdleTimeout: 60 * time.Second, } log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) } - -func unused() { - // this function does nothing - // and is called nowhere -} From 9e8ca806ebeed4242ae88c1e60052b7317687ec4 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 01:54:25 +0800 Subject: [PATCH 17/18] added cd pipelines and update buildprod --- .github/workflows/cd.yml | 26 ++++++++++++++++++++++++++ .github/workflows/ci.yml | 1 - scripts/buildprod.sh | 2 +- 3 files changed, 27 insertions(+), 2 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 0000000000..b68f700926 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,26 @@ +name: cd + +on: + push: + branches: [main] + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: action/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Build production app + run: bash scripts/buildprod.sh + + + + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84bc5f633f..7828beedb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,4 +46,3 @@ jobs: - name: Install staticcheck run: go install honnef.co/go/tools/cmd/staticcheck@latest - \ No newline at end of file diff --git a/scripts/buildprod.sh b/scripts/buildprod.sh index f08d1a592e..1bbeef30fb 100755 --- a/scripts/buildprod.sh +++ b/scripts/buildprod.sh @@ -1,3 +1,3 @@ #!/bin/bash -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o notely +CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o notely From 8f93bb005cd2f4daa13a8e3b2175d2c5faa18df7 Mon Sep 17 00:00:00 2001 From: janrusell Date: Tue, 4 Nov 2025 01:56:51 +0800 Subject: [PATCH 18/18] fix ci typo --- .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 7828beedb5..550847b360 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: run: go install github.com/securego/gosec/v2/cmd/gosec@latest - name: Check gosec - run: go sec ./... + run: gosec ./... style: name: Style