Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Action In-line if

So I have the following workflow and its working perfectly. I now want to enhance it and when I am doing a PR to master, I want to set NETLIFY_DEPLOY_TO_PROD: false instead of it being true? Do I have to duplicate this all in a new workflow, or could do some inline if check of github.event_name === push ? true : false

name: 'Netlify Deploy'

on:
  push:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: jsmrcaga/action-netlify-deploy@master
        with:
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} 
          NETLIFY_SITE_ID: ${{ secrets.SITE_ID }} 
          NETLIFY_DEPLOY_MESSAGE: "${{ github.event.head_commit.message }}"
          NETLIFY_DEPLOY_TO_PROD: true
like image 320
jrock2004 Avatar asked Oct 27 '25 08:10

jrock2004


1 Answers

You could set an environment variable to indicate if deploy to prod should happen, and change it depending on the event name:

name: Netlify Deploy

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

env:
  DEPLOY: false

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Deploy on pushes
        if: github.event_name == 'push'
        run: echo 'DEPLOY=true' >> "$GITHUB_ENV"

      - uses: jsmrcaga/action-netlify-deploy@master
        with:
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
          NETLIFY_SITE_ID: ${{ secrets.SITE_ID }}
          NETLIFY_DEPLOY_MESSAGE: ${{ github.event.head_commit.message }}
          NETLIFY_DEPLOY_TO_PROD: ${{ env.DEPLOY }}
like image 88
Benjamin W. Avatar answered Oct 29 '25 05:10

Benjamin W.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!