I thought id share a little info on how to have a conditional statement for your actions that ONLY executes if you are on master.
Firstly, only run on pushes to master, and PRs to master.
on:
# Trigger the workflow on push or pull request for master only.
push:
branches:
- master
pull_request:
branches:
- master
Then finally, in any action:
# Upload to S3
- name: sync s3
# Do not deploy anything other than master
if: github.ref == 'refs/heads/master'
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-east-1'
SOURCE_DIR: 'dist'
The key above being: if: github.ref == 'refs/heads/master'
Personally I wish they would make the branch name an env variable to make this much cleaner but Actions are still new.
Happy deploying!
Top comments (0)