Skip to content

Commit a3fef49

Browse files
committed
improve
1 parent 426c264 commit a3fef49

File tree

2 files changed

+133
-11
lines changed

2 files changed

+133
-11
lines changed

.github/workflows/main-publish.yml

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,70 @@ jobs:
4848
# Create a backup of original package.json
4949
cp package.json package.json.bak
5050
51-
# Update name and version for preview
52-
npm pkg set name="${{ steps.preview_info.outputs.package_name }}"
53-
npm pkg set version="${{ steps.preview_info.outputs.version }}"
51+
# Get the official package name for safety checks
52+
OFFICIAL_PACKAGE=$(node -p "require('./package.json').name")
53+
PREVIEW_PACKAGE="${{ steps.preview_info.outputs.package_name }}"
54+
55+
echo "Official package: $OFFICIAL_PACKAGE"
56+
echo "Preview package: $PREVIEW_PACKAGE"
57+
58+
# Safety check: Ensure we're not accidentally using the official package name
59+
if [ "$PREVIEW_PACKAGE" = "$OFFICIAL_PACKAGE" ]; then
60+
echo "❌ ERROR: Preview package name matches official package name!"
61+
echo "This would overwrite the official package. Aborting."
62+
exit 1
63+
fi
64+
65+
# Update name with error handling
66+
if ! npm pkg set name="$PREVIEW_PACKAGE"; then
67+
echo "❌ ERROR: Failed to set package name to $PREVIEW_PACKAGE"
68+
exit 1
69+
fi
70+
71+
# Update version with error handling
72+
if ! npm pkg set version="${{ steps.preview_info.outputs.version }}"; then
73+
echo "❌ ERROR: Failed to set package version to ${{ steps.preview_info.outputs.version }}"
74+
exit 1
75+
fi
76+
77+
echo "✅ Package.json updated successfully"
78+
79+
- name: Final safety check before publish
80+
run: |
81+
# Double-check package name one more time before publishing
82+
CURRENT_PACKAGE_NAME=$(node -p "require('./package.json').name")
83+
OFFICIAL_PACKAGE="@base44/sdk"
84+
85+
echo "About to publish: $CURRENT_PACKAGE_NAME"
86+
87+
if [ "$CURRENT_PACKAGE_NAME" = "$OFFICIAL_PACKAGE" ]; then
88+
echo "❌ CRITICAL ERROR: About to publish to official package name!"
89+
echo "This is not allowed. Check the workflow configuration."
90+
exit 1
91+
fi
92+
93+
echo "✅ Safety check passed. Package name is safe to publish."
5494
5595
- name: Publish preview package
56-
run: npm publish
96+
run: |
97+
if npm publish; then
98+
echo "✅ Package published successfully"
99+
else
100+
echo "❌ Package publish failed"
101+
exit 1
102+
fi
57103
env:
58104
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
59105

60106
- name: Restore original package.json
61-
run: mv package.json.bak package.json
107+
run: |
108+
if [ -f package.json.bak ]; then
109+
mv package.json.bak package.json
110+
echo "✅ Original package.json restored"
111+
else
112+
echo "❌ WARNING: Backup file package.json.bak not found"
113+
echo "This could indicate an earlier step failed"
114+
fi
62115
63116
permissions:
64117
contents: read

.github/workflows/preview-publish.yml

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
with:
2121
node-version: 20
2222
cache: "npm"
23-
registry-url: "https://registry.npmjs.org"
2423

2524
- name: Install dependencies
2625
run: npm install
@@ -55,24 +54,78 @@ jobs:
5554
# Create a backup of original package.json
5655
cp package.json package.json.bak
5756
58-
# Update name and version for preview
59-
npm pkg set name="${{ steps.preview_info.outputs.package_name }}"
60-
npm pkg set version="${{ steps.preview_info.outputs.version }}"
57+
# Get the official package name for safety checks
58+
OFFICIAL_PACKAGE=$(node -p "require('./package.json').name")
59+
PREVIEW_PACKAGE="${{ steps.preview_info.outputs.package_name }}"
60+
61+
echo "Official package: $OFFICIAL_PACKAGE"
62+
echo "Preview package: $PREVIEW_PACKAGE"
63+
64+
# Safety check: Ensure we're not accidentally using the official package name
65+
if [ "$PREVIEW_PACKAGE" = "$OFFICIAL_PACKAGE" ]; then
66+
echo "❌ ERROR: Preview package name matches official package name!"
67+
echo "This would overwrite the official package. Aborting."
68+
exit 1
69+
fi
70+
71+
# Update name with error handling
72+
if ! npm pkg set name="$PREVIEW_PACKAGE"; then
73+
echo "❌ ERROR: Failed to set package name to $PREVIEW_PACKAGE"
74+
exit 1
75+
fi
76+
77+
# Update version with error handling
78+
if ! npm pkg set version="${{ steps.preview_info.outputs.version }}"; then
79+
echo "❌ ERROR: Failed to set package version to ${{ steps.preview_info.outputs.version }}"
80+
exit 1
81+
fi
82+
83+
echo "✅ Package.json updated successfully"
84+
85+
- name: Final safety check before publish
86+
run: |
87+
# Double-check package name one more time before publishing
88+
CURRENT_PACKAGE_NAME=$(node -p "require('./package.json').name")
89+
OFFICIAL_PACKAGE="@base44/sdk"
90+
91+
echo "About to publish: $CURRENT_PACKAGE_NAME"
92+
93+
if [ "$CURRENT_PACKAGE_NAME" = "$OFFICIAL_PACKAGE" ]; then
94+
echo "❌ CRITICAL ERROR: About to publish to official package name!"
95+
echo "This is not allowed. Check the workflow configuration."
96+
exit 1
97+
fi
98+
99+
echo "✅ Safety check passed. Package name is safe to publish."
61100
62101
- name: Publish preview package
63-
run: npm publish
102+
run: |
103+
if npm publish; then
104+
echo "✅ Package published successfully"
105+
else
106+
echo "❌ Package publish failed"
107+
exit 1
108+
fi
64109
env:
65110
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
66111

67112
- name: Restore original package.json
68-
run: mv package.json.bak package.json
113+
run: |
114+
if [ -f package.json.bak ]; then
115+
mv package.json.bak package.json
116+
echo "✅ Original package.json restored"
117+
else
118+
echo "❌ WARNING: Backup file package.json.bak not found"
119+
echo "This could indicate an earlier step failed"
120+
fi
69121
70122
- name: Comment PR with install instructions
71123
uses: actions/github-script@v6
72124
with:
73125
script: |
74126
const fullPackage = '${{ steps.preview_info.outputs.full_package }}';
75127
const installCmd = `npm i ${fullPackage}`;
128+
const aliasInstallCmd = `npm i "@base44/sdk@npm:${fullPackage}"`;
76129
const body = `### 🚀 Package Preview Available!
77130
78131
---
@@ -83,6 +136,22 @@ jobs:
83136
${installCmd}
84137
\`\`\`
85138
139+
**Prefer not to change any import paths? Install using npm alias so your code still imports \\`@base44/sdk\\`:**
140+
141+
\`\`\`sh
142+
${aliasInstallCmd}
143+
\`\`\`
144+
145+
Or add it to your \`package.json\` dependencies:
146+
147+
\`\`\`json
148+
{
149+
"dependencies": {
150+
"@base44/sdk": "npm:${fullPackage}"
151+
}
152+
}
153+
\`\`\`
154+
86155
- 📦 **Preview Package**: \`${fullPackage}\`
87156
- 🔗 [View this commit on GitHub](https://github.com/${{ github.repository }}/commit/${{ github.sha }})
88157

0 commit comments

Comments
 (0)