publish-alpha.yml 3.3 KB

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