我创建了一个 Github 存储库,其中包含构建 npm 包并将其发布到 npmjs.com 的操作。我的行动的触发因素是在 Github 上创建一个新版本。创建新版本时,Github 要求我提供版本号。我很想在操作中使用这个版本号并将其提供给yarnpublish命令。
我的 ci 文件看起来像这样(我删除了一些在这里不重要的部分):
name: Deploy npm package
on:
release:
types: [created]
jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn build
- run: yarn publish --new-version ${...}
env:a
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
是否有包含版本号的环境变量?
它应该是${{ github.event.release.tag_name }}
。版本的结构可以在这里找到:https://developer.github.com/v3/repos/releases/#get-a-single-release https://developer.github.com/v3/repos/releases/#get-a-single-release
我还建议使用
on:
release:
types: [published]
而不是为了避免将某些内容放入 npm 以进行草稿发布而创建。
看:https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#release-event-release https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#release-event-release
Hint:
要调试该事件,您可以使用:
jobs:
debug:
name: Debug
runs-on: ubuntu-latest
steps:
- name: Dump env
run: env | sort
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)