Use environment variable in github action if
do it like this:
if: github.ref == 'specific-branch'
reference branch conditional
Though the original problem had been solved without environment vars, I'd like to share how it can be used with if conditions.
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Set env BRANCH
run: echo "BRANCH=$(echo $GITHUB_REF | cut -d'/' -f 3)" >> $GITHUB_ENV
- name: Set env NEED
run: |
if [[ $BRANCH == 'master' && $GITHUB_EVENT_NAME == 'push' ]]; then
echo "NEED=true" >> "$GITHUB_ENV"
else
echo "NEED=false" >> "$GITHUB_ENV"
fi
- name: Skip Deploy?
if: env.NEED != 'true'
run: echo "Only pushing to 'master' causes automatic deployment"
...
The first two steps set 2 env variables, the third step demonstrates what syntax you need to follow to use these vars in if conditions.