【问题标题】:Github action npm publish use tag nameGithub action npm publish 使用标签名
【发布时间】:2021-09-02 01:33:05
【问题描述】:

我正在将我们现有的 Travis 任务迁移到 GH 操作。对于 Travis,以下命令将发布到 npm 并使用 npm 版本的发布标签名称。

script: yarn npm-bundle && npm version $TRAVIS_BRANCH --allow-same-version -m
      "chore - release version %s [skip ci]" --allow-empty

不幸的是,更改为以下不起作用...

        run: |
          yarn npm-bundle && npm version ${{ github.event.release.tag_name }} --allow-same-version -m "chore - release version %s [skip ci]" --allow-empty
          npm publish --access public --dry-run

它显然是空的,因为 npm 使用的是 package.json 中的版本。我尝试了一些其他变量,例如${{ github.head_ref }}

还有……

run: |
          yarn npm-bundle -m "chore - release version %s [skip ci]" --allow-empty
          npm publish --tag ${{ github.event.release.tag_name }} --allow-same-version --access public --dry-run

【问题讨论】:

    标签: npm github-actions npm-publish npm-version


    【解决方案1】:

    我已经通过重构以下内容解决了这个问题...

          - uses: actions/setup-node@v1
            with:
              node-version: 14.15.0
              registry-url: https://registry.npmjs.org/
          - run: yarn install
          - run: git config --global user.name "${{ github.actor }}"
          - run: git config --global user.email "github-action-${{ github.actor }}@users.noreply.github.com"
          - run: npm version ${{ github.event.release.tag_name }}
          - run: yarn npm-bundle
          - run: npm publish --access public
            env:
              NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
    
    

    【讨论】:

      【解决方案2】:

      您可以在工作流程中使用 npm-publish 操作,而不是在 Travis 中使用的脚本。

      如果您要查找 NPM 可用的更多操作,可以在 Github Marketplace 上找到它们

      例如在这里,您可以在您的工作流程中使用类似的东西,如果您需要使用yarn 或其他命令,则可以通过其他run 步骤适应您的上下文:

      on: push
      
      jobs:
        publish:
          runs-on: ubuntu-latest
          steps:
            - uses: actions/checkout@v1
            - uses: actions/setup-node@v1
              with:
                node-version: 10
            - run: npm install
            - run: npm test
            - uses: JS-DevTools/npm-publish@v1
              with:
                token: ${{ secrets.NPM_TOKEN }}
                tag: <your release tag name>
      

      有关此操作如何工作的更多信息,check here

      其他操作

      如果您想查看,这个other action (publish-to-npm) 也可能很有趣。

      【讨论】:

        猜你喜欢
        • 2017-09-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-05
        • 2022-11-11
        • 2023-03-28
        • 2023-02-15
        • 2022-01-16
        • 2022-06-17
        相关资源
        最近更新 更多