| 
 | 1 | +name: CI Pipeline  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  push:  | 
 | 5 | +    branches: [ main, master, develop, 'feature/**' ]  | 
 | 6 | +    tags: [ 'v*' ]  | 
 | 7 | +  pull_request:  | 
 | 8 | +    branches: [ main, master, develop ]  | 
 | 9 | + | 
 | 10 | +env:  | 
 | 11 | +  GO_VERSION: 1.22  | 
 | 12 | +  REGISTRY: ghcr.io  | 
 | 13 | +  IMAGE_NAME: ${{ github.repository }}  | 
 | 14 | + | 
 | 15 | +jobs:  | 
 | 16 | +  # Code quality and security checks  | 
 | 17 | +  quality:  | 
 | 18 | +    name: Code Quality & Security  | 
 | 19 | +    runs-on: ubuntu-latest  | 
 | 20 | +    steps:  | 
 | 21 | +    - name: Checkout code  | 
 | 22 | +      uses: actions/checkout@v4  | 
 | 23 | + | 
 | 24 | +    - name: Set up Go  | 
 | 25 | +      uses: actions/setup-go@v5  | 
 | 26 | +      with:  | 
 | 27 | +        go-version: ${{ env.GO_VERSION }}  | 
 | 28 | + | 
 | 29 | +    - name: Clean Go module cache directory  | 
 | 30 | +      run: |  | 
 | 31 | +        rm -rf ~/.cache/go-build || true  | 
 | 32 | +        rm -rf ~/go/pkg/mod || true  | 
 | 33 | +
  | 
 | 34 | +    - name: Cache Go modules  | 
 | 35 | +      uses: actions/cache@v4  | 
 | 36 | +      with:  | 
 | 37 | +        path: |  | 
 | 38 | +          ~/.cache/go-build  | 
 | 39 | +          ~/go/pkg/mod  | 
 | 40 | +        key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}  | 
 | 41 | +        restore-keys: |  | 
 | 42 | +          ${{ runner.os }}-go-  | 
 | 43 | +
  | 
 | 44 | +    - name: Install dependencies  | 
 | 45 | +      run: make deps  | 
 | 46 | + | 
 | 47 | +    - name: Format check  | 
 | 48 | +      run: |  | 
 | 49 | +        make fmt  | 
 | 50 | +        if [ -n "$(git status --porcelain)" ]; then  | 
 | 51 | +          echo "Code is not formatted properly"  | 
 | 52 | +          git diff  | 
 | 53 | +          exit 1  | 
 | 54 | +        fi  | 
 | 55 | +
  | 
 | 56 | +    - name: Build frontend assets  | 
 | 57 | +      run: make build-frontend  | 
 | 58 | + | 
 | 59 | +    - name: Install golangci-lint v2  | 
 | 60 | +      run: |  | 
 | 61 | +        curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin" v2.4.0  | 
 | 62 | +        echo "$(go env GOPATH)/bin" >> $GITHUB_PATH  | 
 | 63 | +
  | 
 | 64 | +    - name: Lint  | 
 | 65 | +      run: golangci-lint run --timeout=10m  | 
 | 66 | + | 
 | 67 | +    - name: Security check with gosec  | 
 | 68 | +      run: |  | 
 | 69 | +        # Install gosec  | 
 | 70 | +        go install github.com/securego/gosec/v2/cmd/gosec@latest  | 
 | 71 | +
  | 
 | 72 | +        # Run gosec (allow it to fail)  | 
 | 73 | +        echo "Running gosec security scan..."  | 
 | 74 | +        gosec ./... || true  | 
 | 75 | +
  | 
 | 76 | +        echo "Gosec scan completed"  | 
 | 77 | +
  | 
 | 78 | +    - name: Verify Go modules  | 
 | 79 | +      run: go mod verify  | 
 | 80 | + | 
 | 81 | +  # Comprehensive testing  | 
 | 82 | +  test:  | 
 | 83 | +    name: Test Suite  | 
 | 84 | +    runs-on: ubuntu-latest  | 
 | 85 | +    needs: quality  | 
 | 86 | +    strategy:  | 
 | 87 | +      matrix:  | 
 | 88 | +        go-version: [1.22]  | 
 | 89 | +    services:  | 
 | 90 | +      postgres:  | 
 | 91 | +        image: postgres:16  | 
 | 92 | +        env:  | 
 | 93 | +          POSTGRES_PASSWORD: ci_test_password_postgres  | 
 | 94 | +          POSTGRES_USER: ci_test_user  | 
 | 95 | +          POSTGRES_DB: ci_test_db  | 
 | 96 | +        options: >-  | 
 | 97 | +          --health-cmd pg_isready  | 
 | 98 | +          --health-interval 10s  | 
 | 99 | +          --health-timeout 5s  | 
 | 100 | +          --health-retries 5  | 
 | 101 | +        ports:  | 
 | 102 | +          - 5432:5432  | 
 | 103 | + | 
 | 104 | +      mysql:  | 
 | 105 | +        image: mysql:8.0  | 
 | 106 | +        env:  | 
 | 107 | +          MYSQL_ROOT_PASSWORD: ci_test_root_password_mysql  | 
 | 108 | +          MYSQL_DATABASE: ci_test_db  | 
 | 109 | +          MYSQL_USER: ci_test_user  | 
 | 110 | +          MYSQL_PASSWORD: ci_test_password_mysql  | 
 | 111 | +        options: >-  | 
 | 112 | +          --health-cmd="mysqladmin ping"  | 
 | 113 | +          --health-interval=10s  | 
 | 114 | +          --health-timeout=5s  | 
 | 115 | +          --health-retries=3  | 
 | 116 | +        ports:  | 
 | 117 | +          - 3306:3306  | 
 | 118 | + | 
 | 119 | +      redis:  | 
 | 120 | +        image: redis:7  | 
 | 121 | +        options: >-  | 
 | 122 | +          --health-cmd "redis-cli ping"  | 
 | 123 | +          --health-interval 10s  | 
 | 124 | +          --health-timeout 5s  | 
 | 125 | +          --health-retries 5  | 
 | 126 | +        ports:  | 
 | 127 | +          - 6379:6379  | 
 | 128 | + | 
 | 129 | +    steps:  | 
 | 130 | +    - name: Checkout code  | 
 | 131 | +      uses: actions/checkout@v4  | 
 | 132 | + | 
 | 133 | +    - name: Set up Go ${{ matrix.go-version }}  | 
 | 134 | +      uses: actions/setup-go@v5  | 
 | 135 | +      with:  | 
 | 136 | +        go-version: ${{ matrix.go-version }}  | 
 | 137 | + | 
 | 138 | +    - name: Clean Go module cache directory  | 
 | 139 | +      run: |  | 
 | 140 | +        rm -rf ~/.cache/go-build || true  | 
 | 141 | +        rm -rf ~/go/pkg/mod || true  | 
 | 142 | +
  | 
 | 143 | +    - name: Cache Go modules  | 
 | 144 | +      uses: actions/cache@v4  | 
 | 145 | +      with:  | 
 | 146 | +        path: |  | 
 | 147 | +          ~/.cache/go-build  | 
 | 148 | +          ~/go/pkg/mod  | 
 | 149 | +        key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}  | 
 | 150 | + | 
 | 151 | +    - name: Install dependencies  | 
 | 152 | +      run: make deps  | 
 | 153 | + | 
 | 154 | +    - name: Run unit tests  | 
 | 155 | +      run: make test  | 
 | 156 | +      env:  | 
 | 157 | +        POSTGRES_URL: postgres://testuser:testpass@localhost:5432/testdb?sslmode=disable  | 
 | 158 | +        MYSQL_URL: testuser:testpass@tcp(localhost:3306)/testdb  | 
 | 159 | +        REDIS_URL: redis://localhost:6379  | 
 | 160 | + | 
 | 161 | +    - name: Verify plugin functionality  | 
 | 162 | +      run: |  | 
 | 163 | +        echo "Testing plugin build and basic functionality..."  | 
 | 164 | +        make build  | 
 | 165 | +        echo "Plugin built successfully"  | 
 | 166 | +
  | 
 | 167 | +    - name: Run benchmarks  | 
 | 168 | +      run: make benchmark  | 
 | 169 | + | 
 | 170 | +    - name: Upload coverage to Codecov  | 
 | 171 | +      if: matrix.go-version == '1.22'  | 
 | 172 | +      uses: codecov/codecov-action@v4  | 
 | 173 | +      with:  | 
 | 174 | +        file: ./coverage.out  | 
 | 175 | +        flags: unittests  | 
 | 176 | +        name: codecov-umbrella  | 
 | 177 | + | 
 | 178 | +  # Docker image build and push  | 
 | 179 | +  docker:  | 
 | 180 | +    name: Docker Build & Push  | 
 | 181 | +    runs-on: ubuntu-latest  | 
 | 182 | +    needs: [quality, test]  | 
 | 183 | +    permissions:  | 
 | 184 | +      contents: read  | 
 | 185 | +      packages: write  | 
 | 186 | +    steps:  | 
 | 187 | +    - name: Checkout code  | 
 | 188 | +      uses: actions/checkout@v4  | 
 | 189 | + | 
 | 190 | +    - name: Set up QEMU  | 
 | 191 | +      uses: docker/setup-qemu-action@v3  | 
 | 192 | + | 
 | 193 | +    - name: Set up Docker Buildx  | 
 | 194 | +      uses: docker/setup-buildx-action@v3  | 
 | 195 | + | 
 | 196 | +    - name: Log in to Container Registry  | 
 | 197 | +      if: github.event_name != 'pull_request'  | 
 | 198 | +      uses: docker/login-action@v3  | 
 | 199 | +      with:  | 
 | 200 | +        registry: ${{ env.REGISTRY }}  | 
 | 201 | +        username: ${{ github.actor }}  | 
 | 202 | +        password: ${{ secrets.GITHUB_TOKEN }}  | 
 | 203 | + | 
 | 204 | +    - name: Generate Docker tag  | 
 | 205 | +      id: docker-tag  | 
 | 206 | +      run: |  | 
 | 207 | +        if [ "${{ github.event_name }}" = "pull_request" ]; then  | 
 | 208 | +          TAG="pr-${{ github.event.number }}"  | 
 | 209 | +        else  | 
 | 210 | +          TAG="${{ github.ref_name }}"  | 
 | 211 | +          # Sanitize tag name  | 
 | 212 | +          TAG=$(echo "$TAG" | sed 's/[^a-zA-Z0-9_.-]/-/g')  | 
 | 213 | +        fi  | 
 | 214 | +        echo "tag=$TAG" >> $GITHUB_OUTPUT  | 
 | 215 | +        echo "Generated Docker tag: $TAG"  | 
 | 216 | +
  | 
 | 217 | +    - name: Generate lowercase image name  | 
 | 218 | +      id: image-name  | 
 | 219 | +      run: |  | 
 | 220 | +        IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')  | 
 | 221 | +        echo "name=$IMAGE_NAME_LOWER" >> $GITHUB_OUTPUT  | 
 | 222 | +        echo "Generated lowercase image name: $IMAGE_NAME_LOWER"  | 
 | 223 | +
  | 
 | 224 | +    - name: Extract metadata  | 
 | 225 | +      id: meta  | 
 | 226 | +      uses: docker/metadata-action@v5  | 
 | 227 | +      with:  | 
 | 228 | +        images: ${{ env.REGISTRY }}/${{ steps.image-name.outputs.name }}  | 
 | 229 | +        tags: |  | 
 | 230 | +          type=raw,value=${{ steps.docker-tag.outputs.tag }}  | 
 | 231 | +          type=raw,value=latest,enable={{is_default_branch}}  | 
 | 232 | +
  | 
 | 233 | +    - name: Build and push Docker image  | 
 | 234 | +      uses: docker/build-push-action@v5  | 
 | 235 | +      with:  | 
 | 236 | +        context: .  | 
 | 237 | +        file: ./Dockerfile  | 
 | 238 | +        platforms: linux/amd64,linux/arm64  | 
 | 239 | +        push: ${{ github.event_name != 'pull_request' }}  | 
 | 240 | +        tags: ${{ steps.meta.outputs.tags }}  | 
 | 241 | +        labels: ${{ steps.meta.outputs.labels }}  | 
 | 242 | +        cache-from: type=gha  | 
 | 243 | +        cache-to: type=gha,mode=max  | 
 | 244 | +        build-args: |  | 
 | 245 | +          VERSION=${{ github.sha }}  | 
 | 246 | +          BUILD_DATE=${{ github.event.head_commit.timestamp }}  | 
 | 247 | +
  | 
 | 248 | +
  | 
 | 249 | +  # Security scanning  | 
 | 250 | +  security:  | 
 | 251 | +    name: Security Scan  | 
 | 252 | +    runs-on: ubuntu-latest  | 
 | 253 | +    needs: [docker]  | 
 | 254 | +    if: github.event_name != 'pull_request' && needs.docker.result == 'success'  | 
 | 255 | +    steps:  | 
 | 256 | +    - name: Checkout code  | 
 | 257 | +      uses: actions/checkout@v4  | 
 | 258 | + | 
 | 259 | +    - name: Generate Docker tag for scanning  | 
 | 260 | +      id: scan-tag  | 
 | 261 | +      run: |  | 
 | 262 | +        if [ "${{ github.event_name }}" = "pull_request" ]; then  | 
 | 263 | +          TAG="pr-${{ github.event.number }}"  | 
 | 264 | +        else  | 
 | 265 | +          TAG="${{ github.ref_name }}"  | 
 | 266 | +          # Sanitize tag name  | 
 | 267 | +          TAG=$(echo "$TAG" | sed 's/[^a-zA-Z0-9_.-]/-/g')  | 
 | 268 | +        fi  | 
 | 269 | +        echo "tag=$TAG" >> $GITHUB_OUTPUT  | 
 | 270 | +
  | 
 | 271 | +    - name: Generate lowercase image name for scanning  | 
 | 272 | +      id: scan-image-name  | 
 | 273 | +      run: |  | 
 | 274 | +        IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')  | 
 | 275 | +        IMAGE_REF="${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ steps.scan-tag.outputs.tag }}"  | 
 | 276 | +        echo "image_ref=$IMAGE_REF" >> $GITHUB_OUTPUT  | 
 | 277 | +        echo "Scanning Docker image: $IMAGE_REF"  | 
 | 278 | +
  | 
 | 279 | +    - name: Wait for image availability  | 
 | 280 | +      run: |  | 
 | 281 | +        IMAGE_REF="${{ steps.scan-image-name.outputs.image_ref }}"  | 
 | 282 | +        echo "Checking if image exists: $IMAGE_REF"  | 
 | 283 | +
  | 
 | 284 | +        # Try to pull the image to verify it exists  | 
 | 285 | +        if docker manifest inspect "$IMAGE_REF" >/dev/null 2>&1; then  | 
 | 286 | +          echo "✅ Image found: $IMAGE_REF"  | 
 | 287 | +          echo "SCAN_IMAGE=true" >> $GITHUB_ENV  | 
 | 288 | +        else  | 
 | 289 | +          echo "⚠️ Image not found: $IMAGE_REF"  | 
 | 290 | +          echo "SCAN_IMAGE=false" >> $GITHUB_ENV  | 
 | 291 | +          echo "Skipping Trivy scan - image not available"  | 
 | 292 | +        fi  | 
 | 293 | +
  | 
 | 294 | +    - name: Run Trivy vulnerability scanner  | 
 | 295 | +      if: env.SCAN_IMAGE == 'true'  | 
 | 296 | +      uses: aquasecurity/trivy-action@master  | 
 | 297 | +      with:  | 
 | 298 | +        image-ref: ${{ steps.scan-image-name.outputs.image_ref }}  | 
 | 299 | +        format: 'sarif'  | 
 | 300 | +        output: 'trivy-results.sarif'  | 
 | 301 | + | 
 | 302 | +    - name: Upload Trivy scan results to GitHub Security tab  | 
 | 303 | +      if: env.SCAN_IMAGE == 'true' && always()  | 
 | 304 | +      uses: github/codeql-action/upload-sarif@v3  | 
 | 305 | +      with:  | 
 | 306 | +        sarif_file: 'trivy-results.sarif'  | 
0 commit comments