Skip to content

Commit 23ad05f

Browse files
PaulDuvallclaude
andcommitted
enhance: automate GitHub variable setting and NPM token storage in setup script
- Add automatic GitHub repository variable configuration using GitHub CLI - Add interactive NPM token input with secure hidden prompt - Support environment variable NPM_TOKEN for non-interactive setup - Include fallback instructions when GitHub CLI unavailable - Update documentation with three setup options (automated, env var, manual) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 005ceac commit 23ad05f

File tree

2 files changed

+99
-18
lines changed

2 files changed

+99
-18
lines changed

docs/npm-ssm/README.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,35 @@ Store NPM tokens securely in AWS SSM and use them in GitHub Actions.
44

55
## Setup (one-time)
66

7+
**Option 1: Fully automated**
78
```bash
8-
# 1. Run setup script
9+
# Run the setup script - it does everything!
910
./scripts/setup-npm-ssm.sh
1011

11-
# 2. Set GitHub variables (copy commands from script output)
12-
gh variable set AWS_ROLE --body 'arn:aws:iam::ACCOUNT:role/github-actions-npm-REPO'
13-
gh variable set AWS_REGION --body 'us-east-1'
12+
# The script will:
13+
# 1. Create AWS OIDC provider and IAM role
14+
# 2. Set GitHub repository variables
15+
# 3. Prompt for your NPM token and store it securely
16+
```
17+
18+
**Option 2: With environment variable**
19+
```bash
20+
# Set your NPM token as an environment variable
21+
export NPM_TOKEN="npm_your_token_here"
1422

15-
# 3. Store your NPM token
16-
aws ssm put-parameter \
17-
--name '/npm/token' \
18-
--value 'npm_YOUR_TOKEN_HERE' \
19-
--type SecureString \
20-
--region us-east-1
23+
# Run setup script (won't prompt for token)
24+
./scripts/setup-npm-ssm.sh
25+
```
26+
27+
**Option 3: Manual fallback**
28+
If the script can't set GitHub variables automatically:
29+
```bash
30+
# Run setup script first
31+
./scripts/setup-npm-ssm.sh
32+
33+
# Then manually run the commands it outputs
34+
gh variable set AWS_ROLE --body 'arn:aws:iam::ACCOUNT:role/...'
35+
gh variable set AWS_REGION --body 'us-east-1'
2136
```
2237

2338
## How it works

scripts/setup-npm-ssm.sh

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/bin/bash
2-
# Simple setup for NPM token storage in AWS SSM
2+
# Complete setup for NPM token storage in AWS SSM
33

44
set -e
55

66
# Get repo info
77
REPO=$(git remote get-url origin | sed 's/.*github.com[:/]\(.*\)\.git/\1/')
88
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
99
ROLE_NAME="github-actions-npm-${REPO//\//-}"
10+
REGION=${AWS_REGION:-us-east-1}
1011

11-
echo "🔧 Setting up AWS for $REPO..."
12+
echo "🔧 Setting up NPM token management for $REPO..."
13+
14+
# Step 1: Create AWS resources
15+
echo "1️⃣ Creating AWS resources..."
1216

1317
# Create OIDC provider (idempotent)
1418
aws iam create-open-id-connect-provider \
@@ -48,11 +52,73 @@ aws iam put-role-policy --role-name "$ROLE_NAME" --policy-name SSMReadNPM \
4852

4953
ROLE_ARN="arn:aws:iam::$ACCOUNT:role/$ROLE_NAME"
5054

51-
echo "✅ Setup complete!"
55+
# Step 2: Set GitHub variables automatically
56+
echo "2️⃣ Setting GitHub repository variables..."
57+
58+
if command -v gh >/dev/null 2>&1; then
59+
if gh auth status >/dev/null 2>&1; then
60+
gh variable set AWS_ROLE --body "$ROLE_ARN"
61+
gh variable set AWS_REGION --body "$REGION"
62+
echo "✅ GitHub variables configured"
63+
else
64+
echo "⚠️ GitHub CLI not authenticated. Run: gh auth login"
65+
echo " Then manually set variables:"
66+
echo " gh variable set AWS_ROLE --body '$ROLE_ARN'"
67+
echo " gh variable set AWS_REGION --body '$REGION'"
68+
fi
69+
else
70+
echo "⚠️ GitHub CLI not installed. Install with: brew install gh"
71+
echo " Then manually set variables:"
72+
echo " gh variable set AWS_ROLE --body '$ROLE_ARN'"
73+
echo " gh variable set AWS_REGION --body '$REGION'"
74+
fi
75+
76+
# Step 3: Prompt for NPM token and store it
77+
echo "3️⃣ Storing NPM token..."
78+
79+
if [ -n "$NPM_TOKEN" ]; then
80+
# Token provided via environment variable
81+
aws ssm put-parameter \
82+
--name '/npm/token' \
83+
--value "$NPM_TOKEN" \
84+
--type SecureString \
85+
--region "$REGION" \
86+
--overwrite 2>/dev/null || aws ssm put-parameter \
87+
--name '/npm/token' \
88+
--value "$NPM_TOKEN" \
89+
--type SecureString \
90+
--region "$REGION"
91+
echo "✅ NPM token stored from environment variable"
92+
else
93+
# Prompt for token
94+
echo ""
95+
echo "📝 Please enter your NPM token:"
96+
echo " (Get it from: https://www.npmjs.com/settings/tokens)"
97+
read -s -p "NPM Token: " USER_NPM_TOKEN
98+
echo ""
99+
100+
if [ -n "$USER_NPM_TOKEN" ]; then
101+
aws ssm put-parameter \
102+
--name '/npm/token' \
103+
--value "$USER_NPM_TOKEN" \
104+
--type SecureString \
105+
--region "$REGION" \
106+
--overwrite 2>/dev/null || aws ssm put-parameter \
107+
--name '/npm/token' \
108+
--value "$USER_NPM_TOKEN" \
109+
--type SecureString \
110+
--region "$REGION"
111+
echo "✅ NPM token stored securely in SSM"
112+
else
113+
echo "⚠️ No token provided. Store manually with:"
114+
echo " aws ssm put-parameter --name '/npm/token' --value 'YOUR_TOKEN' --type SecureString --region $REGION"
115+
fi
116+
fi
117+
52118
echo ""
53-
echo "1. Set GitHub variables:"
54-
echo " gh variable set AWS_ROLE --body '$ROLE_ARN'"
55-
echo " gh variable set AWS_REGION --body 'us-east-1'"
119+
echo "🎉 Setup complete! Your NPM token is now:"
120+
echo " ✅ Stored encrypted in AWS SSM"
121+
echo " ✅ Accessible via GitHub Actions OIDC"
122+
echo " ✅ Ready for automatic NPM publishing"
56123
echo ""
57-
echo "2. Store NPM token:"
58-
echo " aws ssm put-parameter --name '/npm/token' --value 'YOUR_NPM_TOKEN' --type SecureString --region us-east-1"
124+
echo "💡 Test by pushing code - the workflow will automatically publish!"

0 commit comments

Comments
 (0)