Skip to content
Open

pull #2649

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
07ea958
commit1
m1kab0 Jun 8, 2026
101af05
commit yaml file
m1kab0 Jun 8, 2026
80deb1d
ci.yml edit to go version instead of exit 1
m1kab0 Jun 8, 2026
087f276
CI that will fail
m1kab0 Jun 9, 2026
1b2ade7
broken message
m1kab0 Jun 9, 2026
79c4efd
repaired message
m1kab0 Jun 9, 2026
d7b98c2
-cover flag added to ci
m1kab0 Jun 9, 2026
1ddb0e1
-cover flag added to ci2
m1kab0 Jun 9, 2026
ed4a861
-cover flag added to ci3
m1kab0 Jun 9, 2026
dfc6d6d
-cover flag added to ci4
m1kab0 Jun 9, 2026
0071f69
-cover flag added to ci5
m1kab0 Jun 9, 2026
62b88a7
-cover flag added to ci6
m1kab0 Jun 9, 2026
fb38cb6
-cover flag added to ci7 final
m1kab0 Jun 9, 2026
28bbd71
readme badge
m1kab0 Jun 9, 2026
b84528a
Merge pull request #1 from m1kab0/addtests
m1kab0 Jun 10, 2026
8c1cb2d
ci.yaml
m1kab0 Jun 11, 2026
85d1471
ci.yaml
m1kab0 Jun 11, 2026
11862d2
ci.yml finished
m1kab0 Jun 11, 2026
816fa18
yaml ci
m1kab0 Jun 11, 2026
8c38156
Merge pull request #2 from m1kab0/addtests
m1kab0 Jun 11, 2026
aeaa90f
linting
m1kab0 Jun 12, 2026
f483e58
CI gosec test
m1kab0 Jun 12, 2026
eef199e
gosec tun
m1kab0 Jun 12, 2026
cd5b6a4
fixed code bugs
m1kab0 Jun 12, 2026
088ce76
srv add fix
m1kab0 Jun 12, 2026
6f8cf53
cd
m1kab0 Jun 12, 2026
a0f0198
Merge pull request #3 from m1kab0/addtests
m1kab0 Jun 12, 2026
73f09fc
cd google cloud connect
m1kab0 Jun 14, 2026
c6a85a3
cloud builds submit 3
m1kab0 Jun 14, 2026
3459b73
Merge pull request #4 from m1kab0/addtests
m1kab0 Jun 14, 2026
43466d8
gcloud fix
m1kab0 Jun 14, 2026
584b79f
main: notely cd deploy to cloud
m1kab0 Jun 15, 2026
e137292
main: Welcome to notely change
m1kab0 Jun 15, 2026
d4694c9
main: cd fix
m1kab0 Jun 15, 2026
3e61b33
main: cd database migration
m1kab0 Jun 15, 2026
d915741
main: cd database migration fix
m1kab0 Jun 15, 2026
de16b95
main: cd database migration fix 2
m1kab0 Jun 15, 2026
6457094
main: cd database migration fix 3
m1kab0 Jun 15, 2026
987f65f
main: cd database migration fix 4
m1kab0 Jun 15, 2026
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
47 changes: 47 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: cd

on:
push:
branches: [main]

jobs:
Deploy:
runs-on: ubuntu-latest
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

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

- name: Build
run: ./scripts/buildprod.sh

- name: database migration
run: ./scripts/migrateup.sh

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2

- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker us-central1-docker.pkg.dev

- name: gcloud builds submit
run: gcloud builds submit --tag us-central1-docker.pkg.dev/notely-499416/notely-ar-repo/notely:latest

- name: Deploy to Cloud Run
run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notely-499416/notely-ar-repo/notely:latest --region us-central1 --allow-unauthenticated --project notely-499416 --max-instances=4


47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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.26.0"

- name: go test
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.26.0"

- name: Check for Formatting Issues
run: test -z $(go fmt ./...)

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
![CI status](https://github.com/m1kab0/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!
Bartlomiej's version of Boot.dev's Notely app.
57 changes: 57 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package auth

import (
"errors"
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
type testCase struct {
name string
headers http.Header
expectedKey string
expectedErr error
}

tests := []testCase{
{
name: "no authorization header",
headers: http.Header{},
expectedKey: "",
expectedErr: ErrNoAuthHeaderIncluded,
},
{
name: "valid API key",
headers: http.Header{
"Authorization": []string{"ApiKey my-secret-key"},
},
expectedKey: "my-secret-key",
expectedErr: nil,
},
{
name: "malformed header - missing ApiKey prefix",
headers: http.Header{
"Authorization": []string{"Bearer my-secret-key"},
},
expectedKey: "",
expectedErr: errors.New("malformed authorization header"),
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
key, err := GetAPIKey(tc.headers)

if tc.expectedErr != nil && err == nil {
t.Errorf("expected error %q, got none", tc.expectedErr)
}
if tc.expectedErr == nil && err != nil {
t.Errorf("unexpected error: %v", err)
}
if key != tc.expectedKey {
t.Errorf("expected key %q, got %q", tc.expectedKey, key)
}
})
}
}
5 changes: 4 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ 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: %v", err)
}
}
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log"
"net/http"
"os"
"strings"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -89,10 +91,12 @@ func main() {

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

log.Printf("Serving on port: %s\n", port)
log.Printf("Serving on port: %s\n", strings.ReplaceAll(port, "\n", ""))
log.Fatal(srv.ListenAndServe())

}
6 changes: 3 additions & 3 deletions 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 All @@ -21,7 +21,7 @@ <h1>Notely</h1>
<button id="createNoteButton" onclick="createNote()">Create Note</button>

<h2>Your Notes</h2>
<div id="notes"></div>
<div id='notes'></div>

<button onclick="logout()">Logout</button>
</div>
Expand All @@ -33,7 +33,7 @@ <h2>Your Notes</h2>

async function createNote() {
if (!currentUser) {
alert('Please create a user first');
alert('śPlease create a user first');
return;
}
const noteContent = document.getElementById('newNoteContent').value;
Expand Down