Skip to content
Open

new #2702

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

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

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

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

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

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.24'
- name: build notely
run: go build -o notely .

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

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

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

- name: Build Docker image
run: |
docker build -t us-central1-docker.pkg.dev/notel-500815/notely-ar-repo/my-app:v1 .

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

- name: Push Docker image
run: |
docker push us-central1-docker.pkg.dev/notel-500815/notely-ar-repo/my-app:v1

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

- name: Deploy to Cloud Run
run: gcloud run deploy notely --image us-central1-docker.pkg.dev/notel-500815/notely-ar-repo/my-app:v1 --region us-central1 --allow-unauthenticated --project notel-500815 --max-instances=4
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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@v6

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.26.0"

- name: run tests
run: go test ./...
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

![alt text goes here](https://github.com/Yashwarhade8010/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 +23,6 @@ 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!

Yash's version of Boot.dev's Notely app.
Yash's version of Boot.dev's Notely app.
1 change: 1 addition & 0 deletions devops/learn-cicd-starter
Submodule learn-cicd-starter added at a84ed9
70 changes: 70 additions & 0 deletions internal/auth/get_api_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
tests := []struct {
name string
header string
wantKey string
wantErr string
}{
{
name: "valid api key",
header: "ApiKey my-secret-key",
wantKey: "my-secret-key",
},
{
name: "missing authorization header",
wantErr: ErrNoAuthHeaderIncluded.Error(),
},
{
name: "wrong auth scheme",
header: "Bearer token",
wantErr: "malformed authorization header",
},
{
name: "missing api key",
header: "ApiKey",
wantErr: "malformed authorization header",
},
{
name: "empty api key",
header: "ApiKey ",
wantErr: "malformed authorization header",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
headers := http.Header{}
if tt.header != "" {
headers.Set("Authorization", tt.header)
}

gotKey, err := GetAPIKey(headers)

if gotKey != tt.wantKey {
t.Fatalf("expected key %q, got %q", tt.wantKey, gotKey)
}

if tt.wantErr == "" {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
return
}

if err == nil {
t.Fatal("expected an error but got nil")
}

if err.Error() != tt.wantErr {
t.Fatalf("expected error %q, got %q", tt.wantErr, err.Error())
}
})
}
}
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
Binary file added vendor/.DS_Store
Binary file not shown.
Binary file added vendor/github.com/.DS_Store
Binary file not shown.