publish-alpha.yml 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. name: Publish Alpha Version
  2. on: workflow_dispatch
  3. concurrency:
  4. group: "main-branch-alpha-publish-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 alpha latest npm version
  29. id: get_version
  30. run: |
  31. LATEST_VERSION=$(npm view @flowgram.ai/core version --tag=alpha latest 2>/dev/null || true)
  32. if [ -n "$LATEST_VERSION" ]; then
  33. echo "Using existing version: $LATEST_VERSION"
  34. else
  35. LATEST_VERSION="0.1.0-alpha.1"
  36. echo "Version not found, using default: $LATEST_VERSION"
  37. fi
  38. echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
  39. # https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
  40. - name: Echo version
  41. run: |
  42. echo "The package version is : $LATEST_VERSION"
  43. echo "The package output version is ${{ steps.get_version.outputs.version }}"
  44. - uses: actions/setup-node@v3
  45. with:
  46. node-version: 18
  47. registry-url: "https://registry.npmjs.org/"
  48. - name: Rush Install
  49. run: node common/scripts/install-run-rush.js install
  50. - name: Rush build
  51. run: node common/scripts/install-run-rush.js build
  52. # version bump 之前保证是远端最新的,这样无需 commit package.json version
  53. - name: Sync versions
  54. run: |
  55. echo "[
  56. {
  57. \"policyName\": \"publishPolicy\",
  58. \"definitionName\": \"lockStepVersion\",
  59. \"version\": \"$LATEST_VERSION\",
  60. \"nextBump\": \"prerelease\"
  61. }
  62. ]" > common/config/rush/version-policies.json
  63. - name: replace with alpha version
  64. run: node common/scripts/install-run-rush.js version --ensure-version-policy --override-version=$LATEST_VERSION --version-policy=publishPolicy
  65. - name: Version Bump
  66. run: node common/scripts/install-run-rush.js version --bump --version-policy publishPolicy
  67. - name: Publish
  68. env:
  69. NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
  70. run: node common/scripts/install-run-rush.js publish --include-all -p --tag alpha
  71. - name: Get new Version
  72. id: get_new_version
  73. run: |
  74. NEW_VERSION=$(npm view @flowgram.ai/core version --tag=alpha latest)
  75. echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
  76. - name: Create tag
  77. env:
  78. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  79. run: |
  80. git tag "v$NEW_VERSION"
  81. git push origin "v$NEW_VERSION"