Skip to content
Merged
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
110 changes: 110 additions & 0 deletions .github/workflows/defifundr-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: DefiFundr CI

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
cache: true

- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.2

- name: Lint code
run: |
export PATH=$PATH:$(go env GOPATH)/bin
golangci-lint run --timeout=5m

test:
name: Test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD || 'secret' }}
POSTGRES_USER: ${{ secrets.DB_USER || 'root' }}
POSTGRES_DB: ${{ secrets.DB_NAME || 'defi' }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5433:5432
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
cache: true

- name: "Create env file"
run: |
touch .env
echo "${{ secrets.ENV_FILE }}" > .env
cat .env

- name: Install golang-migrate
run: |
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-amd64.tar.gz | tar xvz
sudo mv migrate /usr/bin/migrate
which migrate

- name: Run database migrations
run: migrate -path db/migrations -database "postgresql://${{ secrets.DB_USER || 'root' }}:${{ secrets.DB_PASSWORD || 'secret' }}@localhost:5433/${{ secrets.DB_NAME || 'defi' }}?sslmode=disable" -verbose up

- name: Install dependencies
run: go mod download

- name: Run tests
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
env:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check previous CI implementation. Use similar strategies, avoid exposing sensitive data in CI implementation

DB_SOURCE: postgresql://${{ secrets.DB_USER || 'root' }}:${{ secrets.DB_PASSWORD || 'secret' }}@localhost:5433/${{ secrets.DB_NAME || 'defi' }}?sslmode=disable

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
fail_ci_if_error: false

build:
name: Build
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
cache: true

- name: Build application
run: go build -v -o defifundr_backend ./cmd/api

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: defifundr-backend
path: defifundr_backend
retention-days: 5
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
linters:
enable:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduce sensitivity of linter for now

- errcheck
- govet

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck

run:
timeout: 5m
9 changes: 7 additions & 2 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ package main

import (
"fmt"
"log"
"net/http"
)


func main() {
fmt.Println("Hello, World!")
http.ListenAndServe(":8080", nil)

// Fix: Check error return value of ListenAndServe
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}
1 change: 1 addition & 0 deletions db/seeds/seed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package seeds