Skip to content

Commit 1e87ba4

Browse files
author
Test User
committed
feat: add npm token verification and maintainer checks
- Add comprehensive npm token verification step before publishing - Verify token validity and authentication - Check maintainer permissions for existing packages - Add maintainers field to package.json - Add post-publish maintainer verification step - Improve error messages for token issues
1 parent f3274ae commit 1e87ba4

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

.github/workflows/release.yml

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,53 @@ jobs:
160160
env:
161161
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
162162

163+
- name: Verify npm token and permissions
164+
run: |
165+
echo "Verifying npm token and permissions..."
166+
167+
if [ -z "$NODE_AUTH_TOKEN" ]; then
168+
echo "❌ Error: NPM_TOKEN secret is not set"
169+
echo "Please add NPM_TOKEN to GitHub Secrets with publish permissions"
170+
exit 1
171+
fi
172+
173+
# Verify token is valid and can authenticate
174+
NPM_USER=$(npm whoami 2>&1 || echo "")
175+
if [ -z "$NPM_USER" ]; then
176+
echo "❌ Error: npm token is invalid or expired"
177+
echo "Please create a new npm token with publish permissions:"
178+
echo " https://www.npmjs.com/settings/YOUR_USERNAME/tokens"
179+
echo " Token type: Automation (for CI/CD)"
180+
exit 1
181+
fi
182+
183+
echo "✅ npm token is valid"
184+
echo "✅ Authenticated as: $NPM_USER"
185+
186+
# Check if package exists and verify maintainer access
187+
PACKAGE_EXISTS=$(npm view doplan-cli version 2>&1 || echo "")
188+
if [ -n "$PACKAGE_EXISTS" ] && [ "$PACKAGE_EXISTS" != "null" ]; then
189+
echo "📦 Package doplan-cli exists on npm"
190+
191+
# Get maintainers
192+
MAINTAINERS=$(npm view doplan-cli maintainers 2>&1 || echo "")
193+
echo "Maintainers: $MAINTAINERS"
194+
195+
# Verify current user is a maintainer
196+
IS_MAINTAINER=$(npm access ls-packages "$NPM_USER" 2>&1 | grep -q "doplan-cli" && echo "yes" || echo "no")
197+
if [ "$IS_MAINTAINER" = "no" ]; then
198+
echo "⚠️ Warning: User $NPM_USER may not have publish permissions for doplan-cli"
199+
echo "Please verify you are a maintainer of the package"
200+
else
201+
echo "✅ User $NPM_USER has access to doplan-cli"
202+
fi
203+
else
204+
echo "📦 Package doplan-cli does not exist yet (will be created on first publish)"
205+
echo "✅ Token has permissions to create new packages"
206+
fi
207+
env:
208+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
209+
163210
- name: Extract version from tag
164211
id: get_version
165212
run: |
@@ -200,4 +247,40 @@ jobs:
200247
echo "Published to npm successfully!"
201248
echo "Package: doplan-cli@${{ steps.get_version.outputs.version }}"
202249
echo "npm URL: https://www.npmjs.com/package/doplan-cli"
203-
250+
251+
- name: Verify package maintainers
252+
run: |
253+
echo "Verifying package maintainers..."
254+
255+
# Get package info
256+
PACKAGE_INFO=$(npm view doplan-cli --json 2>&1 || echo "")
257+
258+
if [ -n "$PACKAGE_INFO" ] && [ "$PACKAGE_INFO" != "null" ]; then
259+
echo "✅ Package published successfully"
260+
261+
# Extract maintainers
262+
MAINTAINERS=$(echo "$PACKAGE_INFO" | jq -r '.maintainers[]? | "\(.name) <\(.email)>"' 2>/dev/null || echo "")
263+
264+
if [ -n "$MAINTAINERS" ]; then
265+
echo "📋 Package maintainers:"
266+
echo "$MAINTAINERS" | while read -r maintainer; do
267+
echo " - $maintainer"
268+
done
269+
else
270+
echo "⚠️ No maintainers field found in package.json"
271+
fi
272+
273+
# Show current npm user
274+
NPM_USER=$(npm whoami 2>&1 || echo "")
275+
if [ -n "$NPM_USER" ]; then
276+
echo "🔐 Published by: $NPM_USER"
277+
fi
278+
else
279+
echo "⚠️ Could not retrieve package information"
280+
fi
281+
env:
282+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
283+
284+
- name: Restore cache
285+
run: |
286+
tar --overwrite -xf mycache.tar

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
"productivity"
2929
],
3030
"author": "DoPlan Team <[email protected]>",
31+
"maintainers": [
32+
{
33+
"name": "DoPlan Team",
34+
"email": "[email protected]"
35+
}
36+
],
3137
"license": "MIT",
3238
"repository": {
3339
"type": "git",

0 commit comments

Comments
 (0)