1+ name : ' Deploy to Cloud Run'
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ environment :
7+ description : ' deploy tag to environment'
8+ required : true
9+ default : ' dev'
10+ type : choice
11+ options :
12+ - dev
13+ - prod
14+
15+ jobs :
16+
17+ # #####################################################################
18+ # env: prod (bcr-relay)
19+ deploy :
20+ name : deploy to prod
21+ if : github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'prod'
22+
23+ permissions :
24+ contents : read
25+ deployments : write
26+ id-token : write
27+ concurrency :
28+ group : ${{ github.workflow }}-${{ github.event.inputs.environment || github.event_name }}
29+ cancel-in-progress : true
30+
31+ runs-on : ubuntu-latest
32+ environment : prod
33+
34+ env :
35+ GCR_SERVICE : ${{ vars.GCR_SERVICE }}
36+ GCR_REGION : ${{ vars.GCR_REGION }}
37+ GAR_PATH : ${{ vars.GAR_PATH }}
38+ IMAGE_NAME : ${{ vars.IMAGE_NAME }}
39+
40+ steps :
41+ - name : Validate tag on dispatch
42+ run : |
43+ if [[ "${{ github.ref_type }}" != 'tag' ]]; then
44+ echo "::error::Manual deployments must be triggered from a tag."
45+ echo "::error::Please select a tag from the 'Use workflow from' dropdown, not a branch."
46+ exit 1
47+ fi
48+ echo "Validation successful: Running from tag '${{ github.ref_name }}'."
49+
50+ - name : Authenticate to GCP
51+ id : auth
52+ uses : google-github-actions/auth@ba79af03959ebeac9769e648f473a284504d9193 # v2.1.10
53+ with :
54+ credentials_json : ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
55+
56+ - name : ' Set image tag to ${{ github.ref_name }}'
57+ id : tag
58+ run : |
59+ TAG=${{ github.ref_name }}
60+ SEMVER_TAG="${TAG#v}"
61+ echo "IMAGE_TAG=$SEMVER_TAG" >> "$GITHUB_OUTPUT"
62+
63+ - name : Deploy to Cloud Run
64+ uses : google-github-actions/deploy-cloudrun@2028e2d7d30a78c6910e0632e48dd561b064884d # v3
65+ with :
66+ service : ${{ env.GCR_SERVICE }}
67+ region : ${{ env.GCR_REGION }}
68+ image : ${{ env.GAR_PATH }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.IMAGE_TAG }}
69+
70+ # #####################################################################
71+ # env: dev (bcr-relay-dev)
72+ deploy-dev :
73+ name : deploy to dev
74+ if : github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'dev'
75+
76+ permissions :
77+ contents : read
78+ deployments : write
79+ id-token : write
80+ concurrency :
81+ group : ${{ github.workflow }}-${{ github.event.inputs.environment || github.event_name }}
82+ cancel-in-progress : true
83+
84+ runs-on : ubuntu-latest
85+ environment : dev
86+
87+ env :
88+ GCR_SERVICE : ${{ vars.GCR_SERVICE }}
89+ GCR_REGION : ${{ vars.GCR_REGION }}
90+ GAR_PATH : ${{ vars.GAR_PATH }}
91+ IMAGE_NAME : ${{ vars.IMAGE_NAME }}
92+
93+ steps :
94+ - name : Validate tag on dispatch
95+ run : |
96+ if [[ "${{ github.ref_type }}" != 'tag' ]]; then
97+ echo "::error::Manual deployments must be triggered from a tag."
98+ echo "::error::Please select a tag from the 'Use workflow from' dropdown, not a branch."
99+ exit 1
100+ fi
101+ echo "Validation successful: Running from tag '${{ github.ref_name }}'."
102+
103+ - name : Authenticate to GCP
104+ id : auth
105+ uses : google-github-actions/auth@ba79af03959ebeac9769e648f473a284504d9193 # v2.1.10
106+ with :
107+ credentials_json : ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
108+
109+ - name : ' Set image tag to ${{ github.ref_name }}'
110+ id : tag
111+ run : |
112+ TAG=${{ github.ref_name }}
113+ SEMVER_TAG="${TAG#v}"
114+ echo "IMAGE_TAG=$SEMVER_TAG" >> "$GITHUB_OUTPUT"
115+
116+ - name : Deploy to Cloud Run
117+ uses : google-github-actions/deploy-cloudrun@2028e2d7d30a78c6910e0632e48dd561b064884d # v3
118+ with :
119+ service : ${{ env.GCR_SERVICE }}
120+ region : ${{ env.GCR_REGION }}
121+ image : ${{ env.GAR_PATH }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.IMAGE_TAG }}
0 commit comments