name: Build and Deploy on: push: branches: [main, develop] pull_request: branches: [main] env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Container Registry if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=sha - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: ./docker platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | VITE_COUCHDB_URL=${{ vars.VITE_COUCHDB_URL || 'http://localhost:5984' }} VITE_COUCHDB_USER=${{ vars.VITE_COUCHDB_USER || 'admin' }} VITE_COUCHDB_PASSWORD=${{ secrets.VITE_COUCHDB_PASSWORD || 'change-this-secure-password' }} APP_BASE_URL=${{ vars.APP_BASE_URL || 'http://localhost:8080' }} VITE_GOOGLE_CLIENT_ID=${{ vars.VITE_GOOGLE_CLIENT_ID || '' }} VITE_GITHUB_CLIENT_ID=${{ vars.VITE_GITHUB_CLIENT_ID || '' }} NODE_ENV=production cache-from: type=gha cache-to: type=gha,mode=max - name: Build with Bake (Alternative) if: false # Set to true to use bake instead uses: docker/bake-action@v4 with: workdir: ./docker files: docker-bake.hcl targets: prod push: ${{ github.event_name != 'pull_request' }} test: runs-on: ubuntu-latest needs: build if: github.event_name == 'pull_request' steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Bun uses: oven-sh/setup-bun@v1 with: bun-version: latest - name: Install dependencies run: bun install --frozen-lockfile - name: Run linting run: bun run lint - name: Run type checking run: bun run type-check - name: Run tests run: bun run test deploy: runs-on: ubuntu-latest needs: [build, test] if: github.ref == 'refs/heads/main' && github.event_name == 'push' environment: production steps: - name: Deploy to production run: | echo "Deploy to production server" # Add your deployment commands here # Example: SSH to server and pull the new image