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. - name: Check if version changed
  15. id: version_changed
  16. run: |
  17. cd components
  18. git diff HEAD^ HEAD -- components/package.json | grep 'version":' | grep -v '\/\/' > /dev/null
  19. echo "::set-output name=changed::$(echo $?)"
  20. - name: Setup Node.js environment
  21. uses: actions/setup-node@v1
  22. with:
  23. node-version: 18.x
  24. - name: Publish
  25. if: steps.version_changed.outputs.changed == '0'
  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 }}