publish_minor_to_npm.yml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. name: Publish Minor Branch to NPM
  2. on:
  3. workflow_dispatch:
  4. # Nightly run at 02:00 UTC
  5. schedule:
  6. - cron: '0 2 * * *'
  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 minor branch
  14. if: github.ref == 'refs/heads/minor'
  15. steps:
  16. - name: Checkout
  17. uses: actions/checkout@v4
  18. with:
  19. fetch-depth: 0
  20. # Check if branch received commits in the last 24 h; skip remainder if none
  21. - name: Check for new commits
  22. id: commit_check
  23. run: |
  24. # Count commits on this branch since 24 h ago
  25. COMMITS=$(git rev-list --count --since="24 hours" HEAD)
  26. echo "Commits found: $COMMITS"
  27. if [ "$COMMITS" -eq 0 ]; then
  28. echo "should_publish=false" >> $GITHUB_OUTPUT
  29. else
  30. echo "should_publish=true" >> $GITHUB_OUTPUT
  31. fi
  32. - name: Setup Node.js
  33. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  34. uses: actions/setup-node@v4
  35. with:
  36. node-version: '22.x'
  37. registry-url: 'https://registry.npmjs.org'
  38. - name: Install dependencies
  39. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  40. run: npm install --no-save
  41. - name: Get current date
  42. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  43. id: date
  44. run: echo "date=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
  45. - name: Configure Git
  46. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  47. run: |
  48. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  49. git config --global user.name "github-actions[bot]"
  50. - name: Version and build packages
  51. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  52. run: |
  53. # Get the current version from lerna.json
  54. CURRENT_VERSION=$(node -p "require('./lerna.json').version")
  55. # Split version into parts
  56. IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
  57. # Increment minor version for pre-release
  58. MINOR=$((VERSION_PARTS[1] + 1))
  59. # Compose new pre-release version incl. timestamp
  60. NEW_VERSION="${VERSION_PARTS[0]}.${MINOR}.0-minor-${{ steps.date.outputs.date }}"
  61. npx lerna version $NEW_VERSION --no-git-tag-version --yes --no-push --force-publish
  62. - name: Commit changes
  63. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  64. run: |
  65. git add .
  66. git commit -m "chore: Bump version for minor pre-release to $NEW_VERSION"
  67. - name: Publish to NPM
  68. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  69. run: npx lerna publish from-package --yes --dist-tag minor --no-git-reset
  70. env:
  71. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  72. NPM_CONFIG_PROVENANCE: true
  73. # Informative noop when skipping
  74. - name: Skip publish
  75. if: ${{ steps.commit_check.outputs.should_publish == 'false' }}
  76. run: echo "No new commits in last 24 hours – skipping publish."