【问题标题】:How to ask travis to deploy on npm only when merged on master branch?仅当合并到 master 分支时,如何要求 travis 在 npm 上部署?
【发布时间】:2019-10-08 15:45:24
【问题描述】:

我们正在 github 上配置一个公共项目。 我们希望我们的 travis 作业在每个 PR 上运行测试和构建,并且仅在 master 上接受的 MR 上部署(npm publish)。

我们已经尝试过这个配置,但它不起作用:

language: node_js
node_js: 
  - 10.16.0
before_script:
  - npm run build

deploy:
  provider: npm
  email: "myemail@example.com"
  api_key:
    secure: "our secure key that is irrelevant for this question"
  after_deploy:
    - ./script/updateNpmVersion.sh
  on:
    branch: master

还有./script/updateNpmVersion.sh

#!/bin/bash
git pull develop
npm version minor
git add package.json
git commit -m "bump npm version"
git push origin develop

但它不起作用。基本上从不调用 Deploy。

【问题讨论】:

    标签: npm travis-ci


    【解决方案1】:

    我认为存在语法问题。 after_deploy 脚本应该在 deploy 步骤完成后执行。此外,您可以在配置 on 密钥时尝试提供一个用于部署的特定存储库。

    另外,您可能需要授予执行updateNpmVersion.sh 脚本所需的权限。所以你最终的yml 文件应该是这样的

    language: node_js
    
    node_js: 
      - 10.16.0
    
    before_script:
      - npm run build
      - chmod +x ./script/updateNpmVersion.sh
    
    deploy:
      provider: npm
      email: "myemail@example.com"
      api_key:
        secure: "our secure key that is irrelevant for this question"
      on:
        repo: OWNER_NAME/REPO_NAME
        branch: master
    
    after_deploy:
        - ./script/updateNpmVersion.sh
    

    【讨论】:

      猜你喜欢
      • 2015-05-01
      • 2016-09-20
      • 2019-01-23
      • 2018-04-14
      • 1970-01-01
      • 2021-04-16
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      相关资源
      最近更新 更多