publish.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. name: Publish
  2. on: workflow_dispatch
  3. concurrency:
  4. group: "main-branch-workflow" # 唯一标识符,确保只运行一个实例
  5. cancel-in-progress: false # 不取消正在运行的实例,后续触发需要等待当前实例完成
  6. jobs:
  7. build:
  8. runs-on: ubuntu-latest
  9. permissions:
  10. contents: write
  11. steps:
  12. - uses: actions/checkout@v3
  13. with:
  14. fetch-depth: 2
  15. - name: Set up npm token
  16. env:
  17. NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
  18. run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
  19. - name: Debug Auth
  20. env:
  21. NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
  22. run: |
  23. npm whoami
  24. - name: Config Git User
  25. run: |
  26. git config --local user.name "dragooncjw"
  27. git config --local user.email "289056872@qq.com"
  28. - name: Get latest npm version
  29. id: get_version
  30. run: |
  31. LATEST_VERSION=$(npm view @flowgram.ai/core version --tag=latest latest)
  32. echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
  33. # https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
  34. - name: Echo version
  35. run: |
  36. echo "The package version is : $LATEST_VERSION"
  37. echo "The package output version is ${{ steps.get_version.outputs.version }}"
  38. - uses: actions/setup-node@v3
  39. with:
  40. node-version: 18
  41. registry-url: "https://registry.npmjs.org/"
  42. - name: Rush Install
  43. run: node common/scripts/install-run-rush.js install
  44. - name: Rush build
  45. run: node common/scripts/install-run-rush.js build
  46. # version bump 之前保证是远端最新的,这样无需 commit package.json version
  47. - name: Sync versions
  48. run: |
  49. echo "[
  50. {
  51. \"policyName\": \"publishPolicy\",
  52. \"definitionName\": \"lockStepVersion\",
  53. \"version\": \"$LATEST_VERSION\",
  54. \"nextBump\": \"patch\"
  55. }
  56. ]" > common/config/rush/version-policies.json
  57. - name: Version Bump
  58. run: node common/scripts/install-run-rush.js version --bump --version-policy publishPolicy
  59. - name: Publish
  60. env:
  61. NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
  62. run: node common/scripts/install-run-rush.js publish --include-all -p --tag latest
  63. - name: Get new Version
  64. id: get_new_version
  65. run: |
  66. NEW_VERSION=$(npm view @flowgram.ai/core version --tag=latest latest)
  67. echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
  68. - name: Create tag
  69. env:
  70. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  71. run: |
  72. git tag "v$NEW_VERSION"
  73. git push origin "v$NEW_VERSION"