-
Notifications
You must be signed in to change notification settings - Fork 0
41 lines (34 loc) · 1.38 KB
/
delete-deployment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Delete Cloud Run instances on PR closed by merged
on:
pull_request:
branches:
- main
types: [closed]
jobs:
delete-cloud-run:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4.5.0
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GAR_JSON_KEY }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
- name: 'Display information about the current gcloud environment'
run: 'gcloud info'
- name: Check if Cloud Run service exists
id: check_service
run: |
SERVICE_NAME=${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }}
if gcloud run services describe $SERVICE_NAME --region=${{ vars.GCP_REGION }} > /dev/null 2>&1; then
echo "service_exists=true" >> $GITHUB_ENV
else
echo "service_exists=false" >> $GITHUB_ENV
fi
- name: 'Delete service'
if: env.service_exists == 'true'
run: gcloud run services delete ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}-${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }} --region=${{ vars.GCP_REGION }} --quiet