Skip to content

Fix cd workflow clean #1505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
36f93df
README.md
OldGambler May 8, 2025
31c72fd
Merge pull request #1 from OldGambler/addtests
OldGambler May 8, 2025
62d6759
Update README.md
OldGambler May 8, 2025
edddde3
commit number 1
May 8, 2025
5fdad0f
Merge branch 'addtests' of https://github.com/OldGambler/learn-cicd-s…
May 8, 2025
fe8633b
commit number 2
May 8, 2025
9e99971
commmit 3
May 8, 2025
47fd9fd
commit 4
May 9, 2025
1bed5f8
renamed auth_tests.go to auth_test.go, a simple s
May 9, 2025
9c89fa7
fixed the test to ApiKeys instead of Bearer
May 9, 2025
af4b7e5
ci.yml should run tests now
May 9, 2025
b9359e2
added -cover?
May 9, 2025
da7db76
how about now?
May 9, 2025
9abc476
now?
May 9, 2025
92ddbd3
added a badge
May 9, 2025
3b7f589
main commit
May 9, 2025
c53afb9
new style go fmt ./...
May 9, 2025
66f1118
Merge branch 'main' into addtests
OldGambler May 9, 2025
39d7d91
Merge pull request #2 from OldGambler/addtests
OldGambler May 9, 2025
9f8c47d
fixed the yml
May 9, 2025
fc012c1
Merge pull request #3 from OldGambler/addtests
OldGambler May 9, 2025
9b94246
added staticcheck to yml
May 9, 2025
2bc312b
Merge pull request #4 from OldGambler/addtests
OldGambler May 9, 2025
8dee7ce
got rid of unused
May 9, 2025
32f6837
Merge pull request #5 from OldGambler/addtests
OldGambler May 9, 2025
45ba60b
gosec added to yml
May 9, 2025
c890500
Merge pull request #6 from OldGambler/addtests
OldGambler May 9, 2025
e6744e9
using gosec to fix everything
May 9, 2025
574947b
Merge pull request #7 from OldGambler/addtests
OldGambler May 9, 2025
96f3816
fixed the gosec function problems
May 9, 2025
9a30cee
Merge pull request #8 from OldGambler/addtests
OldGambler May 9, 2025
2ac43c2
fixd the yml hopefully will work better now
May 9, 2025
650efba
Merge pull request #9 from OldGambler/addtests
OldGambler May 9, 2025
b4dcdef
added a new yml
May 9, 2025
a860e5a
Merge pull request #10 from OldGambler/addtests
OldGambler May 9, 2025
5cfae38
changed version
May 9, 2025
e66729c
Merge pull request #11 from OldGambler/addtests
OldGambler May 9, 2025
ba9ec9a
redone cd and ci
May 9, 2025
4e16311
Merge pull request #12 from OldGambler/addtests
OldGambler May 9, 2025
f039ec4
just copied the code
May 9, 2025
43d33b9
Merge pull request #13 from OldGambler/addtests
OldGambler May 9, 2025
1d86039
Fix Docker image tag in CD workflow
May 13, 2025
6d067fa
Merge pull request #14 from OldGambler/fix-cd-workflow
OldGambler May 13, 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
2 changes: 2 additions & 0 deletions .env.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exit
PORT=8888
81 changes: 81 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: cd

on:
push:
branches: [main]

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

<<<<<<< HEAD
=======
# Add permissions for the job
permissions:
contents: "read"
id-token: "write"

>>>>>>> 3b4c6ab (Fix Docker image tag in CD workflow)
steps:
- name: Check out code
uses: actions/checkout@v4

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

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

on:
push:
branches: [main]

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

# Add permissions for the job
permissions:
contents: "read"
id-token: "write"

steps:
- name: Check out code
uses: actions/checkout@v4

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

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

# Setup gcloud after buildprod runs
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
with:
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
project_id: notely-459323

# Build and push Docker image
- name: "Build and push Docker image"
run: "gcloud builds submit --tag us-central1-docker.pkg.dev/notely-459323/notely/notely-app:latest ."<<<<<<< HEAD
=======

# Setup gcloud after buildprod runs
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v1"
with:
service_account_key: ${{ secrets.GCP_CREDENTIALS }}
project_id: notely-459323

# Build and push Docker image
- name: "Build and push Docker image"
run: "gcloud builds submit --tag us-central1-docker.pkg.dev/notely-459323/notely/notely-app:latest ."
>>>>>>> 3b4c6ab (Fix Docker image tag in CD workflow)
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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.22.2"

- name: Run unit tests
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.22.2"

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

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

- name: Run staticcheck
run: staticcheck ./...
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# learn-cicd-starter (Notely)

[![ci](https://github.com/OldGambler/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
Expand All @@ -21,3 +23,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!

"Matt's version of Boot.dev's Notely app."
56 changes: 56 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKey(t *testing.T) {
testCases := []struct {
name string
authHeader string
expected string
expectError bool
}{
{
name: "Valid Token",
authHeader: "ApiKey Jojo",
expected: "Jojo",
expectError: false,
},
{
name: "Bearer instead of ApiKey",
authHeader: "Bearer L",
expected: "Kira",
expectError: true,
},
{
name: "Empty Header",
authHeader: "",
expected: "",
expectError: true,
},
{
name: "No Token",
authHeader: "ApiKey ",
expected: "",
expectError: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
headers := make(http.Header)
headers.Add("Authorization", tc.authHeader)
apiKey, err := GetAPIKey(headers)
if tc.expectError && err == nil {
t.Fatalf("expected error but got none")
}
if !tc.expectError && err != nil {
t.Fatalf("expected no error but got: %v", err)
}
if err == nil && apiKey != tc.expected {
t.Fatalf("expected API key %q, got %q", tc.expected, apiKey)
}
})
}
}
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 writing dat: %s", 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: 10 * time.Second,
}

log.Printf("Serving on port: %s\n", port)
Expand Down