Merge pull request #11 from Spchdt/new-actions #29
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: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| REGION: us-central1 | |
| SERVICE_NAME: jemmie-backend | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| enable-cache: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: uv sync --extra dev | |
| - name: Ruff lint | |
| run: uv run ruff check . | |
| - name: Ruff format check | |
| run: uv run ruff format --check . | |
| - name: Mypy type check | |
| run: uv run mypy src tests | |
| - name: Pytest | |
| run: uv run pytest -q --ignore-glob="**/.git/**" || [ $? -eq 5 ] | |
| deploy: | |
| needs: check | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Google Auth | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Configure Docker | |
| run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev | |
| - name: Build and Push | |
| run: | | |
| docker build --target production -t ${{ env.REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/jemmie-backend/${{ env.SERVICE_NAME }}:${{ github.sha }} . | |
| docker push ${{ env.REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/jemmie-backend/${{ env.SERVICE_NAME }}:${{ github.sha }} | |
| - name: Deploy to Cloud Run | |
| run: | | |
| gcloud run deploy ${{ env.SERVICE_NAME }} \ | |
| --image=${{ env.REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/jemmie-backend/${{ env.SERVICE_NAME }}:${{ github.sha }} \ | |
| --region=${{ env.REGION }} \ | |
| --platform=managed \ | |
| --session-affinity \ | |
| --timeout=3600 \ | |
| --min-instances=1 \ | |
| --port=8080 \ | |
| --allow-unauthenticated \ | |
| --set-env-vars="GOOGLE_GENAI_USE_VERTEXAI=TRUE,GOOGLE_CLOUD_PROJECT=${{ secrets.GCP_PROJECT_ID }},GOOGLE_CLOUD_LOCATION=${{ env.REGION }}" | |
| - name: Get Service URL | |
| run: | | |
| SERVICE_URL=$(gcloud run services describe ${{ env.SERVICE_NAME }} \ | |
| --region=${{ env.REGION }} \ | |
| --format='value(status.url)') | |
| echo "Service deployed at: $SERVICE_URL" | |
| echo "WebSocket endpoint: wss://${SERVICE_URL#https://}/ws/{device_id}" |