Add Cloudflare Tunnel sidecar to Cloud Run deployment #1
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: Preview Cleanup | |
| on: | |
| pull_request: | |
| types: [closed] | |
| permissions: | |
| contents: read | |
| id-token: write | |
| deployments: write | |
| jobs: | |
| cleanup: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - id: 'auth' | |
| uses: 'google-github-actions/auth@v2' | |
| with: | |
| workload_identity_provider: '${{ secrets.GC_WORKLOAD_IDENTITY_PROVIDER }}' | |
| service_account: '${{ secrets.GC_SERVICE_ACCOUNT }}' | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Remove Preview Traffic Tag | |
| run: | | |
| gcloud run services update-traffic cofacts-ai \ | |
| --region asia-east1 \ | |
| --remove-tags="pr-${{ github.event.number }}" || echo "Tag not found or service does not exist, skipping." | |
| - name: Deactivate GitHub Deployment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const environment = `pr-${context.issue.number}`; | |
| const { owner, repo } = context.repo; | |
| try { | |
| const deployments = await github.rest.repos.listDeployments({ | |
| owner, | |
| repo, | |
| environment, | |
| }); | |
| for (const deployment of deployments.data) { | |
| await github.rest.repos.createDeploymentStatus({ | |
| owner, | |
| repo, | |
| deployment_id: deployment.id, | |
| state: 'inactive', | |
| description: 'Preview environment deactivated.', | |
| }); | |
| } | |
| } catch (error) { | |
| console.error('Error deactivating deployments:', error); | |
| } |