fix :Ci/cd #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ClearRouter CI/CD | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| name: Test & Build | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: clearrouter | |
| POSTGRES_PASSWORD: clearrouter_pass | |
| POSTGRES_DB: clearrouter | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.23' | |
| - name: Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Install dependencies | |
| run: go mod download | |
| - name: Run tests | |
| run: go test -v ./... | |
| env: | |
| DATABASE_URL: postgres://clearrouter:clearrouter_pass@localhost:5432/clearrouter?sslmode=disable | |
| - name: Build application | |
| run: go build -o main ./apps/backend/cmd/server/main.go | |
| - name: Install Gosec | |
| run: go install github.com/securego/gosec/v2/cmd/gosec@latest | |
| - name: Run Gosec | |
| run: gosec -fmt=sarif -out=gosec-report.sarif ./... | |
| - name: Run security scan | |
| uses: SecureCodeWarrior/github-action-add-sarif-contextual-training@v1 | |
| with: | |
| input-pattern: 'gosec-report.sarif' | |
| output-file: 'gosec-report.sarif' | |
| continue-on-error: true | |
| docker: | |
| name: Build Docker Image | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./apps/backend/Dockerfile.prod | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKER_USERNAME }}/clearrouter:latest | |
| ${{ secrets.DOCKER_USERNAME }}/clearrouter:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy: | |
| name: Deploy (Optional) | |
| runs-on: ubuntu-latest | |
| needs: [test, docker] | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Deploy notification | |
| run: | | |
| echo "🚀 Ready to deploy!" | |
| echo "Docker image: ${{ secrets.DOCKER_USERNAME }}/clearrouter:${{ github.sha }}" | |
| echo "Add your deployment steps here (SSH, Kubernetes, etc.)" |