仅当分支在 TravisCI 中为主时才执行脚本

Only execute script if branch is master in TravisCI

我是 TravisCI 的新手,这可能是一个非常愚蠢的问题,但我正在尝试以一种仅在当前分支为 master 时才部署到 Firebase 的方式编写 travis 配置。 也就是说,只有当代码被推送到 master 或 PR 与 master 合并时,firebase deploy 命令才会执行。 deploy命令应该在其他分支被推送到,或者在制作PR时执行。 这是我目前拥有的:

language: node_js
node_js: 12.16.1
script: echo "Running travis-ci"
install: 
  - npm install -g firebase-tools
  - npm i react-scripts
script:
  - yarn add react
  - yarn test
  - if [ "$TRAVIS_BRANCH" = "master" ]; then yarn build; fi
  - if [ "$TRAVIS_BRANCH" = "master" ]; then firebase deploy --project testproj8876 --token $FIREBASE_TOKEN; fi
branches:
  only:
    - master

由于我还不太熟悉约定,任何 improvements/suggestions 也将不胜感激。

Google Travis 直接支持 Firebase。参见 here

因此,我建议使用上面 link 中描述的解决方案。

deploy:
  provider: firebase
  token:
   secure: "YOUR ENCRYPTED token"

至于你的情况,你可以查看我的一份.travis.yml文件here and the documentation there (Conditional Deployments)

以下部分是您需要的:

deploy:
  cleanup: false
  on:
    branch:
    - master

如果您还有疑问,请随时提问。