Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: ci

on:
pull_request:
branches: ["main"]

jobs:
tests:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Checkout 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 tests
run: go test ./... -cover

- name: test security
run: gosec ./...

format:
name: Format
runs-on: ubuntu-latest

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

- name: Set up go
uses: actions/setup-go@v5
with:
go-version: "1.23.0"

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

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

- name: test linter
run: staticcheck ./...

36 changes: 36 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: cd

on:
push:
branches: ["main"]

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

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

- name: Set up go
uses: actions/setup-go@v5
with:
go-version: "1.23.0"

- name: Build
run: ./scripts/buildprod.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: Use gcloud CLI
run: gcloud info

- name: Gcloud Build submit
run: gcloud builds submit --tag asia-south1-docker.pkg.dev/notelydemobyshantesh/notely-shan-repo/notely:latest .
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# learn-cicd-starter (Notely)
# shaun (Notely)

![Go Test](https://github.com/teamharmony/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).

Expand Down
26 changes: 26 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package auth

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

func Test(t *testing.T) {
expectedKey := "1a2b3c4d5e6f"

headers := make(http.Header)

headers.Add("Authorization", strings.Join([]string{"ApiKey", expectedKey}, " "))

actualKey, err := GetAPIKey(headers)

if actualKey != expectedKey {
t.Errorf("the key %v passed in the header is different from key %v returned on parsing.", expectedKey, actualKey)
}

if err != nil {
t.Errorf("Expected no error but received %v", err)
}

}
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)
_, err = w.Write(dat)
if err != nil {
log.Printf("Error while writing response %v", err)
}
}
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