109 words
1 minute
Only run GitHub Action on push to master / main
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
Only run GitHub Action on push to master / main
https://mranv.pages.dev/posts/only-run-github-action-on-push-to-master-main/