From dc09cac0585e77ebcc110c1de065b631109d679e Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Sun, 13 Jul 2025 09:39:09 +0300 Subject: [PATCH 01/34] changes --- .gitignore | 2 +- README.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2092f54e78..13b43c0f57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ out .env learn-cicd-starter -notely +notely.exe diff --git a/README.md b/README.md index c2bec0368b..c2178a0058 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! + +ahsan0098 version of Boot.dev's Notely app. \ No newline at end of file From c06e675ba1e720081718fef25fbd7df45cd91c75 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Sun, 3 Aug 2025 22:04:40 +0300 Subject: [PATCH 02/34] yml file added --- .github/workflows/ci.yml | 0 sqlc.yaml | 30 ++++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) 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..e69de29bb2 diff --git a/sqlc.yaml b/sqlc.yaml index 6300c07fec..99ceb2f807 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -1,8 +1,22 @@ -version: "2" -sql: - - schema: "sql/schema" - queries: "sql/queries" - engine: "sqlite" - gen: - go: - out: "internal/database" +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.23.0" + + - name: Force Failure + run: (exit 1) From 79b30b1b61156b3f7be077e0b03fd91920148239 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Sun, 3 Aug 2025 23:26:41 +0300 Subject: [PATCH 03/34] checking cicd working --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ .gitignore | 1 + 2 files changed, 23 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..b646844e83 --- /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: actions/setup-go@v5 + with: + go-version: "1.24.0" + + - name: Force Failure + run: (exit 0) \ No newline at end of file diff --git a/.gitignore b/.gitignore index 13b43c0f57..9bff2a9700 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ out .env learn-cicd-starter notely.exe +notly From 17ddf18df022c04d32cbd441a62131acedcad00b Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Sun, 3 Aug 2025 23:30:42 +0300 Subject: [PATCH 04/34] checking cicd working --- .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 b646844e83..cb80b71388 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.24.0" + go-version: "1.24" - name: Force Failure run: (exit 0) \ No newline at end of file From 4b6d0fd57edef66941fae9620774464b0b45fd0f Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Wed, 6 Aug 2025 21:45:33 +0300 Subject: [PATCH 05/34] ci failure test --- .github/workflows/ci.yml | 6 ++-- internal/auth/auth_test.go | 64 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 internal/auth/auth_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb80b71388..bb1debe07e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,10 +13,8 @@ jobs: - name: Check out code uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: "1.24" + - name: Test + run: go test ./... - name: Force Failure run: (exit 0) \ No newline at end of file diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 0000000000..512cbd7517 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,64 @@ +package auth + +import ( + "errors" + "net/http" + "strings" + "testing" +) + +func TestGetAPIKey(t *testing.T) { + tests := []struct { + name string + header http.Header + expectedKey string + expectedError error + }{ + { + name: "no header", + header: http.Header{}, + expectedKey: "", + expectedError: ErrNoAuthHeaderIncluded, + }, + { + name: "malformed header - no value", + header: http.Header{ + "Authorization": []string{"Bearer12345"}, + }, + expectedKey: "", + expectedError: errors.New("malformed authorization header"), + }, + { + name: "malformed header - missing key part", + header: http.Header{ + "Authorization": []string{"ApiKey"}, + }, + expectedKey: "", + expectedError: errors.New("malformed authorization header"), + }, + { + name: "valid header", + header: http.Header{ + "Authorization": []string{"ApiKey test12345"}, + }, + expectedKey: "test12345", + expectedError: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + key, err := GetAPIKey(tt.header) + + if key == tt.expectedKey { + t.Errorf("expected key '%s', got '%s'", tt.expectedKey, key) + } + + if (err != nil && tt.expectedError == nil) || (err == nil && tt.expectedError != nil) { + t.Errorf("expected error '%v', got '%v'", tt.expectedError, err) + } else if err != nil && tt.expectedError != nil && !strings.Contains(err.Error(), tt.expectedError.Error()) { + t.Errorf("expected error '%v', got '%v'", tt.expectedError, err) + } + }) + } +} \ No newline at end of file From f5a9a27f98a13c72d2b5d697718d24f81c451649 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Wed, 6 Aug 2025 22:01:35 +0300 Subject: [PATCH 06/34] testing --- .github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb1debe07e..eaef5fef64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,5 @@ jobs: - name: Check out code uses: actions/checkout@v4 - - name: Test - run: go test ./... - - - name: Force Failure - run: (exit 0) \ No newline at end of file + - name: Run Go Tests + run: go test ./... \ No newline at end of file From 88ad2d414bf29752613de69a07a315bc9b69c5e3 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Wed, 6 Aug 2025 22:08:56 +0300 Subject: [PATCH 07/34] Fix CI to run go 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 eaef5fef64..c8544480fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,4 +14,4 @@ jobs: uses: actions/checkout@v4 - name: Run Go Tests - run: go test ./... \ No newline at end of file + run: go test ./... From 8e05b50b97f8c8cb38fa2997346faab1b2de6189 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Wed, 6 Aug 2025 22:15:26 +0300 Subject: [PATCH 08/34] Fix CI to run go tests --- .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 c8544480fc..ff5111eefb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,5 +13,10 @@ jobs: - name: Check out code uses: actions/checkout@v4 - - name: Run Go Tests - run: go test ./... + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23.0' + + - name: Run unit tests + run: go test ./... \ No newline at end of file From 9c96d633b5bccd24c3756b54d6c84bc1f08dc099 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Wed, 6 Aug 2025 22:19:08 +0300 Subject: [PATCH 09/34] fixing 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 ff5111eefb..3165361ee4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: '1.23.0' - name: Run unit tests - run: go test ./... \ No newline at end of file + run: go test ./... From 9a8d54eca78a3f61a5442f82d94e83b7ce72ae91 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Wed, 6 Aug 2025 22:22:17 +0300 Subject: [PATCH 10/34] dd --- internal/auth/auth_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 512cbd7517..4eee28ba98 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -61,4 +61,8 @@ func TestGetAPIKey(t *testing.T) { } }) } -} \ No newline at end of file +} + +func TestFailing(t *testing.T) { + t.Fatal("go test") +} From 2ed50808e0586df4da6dc1ca0b3c8e8ac17b6ed0 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Wed, 6 Aug 2025 22:26:42 +0300 Subject: [PATCH 11/34] sdfsd --- internal/auth/auth_test.go | 74 ++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 4eee28ba98..5ac1cd99d3 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -1,7 +1,7 @@ package auth import ( - "errors" + "fmt" "net/http" "strings" "testing" @@ -9,60 +9,54 @@ import ( func TestGetAPIKey(t *testing.T) { tests := []struct { - name string - header http.Header - expectedKey string - expectedError error + key string + value string + expect string + expectErr string }{ { - name: "no header", - header: http.Header{}, - expectedKey: "", - expectedError: ErrNoAuthHeaderIncluded, + expectErr: "no authorization header", }, { - name: "malformed header - no value", - header: http.Header{ - "Authorization": []string{"Bearer12345"}, - }, - expectedKey: "", - expectedError: errors.New("malformed authorization header"), + key: "Authorization", + expectErr: "no authorization header", }, { - name: "malformed header - missing key part", - header: http.Header{ - "Authorization": []string{"ApiKey"}, - }, - expectedKey: "", - expectedError: errors.New("malformed authorization header"), + key: "Authorization", + value: "-", + expectErr: "malformed authorization header", }, { - name: "valid header", - header: http.Header{ - "Authorization": []string{"ApiKey test12345"}, - }, - expectedKey: "test12345", - expectedError: nil, + key: "Authorization", + value: "Bearer xxxxxx", + expectErr: "malformed authorization header", + }, + { + key: "Authorization", + value: "ApiKey xxxxxx", + expect: "xxxxxx", + expectErr: "not expecting an error", }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - key, err := GetAPIKey(tt.header) + 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) - if key == tt.expectedKey { - t.Errorf("expected key '%s', got '%s'", tt.expectedKey, key) + output, err := GetAPIKey(header) + if err != nil { + if strings.Contains(err.Error(), test.expectErr) { + return + } + t.Errorf("Unexpected: TestGetAPIKey:%v\n", err) + return } - if (err != nil && tt.expectedError == nil) || (err == nil && tt.expectedError != nil) { - t.Errorf("expected error '%v', got '%v'", tt.expectedError, err) - } else if err != nil && tt.expectedError != nil && !strings.Contains(err.Error(), tt.expectedError.Error()) { - t.Errorf("expected error '%v', got '%v'", tt.expectedError, err) + if output != test.expect { + t.Errorf("Unexpected: TestGetAPIKey:%s", output) + return } }) } } - -func TestFailing(t *testing.T) { - t.Fatal("go test") -} From abd20bcf44928efa7c72cb6820fd2758c512de3f Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Wed, 6 Aug 2025 22:37:30 +0300 Subject: [PATCH 12/34] dfsf --- .github/workflows/ci.yml | 2 +- sqlc.yaml | 30 ++++++++---------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3165361ee4..9ca4cc6a70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: '1.23.0' - - name: Run unit tests + - name: Tests run: go test ./... diff --git a/sqlc.yaml b/sqlc.yaml index 99ceb2f807..6300c07fec 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -1,22 +1,8 @@ -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.23.0" - - - name: Force Failure - run: (exit 1) +version: "2" +sql: + - schema: "sql/schema" + queries: "sql/queries" + engine: "sqlite" + gen: + go: + out: "internal/database" From bb9119a804a9e01eabf0f7a51952d6c341abe06d Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 07:42:20 +0300 Subject: [PATCH 13/34] .. --- .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 3165361ee4..a833939d34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: '1.23.0' - - name: Run unit tests + - name: go test run: go test ./... From 6ad77924475e7c6efab4e3f507d77339ca42df9e Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 07:46:21 +0300 Subject: [PATCH 14/34] .. --- .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 a833939d34..3165361ee4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: '1.23.0' - - name: go test + - name: Run unit tests run: go test ./... From c9724c4244046ef2c4de89a4e88ac3b9d1aa415b Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 07:47:34 +0300 Subject: [PATCH 15/34] .. --- .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 9ca4cc6a70..3165361ee4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,5 @@ jobs: with: go-version: '1.23.0' - - name: Tests + - name: Run unit tests run: go test ./... From 3a224a383dc7b3bc5c7d9f3de2335befb600700c Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 07:50:45 +0300 Subject: [PATCH 16/34] .. --- internal/auth/auth_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 5ac1cd99d3..6f266eb99d 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -60,3 +60,7 @@ func TestGetAPIKey(t *testing.T) { }) } } + +func TestSomething(t *testing.T) { + t.Log("go test") +} \ No newline at end of file From 1a5d4e2ac7118377e0040e3636f9c65203f121e0 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 07:52:53 +0300 Subject: [PATCH 17/34] .. --- .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 3165361ee4..ff5111eefb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,4 @@ jobs: go-version: '1.23.0' - name: Run unit tests - run: go test ./... + run: go test ./... \ No newline at end of file From 33d6c9833c44e49274460a54f6d2005e82b3fcb4 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 07:58:22 +0300 Subject: [PATCH 18/34] .. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c2178a0058..165cbe005e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # learn-cicd-starter (Notely) + +![alt text goes here](https://github.com/ahsan0098/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). ## Local Development From c3d2c39797bbe134ea41d1b8d9e48940d4e9a62f Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 08:15:12 +0300 Subject: [PATCH 19/34] .. --- .github/workflows/ci.yml | 18 +++++++++++++++++- internal/auth/auth_test.go | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff5111eefb..ba13c32aa9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,4 +19,20 @@ jobs: go-version: '1.23.0' - name: Run unit tests - run: go test ./... \ No newline at end of file + run: go test ./... + style: + tests: + 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.23.0' + + - name: formatting tests + run: test -z $(go fmt ./...) \ No newline at end of file diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 6f266eb99d..59ed944a6e 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -63,4 +63,4 @@ func TestGetAPIKey(t *testing.T) { func TestSomething(t *testing.T) { t.Log("go test") -} \ No newline at end of file +} From 9a3b55bfc3a41ef6018838f9a03b40f879f09fc9 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 08:26:25 +0300 Subject: [PATCH 20/34] .. --- .github/workflows/ci.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba13c32aa9..3165361ee4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,19 +20,3 @@ jobs: - name: Run unit tests run: go test ./... - style: - tests: - 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.23.0' - - - name: formatting tests - run: test -z $(go fmt ./...) \ No newline at end of file From 6352efb907523107624488f8aa0a0eb2d0ee0192 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 08:27:31 +0300 Subject: [PATCH 21/34] added style test --- .github/workflows/ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3165361ee4..ba13c32aa9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,3 +20,19 @@ jobs: - name: Run unit tests run: go test ./... + style: + tests: + 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.23.0' + + - name: formatting tests + run: test -z $(go fmt ./...) \ No newline at end of file From 69113cf17d3225ca083e2acd65ab48ced85f7668 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 08:31:54 +0300 Subject: [PATCH 22/34] added style test --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba13c32aa9..41054ca198 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,12 +20,12 @@ jobs: - name: Run unit tests run: go test ./... + style: - tests: - name: Style - runs-on: ubuntu-latest + name: Style + runs-on: ubuntu-latest - steps: + steps: - name: Check out code uses: actions/checkout@v4 @@ -34,5 +34,5 @@ jobs: with: go-version: '1.23.0' - - name: formatting tests - run: test -z $(go fmt ./...) \ No newline at end of file + - name: Formatting check + run: test -z "$(go fmt ./...)" From a4ae117d3d628d791abaf12dd7eeeb5abcd6d0a1 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 08:37:23 +0300 Subject: [PATCH 23/34] added cover flag to 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 41054ca198..2ae9e375bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: go-version: '1.23.0' - name: Run unit tests - run: go test ./... + run: go test ./... -cover style: name: Style From 03f5c97eebfcdb03924585d4f8cbc44abc8c9091 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 08:52:34 +0300 Subject: [PATCH 24/34] added failing liniting test --- .github/workflows/ci.yml | 6 ++++++ main.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ae9e375bc..5cf6ac8d8a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,3 +36,9 @@ jobs: - name: Formatting check run: test -z "$(go fmt ./...)" + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: linting tests + - run: staticcheck ./... \ No newline at end of file diff --git a/main.go b/main.go index 19d7366c5f..e546112a05 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 5daef25c123d031ea4df2982bdf3fa12dceb7990 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 08:55:46 +0300 Subject: [PATCH 25/34] fixed failing liniting test --- .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 5cf6ac8d8a..da0d826317 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,4 +41,4 @@ jobs: run: go install honnef.co/go/tools/cmd/staticcheck@latest - name: linting tests - - run: staticcheck ./... \ No newline at end of file + run: staticcheck ./... \ No newline at end of file From 90f4f634e609b507b98788dbebd887dc3711c4a3 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 08:57:26 +0300 Subject: [PATCH 26/34] added successing liniting test --- main.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.go b/main.go index e546112a05..dd9f84f90e 100644 --- a/main.go +++ b/main.go @@ -95,9 +95,4 @@ 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 cd98c63bd6d9c26fe69a9cd2af08f4e965d867c7 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 09:03:39 +0300 Subject: [PATCH 27/34] added successing liniting test --- .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 da0d826317..d0ef97790e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,5 +40,5 @@ jobs: - name: Install staticcheck run: go install honnef.co/go/tools/cmd/staticcheck@latest - - name: linting tests + - name: Run staticcheck linter run: staticcheck ./... \ No newline at end of file From 6b7701edd6879cb9e38a3f3aefa5646a240d7b28 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Thu, 7 Aug 2025 22:12:21 +0300 Subject: [PATCH 28/34] formating --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index dd9f84f90e..19d7366c5f 100644 --- a/main.go +++ b/main.go @@ -95,4 +95,4 @@ func main() { log.Printf("Serving on port: %s\n", port) log.Fatal(srv.ListenAndServe()) -} \ No newline at end of file +} From dd33cf74f3355430d2be8388be679abb6d3fec66 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Tue, 2 Sep 2025 08:46:34 +0300 Subject: [PATCH 29/34] added gosec test --- .github/workflows/ci.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0ef97790e..5c07893e35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,4 +41,23 @@ jobs: run: go install honnef.co/go/tools/cmd/staticcheck@latest - name: Run staticcheck linter - run: staticcheck ./... \ No newline at end of file + run: staticcheck ./... + + security: + name: Security + 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.23.0' + + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Run staticcheck linter + run: gosec ./... \ No newline at end of file From c1ecb74aeb6787cd73064f696f4730564fb02d5a Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Tue, 2 Sep 2025 08:50:45 +0300 Subject: [PATCH 30/34] added gosec test 2 --- .github/workflows/ci.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c07893e35..7d3fbd8b0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,20 +44,20 @@ jobs: run: staticcheck ./... security: - name: Security - 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.23.0' - - - name: Install gosec - run: go install github.com/securego/gosec/v2/cmd/gosec@latest - - - name: Run staticcheck linter - run: gosec ./... \ No newline at end of file + name: Security + 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.23.0' + + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Run staticcheck linter + run: gosec ./... \ No newline at end of file From 5be443b22ffb0b94a2aba1f9b31a0122cd8b2080 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Tue, 2 Sep 2025 08:53:20 +0300 Subject: [PATCH 31/34] added gosec test 3 --- .github/workflows/ci.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d3fbd8b0d..f7d0fec98f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,21 +43,21 @@ jobs: - name: Run staticcheck linter run: staticcheck ./... - security: - name: Security - runs-on: ubuntu-latest + security: + name: Security + runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v4 + steps: + - name: Check out code + uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: + - name: Set up Go + uses: actions/setup-go@v5 + with: go-version: '1.23.0' - - name: Install gosec - run: go install github.com/securego/gosec/v2/cmd/gosec@latest + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest - - name: Run staticcheck linter - run: gosec ./... \ No newline at end of file + - name: Run staticcheck linter + run: gosec ./... \ No newline at end of file From 2802cc0e1fc5f2b68e5ce4ae61e6c2c2d17770c1 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Tue, 2 Sep 2025 09:07:25 +0300 Subject: [PATCH 32/34] added gosec test...locally passed...ci check --- json.go | 7 ++++++- main.go | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/json.go b/json.go index 1e6e7985e1..729f333d0e 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) + + if _, err = w.Write(dat); err != nil { + log.Printf("Error writing response JSON: %s", err) + w.WriteHeader(500) + return + } } diff --git a/main.go b/main.go index 19d7366c5f..532af271df 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" @@ -91,6 +92,7 @@ func main() { srv := &http.Server{ Addr: ":" + port, Handler: router, + ReadHeaderTimeout: 5 * time.Second, } log.Printf("Serving on port: %s\n", port) From 09437c2e11635583fd21c0f161158e9d7ef2a562 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Tue, 2 Sep 2025 09:09:57 +0300 Subject: [PATCH 33/34] added gosec test...locally passed...ci checked...styling issue fixed --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 532af271df..15ee531c5d 100644 --- a/main.go +++ b/main.go @@ -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 2eb732c41957bc3f8e3369d145a640c7348b9811 Mon Sep 17 00:00:00 2001 From: Ahsan Ali Date: Tue, 2 Sep 2025 10:10:53 +0300 Subject: [PATCH 34/34] deployement : cd.yml created...testing setup --- .github/workflows/cd.yml | 22 ++++++++++++++++++++++ .gitignore | 2 +- 2 files changed, 23 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 0000000000..a3f52906bc --- /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@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.23.0' + + - name: Build the app + run: scripts/buildprod.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9bff2a9700..53f4c2ab34 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ out .env learn-cicd-starter notely.exe -notly +notely