Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 1.14 KB

only-master.md

File metadata and controls

31 lines (25 loc) · 1.14 KB

Only run GitHub Action on push to master / main

Spotted in this Cloud Run example:

name: Build and Deploy to Cloud Run

on:
  push:
    branches:
    - master

Useful if you don't want people opening pull requests against your repo that inadvertantly trigger a deploy action!

An alternative mechanism I've used is to gate the specific deploy steps in the action, like this.

    # Only run the deploy if push was to master
    - name: Set up Cloud Run
      if: github.ref == 'refs/heads/master'
      uses: GoogleCloudPlatform/github-actions/setup-gcloud@v0
      with:
        version: '275.0.0'
        service_account_email: ${{ secrets.GCP_SA_EMAIL }}
        service_account_key: ${{ secrets.GCP_SA_KEY }}
    - name: Deploy to Cloud Run
      if: github.ref == 'refs/heads/master'
      run: |-
        gcloud config set run/region us-central1