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@master
      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

Created 2020-04-19T07:46:31-07:00, updated 2020-08-12T10:33:23-07:00 · History · Edit