publish_master_to_npm.yml 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. name: Publish Master 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 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. # 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 since 24 h ago on this branch
  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 current version from lerna.json
  54. CURRENT_VERSION=$(node -p "require('./lerna.json').version")
  55. IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
  56. # Increment patch version for pre-release
  57. PATCH=$((VERSION_PARTS[2] + 1))
  58. # Compose new pre-release version incl. timestamp
  59. NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${PATCH}-master-${{ steps.date.outputs.date }}"
  60. npx lerna version $NEW_VERSION --no-git-tag-version --yes --no-push --force-publish
  61. - name: Commit changes
  62. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  63. run: |
  64. git add .
  65. git commit -m "chore: Bump version for pre-release to $NEW_VERSION"
  66. - name: Publish to NPM
  67. if: ${{ steps.commit_check.outputs.should_publish == 'true' }}
  68. run: npx lerna publish from-package --yes --dist-tag master --no-git-reset
  69. env:
  70. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  71. NPM_CONFIG_PROVENANCE: true
  72. # Informative noop when skipping
  73. - name: Skip publish
  74. if: ${{ steps.commit_check.outputs.should_publish == 'false' }}
  75. run: echo "No new commits in last 24 hours – skipping publish."