Github操作npm发布使用标记名称



我正在将我们现有的特拉维斯任务迁移到 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

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

- 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}}

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

如果您正在寻找NPM可用的更多操作,可以在Github市场上找到它们。

例如,您可以在工作流程中使用类似以下内容,如果您需要使用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>

有关此操作如何工作的更多信息,请查看此处。

其他操作

如果要检查,此其他操作(发布到 npm)也可能很有趣。

最新更新