auto-public-npm.yml 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # 当分支 main 有 push 事件并且此次 push 包含了 tag ,并且 tag 的格式为 v* 时,执行以下任务
  2. # 使用 GitHub Actions secrets 存储的 NPM_TOKEN 自动将本仓库 components 目录下的所有文件发布到 npm 上
  3. name: Auto publish npm
  4. on:
  5. push:
  6. branches:
  7. - main
  8. jobs:
  9. publish:
  10. runs-on: ubuntu-latest
  11. steps:
  12. - name: Checkout
  13. uses: actions/checkout@v2
  14. # 读取最新push的 tag 内容,如果是 v 开头,则往下执行,否则退出
  15. - name: Check tag
  16. run: |
  17. if [[ $GITHUB_REF != 'refs/tags/v'* ]]; then
  18. echo "This is not a tag push. Skipping."
  19. exit 78
  20. fi
  21. - name: Setup Node.js environment
  22. uses: actions/setup-node@v1
  23. with:
  24. node-version: 18.x
  25. - name: Publish
  26. run: |
  27. cd components
  28. npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
  29. npm publish
  30. env:
  31. CI: true
  32. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}