Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
07039c8
edit:added my name to README.md
mhv2408 Sep 10, 2025
bbe4e47
added CI workflows
mhv2408 Sep 10, 2025
2de8388
edit:updated last step to print go version
mhv2408 Sep 10, 2025
6151682
added testing workflow to fail
mhv2408 Sep 10, 2025
2b15c8d
edit: updated test still to fail
mhv2408 Sep 10, 2025
e91e212
edit: workflow fail case updated
mhv2408 Sep 10, 2025
1bfc300
edit: workflow to pass
mhv2408 Sep 10, 2025
c135727
added cover flag for the api test
mhv2408 Sep 10, 2025
ba6e0e3
added testing badge to readme
mhv2408 Sep 10, 2025
c3f518b
added testing badge to readme
mhv2408 Sep 10, 2025
0a713e6
added new style format job
mhv2408 Sep 10, 2025
c20e2ea
added new formar changes to main
mhv2408 Sep 10, 2025
442fbeb
modified styles name to style
mhv2408 Sep 10, 2025
485f0de
added code to test linting issues
mhv2408 Sep 10, 2025
51ffa6b
added code to test linting issues
mhv2408 Sep 10, 2025
5705843
removed doNothing functions to resolve linting issues
mhv2408 Sep 10, 2025
3e1de65
removed doNothing functions to resolve linting issues
mhv2408 Sep 10, 2025
4770c9f
added gosec checks to CI
mhv2408 Sep 10, 2025
21ff7e3
resolved security vulnerabilities thrown by gosec
mhv2408 Sep 10, 2025
e166422
added cd pipeline to the code
mhv2408 Sep 12, 2025
618356f
added building the image and pushing it to google artifact registry
mhv2408 Sep 12, 2025
18e3aee
added new changes to the application
mhv2408 Sep 12, 2025
046b431
TURSO DB connection
mhv2408 Sep 12, 2025
1337b66
made some changes to shell scripts
mhv2408 Sep 12, 2025
fa8b85f
ci/cd demo
mhv2408 Dec 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: cd

on:
push:
branches: [main]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}

steps:
- name: Checkout the code
uses: actions/checkout@v4

- name: Setup Go Tool Chain
uses: actions/setup-go@v5
with:
go-version: "1.23.0"

- name: Install goose for to run DB migrations
run: go install github.com/pressly/goose/v3/cmd/goose@latest

- name: Build the app
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 the Docker Image and Push to Artifact Registry'
run: 'gcloud builds submit --tag us-central1-docker.pkg.dev/notely-471904/notely-ar-repo/mhv2408/notely:latest .'

- name: Run Database Migrations
run: ./scripts/migrateup.sh

- name: Deploy to Cloud Run
run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-471904/notely-ar-repo/mhv2408/notely:latest --region us-central1 --allow-unauthenticated --project notely-471904 --max-instances=4
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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: Test Api
run: go test ./... -cover

- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: Run gosec
run: gosec ./...

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.23.0"

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Check formatting issues
run: test -z $(go fmt ./...)

- name: Check linting issues
run: staticcheck ./...
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
![Testing Badge - Status of Tests](https://github.com/mhv2408/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).
Expand All @@ -21,3 +22,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!
Harsha's version of Boot.dev's Notely app.
62 changes: 62 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -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
}
})
}
}
7 changes: 6 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 for response: %s", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -89,8 +90,9 @@ func main() {

router.Mount("/v1", v1Router)
srv := &http.Server{
Addr: ":" + port,
Handler: router,
Addr: ":" + port,
Handler: router,
ReadHeaderTimeout: 5 * time.Second,
}

log.Printf("Serving on port: %s\n", port)
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body class="section">
<h1>Notely</h1>
<h1>Welcome to Notely</h1>

<div id="userCreationContainer" class="section">
<input id="nameField" type="text" placeholder="Enter your name">
Expand Down