GitHub fork #148
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: Deploy (API) | |
| on: | |
| push: | |
| paths: | |
| - 'HackOMania.Api/**' | |
| - '.github/workflows/deploy-api.yml' | |
| branches: ["main"] | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment to deploy to' | |
| required: true | |
| default: 'production' | |
| type: choice | |
| options: | |
| - production | |
| jobs: | |
| build-and-deploy: | |
| concurrency: deploy | |
| runs-on: ubuntu-latest | |
| env: | |
| DOTNET_CLI_TELEMETRY_OPTOUT: 1 | |
| DOTNET_NOLOGO: true | |
| NUGET_XMLDOC_MODE: skip | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: 11.0.x | |
| include-prerelease: true | |
| cache: true | |
| cache-dependency-path: | | |
| global.json | |
| **/*.csproj | |
| # - name: Tests | |
| # run: dotnet test | |
| - name: Authenticate to Google Cloud | |
| id: auth | |
| uses: google-github-actions/auth@v3 | |
| with: | |
| token_format: access_token | |
| workload_identity_provider: projects/242247218750/locations/global/workloadIdentityPools/github/providers/github | |
| service_account: hackomania-api-deployer@hackomania-event-portal.iam.gserviceaccount.com | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Artifact Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: asia-southeast1-docker.pkg.dev | |
| username: oauth2accesstoken | |
| password: ${{ steps.auth.outputs.access_token }} | |
| - name: Extract metadata for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: asia-southeast1-docker.pkg.dev/hackomania-event-portal/hackomania-api/hackomania-api | |
| tags: | | |
| type=sha,prefix= | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: HackOMania.Api/Dockerfile | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| platforms: linux/amd64 | |
| - name: Deploy to Cloud Run | |
| id: deploy | |
| uses: google-github-actions/deploy-cloudrun@v2 | |
| with: | |
| service: hackomania-api | |
| region: asia-southeast1 | |
| image: asia-southeast1-docker.pkg.dev/hackomania-event-portal/hackomania-api/hackomania-api:latest | |
| tag: latest |