fix: resolve Node.js version mismatch and hardcoded dependencies

🔧 **Configuration & Validation Fixes:**

### 📦 Node.js Version Alignment
- Updated workflow from Node 18 → Node 20
- Matches package.json engines requirement (^18.20.2 || >=20.9.0)
- Ensures consistent runtime environment

### 🏷️ Dynamic Package Name Resolution
- Removed hardcoded @xtr-dev/payload-mailing references
- Reads package name dynamically from package.json
- Updates NPM URLs, GitHub releases, and installation commands
- Uses ${{ github.repository }} for dynamic repo references

###  Prerequisites Validation
- Validates all required version branches exist before processing
- Checks Node.js version compatibility with package.json engines
- Provides clear error messages for missing branches with fix instructions
- Extracts and exposes package metadata for downstream steps

**New Validation Steps:**
- 🔍 Version branches validation (version/major, version/minor, version/patch)
- 📌 Package name and version extraction
-  Node.js version compatibility check
- 🛡️ Early failure with actionable error messages

**Benefits:**
-  Prevents cryptic workflow failures
-  Repository-agnostic workflow (works for any fork)
-  Consistent Node.js environment
-  Self-documenting error messages
This commit is contained in:
2025-09-13 13:22:50 +02:00
parent 122123e92f
commit 740a031858

View File

@@ -17,6 +17,7 @@ jobs:
new-version: ${{ steps.version-bump.outputs.new-version }}
current-version: ${{ steps.version-bump.outputs.current-version }}
version-type: ${{ steps.version-type.outputs.type }}
package-name: ${{ steps.prerequisites.outputs.package-name }}
steps:
- name: Checkout code
@@ -28,7 +29,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Setup pnpm
@@ -48,6 +49,51 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Validate prerequisites and setup
id: prerequisites
run: |
# Extract package info
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "package-name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "📦 Package: $PACKAGE_NAME"
echo "📌 Current Version: $CURRENT_VERSION"
# Validate version branches exist
echo "🔍 Validating version branches..."
MISSING_BRANCHES=""
for branch in "version/major" "version/minor" "version/patch"; do
if ! git ls-remote --heads origin "$branch" | grep -q "$branch"; then
MISSING_BRANCHES="$MISSING_BRANCHES $branch"
fi
done
if [ -n "$MISSING_BRANCHES" ]; then
echo "❌ ERROR: Missing required version branches:$MISSING_BRANCHES"
echo "Please create these branches first:"
for branch in $MISSING_BRANCHES; do
echo " git checkout -b $branch && git push origin $branch"
done
exit 1
fi
echo "✅ All version branches exist"
# Validate Node.js version matches package.json engines
NODE_VERSION=$(node --version)
echo "🔍 Validating Node.js version: $NODE_VERSION"
# Basic validation - check if we're on Node 20+
if ! echo "$NODE_VERSION" | grep -qE "^v(20|21|22)\."; then
echo "⚠️ WARNING: Node.js version $NODE_VERSION may not match package.json engines requirements"
fi
echo "✅ Prerequisites validation complete"
- name: Install dependencies
run: pnpm install --frozen-lockfile
@@ -317,12 +363,12 @@ CLAUDE_EOF
### Installation
\`\`\`bash
npm install @xtr-dev/payload-mailing@${{ steps.version-bump.outputs.new-version }}
npm install ${{ steps.prerequisites.outputs.package-name }}@${{ steps.version-bump.outputs.new-version }}
\`\`\`
### Documentation
See the [README](https://github.com/xtr-dev/payload-mailing#readme) for usage instructions and full documentation."
See the [README](https://github.com/${{ github.repository }}#readme) for usage instructions and full documentation."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -335,7 +381,7 @@ CLAUDE_EOF
if: needs.version-and-publish.outputs.new-version != ''
run: |
echo "🎉 Successfully published version ${{ needs.version-and-publish.outputs.new-version }} to NPM!"
echo "📦 Package: https://www.npmjs.com/package/@xtr-dev/payload-mailing"
echo "🏷️ GitHub Release: https://github.com/xtr-dev/payload-mailing/releases/tag/v${{ needs.version-and-publish.outputs.new-version }}"
echo "📦 Package: https://www.npmjs.com/package/${{ needs.version-and-publish.outputs.package-name }}"
echo "🏷️ GitHub Release: https://github.com/${{ github.repository }}/releases/tag/v${{ needs.version-and-publish.outputs.new-version }}"
echo "🔄 Version Type: ${{ needs.version-and-publish.outputs.version-type }}"
echo "📈 Version Change: v${{ needs.version-and-publish.outputs.current-version }} → v${{ needs.version-and-publish.outputs.new-version }}"