Skip to content

Commit

Permalink
ci: add build workflow for backend (#106)
Browse files Browse the repository at this point in the history
* ci: add build workflow for backend

- Implemented a GitHub Actions workflow specifically for building the backend.
- Ensures backend changes are validated through automated builds.
- Improves reliability and consistency in the backend deployment pipeline.

* chore: change branch name from development to develop

* chore: change client test branch from main to develop

* fix: remove supabase db password env

* test: remove all test files
  • Loading branch information
Fingertips18 authored Jan 18, 2025
1 parent 253b612 commit c7133ce
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 490 deletions.
1 change: 0 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
PORT=<PORT>

SUPABASE_DB_PASSWORD=<SUPABASE_DB_PASSWORD>
SUPABASE_URI=<SUPABASE_URI>

# true | false
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/client-test.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Client Test Workflow
name: Client Test

on:
pull_request:
branches:
- main
- develop

jobs:
test:
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/go-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Backend - Build

on:
pull_request:
branches:
- develop
workflow_dispatch:

jobs:
build:
name: Build Application
runs-on: ubuntu-latest

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

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ">=1.23"

- name: Cache Go Modules
uses: actions/cache@v4
with:
path: ~/.cache/go-build
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-build-
- name: Check Go Version
run: go version

- name: Run Build
env:
PORT: ${{ vars.PORT }}
SUPABASE_URI: ${{ secrets.SUPABASE_URI }}
RUN_MIGRATIONS: ${{ vars.RUN_MIGRATIONS }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: |
if ! go build -tags netgo -ldflags '-s -w' -o app; then
echo "Build failed. Please check the logs."
exit 1
fi
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: backend-app
path: app
11 changes: 5 additions & 6 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Go Test Workflow
name: Backend Test

on:
pull_request:
branches:
- main
- develop

jobs:
test:
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: ">=1.23"

- name: Check Go Version
run: go version
Expand All @@ -29,9 +29,8 @@ jobs:
env:
SUPABASE_URI: ${{ secrets.SUPABASE_URI }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ENV: ${{ secrets.ENV }}
CLIENT_URL: ${{ secrets.CLIENT_URL }}
ENV: ${{ vars.ENV }}
EMAIL: ${{ secrets.EMAIL }}
EMAIL_APP_PASSWORD: ${{ secrets.EMAIL_APP_PASSWORD }}
TEST_EMAIL: ${{ secrets.TEST_EMAIL }}
TEST_EMAIL: ${{ vars.TEST_EMAIL }}
run: go test ./... -v
9 changes: 6 additions & 3 deletions configs/email_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package configs

import (
"log"
"errors"
"net/smtp"
"os"
)
Expand All @@ -13,12 +13,15 @@ var (

const SMTPADDRESS = "smtp.gmail.com:587"

func ConfigureEmail() {
func ConfigureEmail() error {
EMAIL := os.Getenv("EMAIL")
PASSWORD := os.Getenv("EMAIL_APP_PASSWORD")

if EMAIL == "" || PASSWORD == "" {
log.Fatal("EMAIL or EMAIL_APP_PASSWORD must be set")
return errors.New("EMAIL or EMAIL_APP_PASSWORD must be set")
}

SMTPAuth = smtp.PlainAuth("", EMAIL, PASSWORD, "smtp.gmail.com")
Email = EMAIL
return nil
}
25 changes: 0 additions & 25 deletions configs/email_config_test.go

This file was deleted.

60 changes: 0 additions & 60 deletions configs/load_env_test.go

This file was deleted.

8 changes: 5 additions & 3 deletions configs/setup_cors.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package configs

import (
"log"
"errors"
"os"

"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/cors"
)

func SetupCORS(app *fiber.App) {
func SetupCORS(app *fiber.App) error {
CLIENT_URL := os.Getenv("CLIENT_URL")
if CLIENT_URL == "" {
log.Fatal("CLIENT_URL must be set")
return errors.New("CLIENT_URL must be set")
}

app.Use(cors.New(cors.Config{
AllowOrigins: []string{CLIENT_URL},
AllowCredentials: true,
}))

return nil
}
52 changes: 0 additions & 52 deletions configs/setup_cors_test.go

This file was deleted.

24 changes: 0 additions & 24 deletions database/connection_test.go

This file was deleted.

56 changes: 0 additions & 56 deletions utils/email_service_test.go

This file was deleted.

Loading

0 comments on commit c7133ce

Please sign in to comment.