publish_master_to_npm.yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. name: Publish Master Branch to NPM
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - master
  7. jobs:
  8. publish:
  9. runs-on: ubuntu-latest
  10. permissions:
  11. contents: read
  12. id-token: write
  13. # Only allow workflow to run on master branch
  14. if: github.ref == 'refs/heads/master'
  15. steps:
  16. - name: Checkout
  17. uses: actions/checkout@v4
  18. with:
  19. fetch-depth: 0
  20. - name: Setup Node.js
  21. uses: actions/setup-node@v4
  22. with:
  23. node-version: '22.x'
  24. registry-url: 'https://registry.npmjs.org'
  25. - name: Install dependencies
  26. run: npm install --no-save
  27. - name: Get current date
  28. id: date
  29. run: echo "date=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
  30. - name: Configure Git
  31. run: |
  32. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  33. git config --global user.name "github-actions[bot]"
  34. - name: Version and build packages
  35. run: |
  36. # Get the current version from lerna.json
  37. CURRENT_VERSION=$(node -p "require('./lerna.json').version")
  38. # Split version into parts
  39. IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
  40. # Increment patch version
  41. PATCH=$((VERSION_PARTS[2] + 1))
  42. # Create new version with date
  43. NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${PATCH}-master-${{ steps.date.outputs.date }}"
  44. # Update version using lerna directly
  45. npx lerna version $NEW_VERSION --no-git-tag-version --yes --no-push --force-publish
  46. - name: Commit changes
  47. run: |
  48. git add .
  49. git commit -m "chore: Bump version for pre-release to $NEW_VERSION"
  50. - name: Publish to NPM
  51. run: npx lerna publish from-package --yes --dist-tag master --no-git-reset
  52. env:
  53. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  54. NPM_CONFIG_PROVENANCE: true