Yml config for building & deploying react app

2019-07-25 14:22发布

I want to create a yml file to prevent my production code from deploying when a new commit is made to the repo.

I only want the production code to be built & deployed if a direct push is made to the master branch. My existing yml config builds & deploys my changes if I create a pull request - without actually merging. I want to stop this. I only want the 'building & deploying' part to be done after a pull request has been made and changes are actually pushed into master.

This is what my current .travis.yml file looks like:

language: node_js
node_js:
  - "8.12"
script: 
  - npm i
  - if [ "$TRAVIS_BRANCH" == "master" ]; then echo "Deploying to firebase";  - CI=false npm run build  fi
install:
  - if [ "$TRAVIS_BRANCH" == "master" ]; then npm i -g firebase-tools; fi
after_success:
  - if [ "$TRAVIS_BRANCH" == "master" ]; then firebase deploy --token "$FIREBASE_TOKEN"; fi 

I had a go at changing that to something more slick:

language: node_js
node_js:
  - "8.12"

stages: 
  - compile
  - test
  - name: deploy
    if: branch = master AND NOT (type = push OR type = pull_request OR fork = true)
env:
  - CI=false

jobs: 
  include: 
    - stage: compile 
      script: 
        - npm i

    - stage: test
      script: ""

    - stage: deploy
      install: npm i -g firebase-tools
      script: 
        - npm run build
    after_success:
        - firebase deploy --token "$FIREBASE_TOKEN"

but this isn't valid yml.

How can I set it so that it only deploys when the code has actually been merged into master (and only that). I still want to execute tests and stuff if pushes are made to other branches like develop etc.

0条回答
登录 后发表回答