auto-public-npm.yml 1.3 KB

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