From 4f3bf029c07dec7cfccd85ed40b59686cd2f4632 Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Fri, 19 Sep 2025 16:01:05 +0200 Subject: [PATCH 01/11] docs: add my line to README (Lesson 4) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c2bec0368b..06ca7f1e36 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,4 @@ 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! +Sahar Yasa's version of Boot.dev's Notely app From 581e46249e4e098fee702acf141d1b01a1c9c6cb Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Fri, 19 Sep 2025 16:57:25 +0200 Subject: [PATCH 02/11] ci: add failing CI workflow (lesson 5) --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 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..e7bfef736b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +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: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Force Failure + run: exit 1 From 980ba8f60e74ddb56871b80b9078fa00d07170d7 Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Fri, 19 Sep 2025 22:41:13 +0200 Subject: [PATCH 03/11] ci: make workflow pass by printing go version --- .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 e7bfef736b..d91d08ada2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.25.1" + go-version: "1.22.x" # if 1.25.1 fails, use a stable line like 1.22.x - - name: Force Failure - run: exit 1 + - name: Print Go version + run: go version From 9e1e868be6afafdd747c81243f801891d7dbc36b Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Fri, 19 Sep 2025 22:57:00 +0200 Subject: [PATCH 04/11] test(auth): add unit tests for GetAPIKey --- internal/auth/auth_test.go | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 internal/auth/auth_test.go diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 0000000000..c8ca87d322 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,48 @@ +package auth + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + header string + want string + wantErr bool + }{ + {name: "no header", header: "", wantErr: true}, + {name: "wrong scheme", header: "Bearer abc123", wantErr: true}, + // Function currently returns "" and NO error for an empty ApiKey value + {name: "empty key", header: "ApiKey ", want: "", wantErr: false}, + {name: "valid", header: "ApiKey abc123", want: "abc123", wantErr: false}, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + req := httptest.NewRequest(http.MethodGet, "/", nil) + if tc.header != "" { + req.Header.Set("Authorization", tc.header) + } + + // GetAPIKey takes http.Header + got, err := GetAPIKey(req.Header) + + if tc.wantErr { + if err == nil { + t.Fatalf("expected an error, got key=%q", got) + } + return + } + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if got != tc.want { + t.Fatalf("want %q, got %q", tc.want, got) + } + }) + } +} From 39afbfa7f615d98194663607af247f7d956303f5 Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Fri, 19 Sep 2025 23:01:41 +0200 Subject: [PATCH 05/11] ci: run unit tests in CI --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d91d08ada2..763af7b1f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ jobs: tests: name: Tests runs-on: ubuntu-latest + steps: - name: Check out code uses: actions/checkout@v4 @@ -15,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.22.x" # if 1.25.1 fails, use a stable line like 1.22.x + go-version: "1.25.1" - - name: Print Go version - run: go version + - name: Run unit tests + run: go test ./... From 4d389828ad21ab8ee25a98e26da03043b8bf398b Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Fri, 19 Sep 2025 23:02:01 +0200 Subject: [PATCH 06/11] test: intentionally fail to verify CI catches failures --- internal/auth/auth_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index c8ca87d322..372255797a 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -46,3 +46,6 @@ func TestGetAPIKey(t *testing.T) { }) } } + +// TEMP: make CI fail on purpose +func Test_IntentionalFail(t *testing.T) { t.Fatal("intentional fail") } From 8999e0f9d3cc28c87665ea03ae4178a55d50aef9 Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Fri, 19 Sep 2025 23:02:31 +0200 Subject: [PATCH 07/11] Revert "test: intentionally fail to verify CI catches failures" This reverts commit 4d389828ad21ab8ee25a98e26da03043b8bf398b. --- internal/auth/auth_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 372255797a..c8ca87d322 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -46,6 +46,3 @@ func TestGetAPIKey(t *testing.T) { }) } } - -// TEMP: make CI fail on purpose -func Test_IntentionalFail(t *testing.T) { t.Fatal("intentional fail") } From 53c322bb3ba130228f2857dff52cb1a381bcb08f Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Fri, 19 Sep 2025 23:56:28 +0200 Subject: [PATCH 08/11] ci: run tests with coverage --- .github/workflows/ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 763af7b1f6..70c7d0b51a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,6 @@ jobs: tests: name: Tests runs-on: ubuntu-latest - steps: - name: Check out code uses: actions/checkout@v4 @@ -16,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.25.1" + go-version: "1.25.1" # if this ever flakes, try "1.22.x" - - name: Run unit tests - run: go test ./... + - name: Run unit tests (with coverage) + run: go test --cover ./... From df6b0b86def89fbbc68af9e7fec87ac739f81341 Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Sat, 20 Sep 2025 00:02:10 +0200 Subject: [PATCH 09/11] docs: add CI status badge to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 06ca7f1e36..1f7f75acf7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![CI](https://github.com/Saharyasa/learn-cicd-starter/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Saharyasa/learn-cicd-starter/actions/workflows/ci.yml) # 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 1762b3ef835ca9960b11419f0d067a48323742a9 Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Sat, 20 Sep 2025 14:48:44 +0200 Subject: [PATCH 10/11] ch3: add style job for formatting check --- .github/workflows/ci.yml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70c7d0b51a..89ba4a9f4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,21 +1,28 @@ -name: ci +name: CI on: pull_request: - branches: [main] + branches: [ "main" ] jobs: tests: - name: Tests runs-on: ubuntu-latest steps: - - name: Check out code - uses: actions/checkout@v4 - + - uses: actions/checkout@v2 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v2 with: - go-version: "1.25.1" # if this ever flakes, try "1.22.x" + go-version: '1.21' + - name: Run unit tests + run: go test ./... - - name: Run unit tests (with coverage) - run: go test --cover ./... + style: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.21' + - name: Check formatting + run: test -z $(go fmt ./...) From fea09d696dbefe483889820da910cc28e284f99b Mon Sep 17 00:00:00 2001 From: Saharyasa Date: Sat, 20 Sep 2025 14:55:46 +0200 Subject: [PATCH 11/11] chore: trigger ci --- trigger.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 trigger.txt diff --git a/trigger.txt b/trigger.txt new file mode 100644 index 0000000000..b022dc85f9 --- /dev/null +++ b/trigger.txt @@ -0,0 +1 @@ +# trigger ci