Explorar el Código

feat(ci): Add GitHub Actions workflow to publish minor branch to NPM

David Höck hace 6 meses
padre
commit
a3928f0d8a
Se han modificado 1 ficheros con 69 adiciones y 0 borrados
  1. 69 0
      .github/workflows/publish_minor_to_npm.yml

+ 69 - 0
.github/workflows/publish_minor_to_npm.yml

@@ -0,0 +1,69 @@
+name: Publish Minor Branch to NPM
+
+on:
+    workflow_dispatch:
+    push:
+        branches:
+            - minor
+        paths:
+            - 'packages/**'
+            - 'package.json'
+            - 'package-lock.json'
+
+jobs:
+    publish:
+        runs-on: ubuntu-latest
+        permissions:
+            contents: read
+            id-token: write
+
+        # Only allow workflow to run on minor branch
+        if: github.ref == 'refs/heads/minor'
+
+        steps:
+            - name: Checkout
+              uses: actions/checkout@v4
+              with:
+                  fetch-depth: 0
+
+            - name: Setup Node.js
+              uses: actions/setup-node@v4
+              with:
+                  node-version: '22.x'
+                  registry-url: 'https://registry.npmjs.org'
+
+            - name: Install dependencies
+              run: npm install --no-save
+
+            - name: Get current date
+              id: date
+              run: echo "date=$(date +'%Y%m%d%H%M')" >> $GITHUB_OUTPUT
+
+            - name: Configure Git
+              run: |
+                  git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
+                  git config --global user.name "github-actions[bot]"
+
+            - name: Version and build packages
+              run: |
+                  # Get the current version from lerna.json
+                  CURRENT_VERSION=$(node -p "require('./lerna.json').version")
+                  # Split version into parts
+                  IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
+                  # Increment minor version
+                  MINOR=$((VERSION_PARTS[1] + 1))
+                  # Create new version with date
+                  NEW_VERSION="${VERSION_PARTS[0]}.${MINOR}.0-minor-${{ steps.date.outputs.date }}"
+                  # Update version using lerna directly
+                  npx lerna version $NEW_VERSION --no-git-tag-version --yes --no-push --force-publish
+
+            - name: Commit changes
+              run: |
+                  git add .
+                  git commit -m "chore: Bump version for minor pre-release to $NEW_VERSION"
+
+            - name: Publish to NPM
+              run: npx lerna publish from-package --yes --dist-tag minor --no-git-reset
+              env:
+                  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+                  NPM_CONFIG_PROVENANCE: true