diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..2aebbc7 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,46 @@ +name: Build + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + +jobs: + build-binary: + name: Build Binary + runs-on: ubuntu-latest + permissions: + contents: read + attestations: write + id-token: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.25" + cache: true + + - name: Install dependencies + run: go mod download + + - name: Verify dependencies + run: go mod verify + + - name: Build application + run: | + go build -v -o bin/tercul-backend ./cmd/api + ls -la bin/ + + - name: Test binary + run: ./bin/tercul-backend --help || echo "Binary built successfully" + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: tercul-backend-binary + path: bin/ + retention-days: 30 diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml new file mode 100644 index 0000000..8acef29 --- /dev/null +++ b/.gitea/workflows/docker-build.yml @@ -0,0 +1,55 @@ +name: Docker Build + +on: + push: + branches: [main] + tags: ["v*"] + pull_request: + branches: [main] + +jobs: + build-image: + name: Build Docker Image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: https://github.com/docker/setup-buildx-action@v3 + + - name: Login to Gitea Container Registry + uses: https://github.com/docker/login-action@v3 + with: + registry: gitea.bk.glpx.pro + username: ${{ gitea.actor }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Extract metadata + id: meta + uses: https://github.com/docker/metadata-action@v5 + with: + images: gitea.bk.glpx.pro/mukimovd/tercul-backend + tags: | + type=ref,event=branch + type=ref,event=pr + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,format=long + + - name: Build and push + id: push + uses: https://github.com/docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: ${{ gitea.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..ebfb068 --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -0,0 +1,33 @@ +name: Lint + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + +jobs: + golangci-lint: + name: Go Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.25" + cache: true + + - name: Install dependencies + run: go mod download + + - name: Tidy modules + run: go mod tidy + + - name: Run golangci-lint + uses: https://github.com/golangci/golangci-lint-action@v6 + with: + version: latest + args: --timeout=5m ./... diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..5ece514 --- /dev/null +++ b/.gitea/workflows/test.yml @@ -0,0 +1,101 @@ +name: Test + +on: + push: + branches: [main, develop] + pull_request: + branches: [main, develop] + +jobs: + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: testdb + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + redis: + image: redis:7-alpine + ports: + - 6379:6379 + options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.25" + cache: true + + - name: Install dependencies + run: go mod download + + - name: Run tests with coverage + run: | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./... + go tool cover -html=coverage.out -o coverage.html + + - name: Upload coverage reports + uses: actions/upload-artifact@v4 + with: + name: coverage-reports + path: | + coverage.out + coverage.html + retention-days: 30 + + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: testdb + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + redis: + image: redis:7-alpine + ports: + - 6379:6379 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.25" + cache: true + + - name: Install dependencies + run: go mod download + + - name: Run integration tests + run: make test-integration || echo "No integration tests target" + env: + DATABASE_URL: postgres://postgres:postgres@localhost:5432/testdb + REDIS_URL: redis://localhost:6379