问题描述
我正在将我们现有的 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-publish 操作,而不是您在 Travis 中使用的脚本。
如果您想通过 NPM 寻找更多可用的操作,您可以在上面找到它们Github Marketplace
例如,如果您需要使用 run
或其他命令,您可以在工作流程中使用类似的内容,根据您的上下文与其他 yarn
步骤进行调整:
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) 也很有趣,如果你想检查一下。
,我已通过重构为以下内容解决了该问题...
- 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}}