API Key Setup for Workflow Testing
Complete guide for setting up API keys for GitHub Actions workflow testing.
Overview
Several workflows require API keys for testing:
- AI Issue Triage - OpenAI API key
- GitHub Projects V2 - GitHub Personal Access Token (PAT)
This guide covers setup for local testing and CI/CD.
Option A: Using .env.local (Recommended for Local Testing)
OpenAI API Key
Get your API key:
- Visit OpenAI API Keys
- Click "Create new secret key"
- Copy the key (starts with
sk-proj-)
Add to .env.local:
bash# In your project root echo "OPENAI_API_KEY=sk-proj-YOUR_KEY_HERE" >> .env.localVerify it works:
bashgrep OPENAI_API_KEY .env.local
Why this works:
- ✅ Test scripts automatically load from
.env.local - ✅ Never committed (it's in
.gitignore) - ✅ Works for all test scripts
- ✅ Simplest setup
GitHub Personal Access Token (PAT)
For GitHub Projects V2 testing:
Create PAT:
- Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token (classic)"
- Select scopes:
repo+project - Copy the token
Add to .env.local:
bashecho "GH_PAT=ghp_YOUR_TOKEN_HERE" >> .env.local
Why this works:
- ✅
.github/workflows/test-projects-v2.shloads from.env.local - ✅ Never committed
- ✅ Recommended for local testing
Option B: Using GitHub CLI Secrets (For CI/CD)
Use this method for GitHub Actions workflows that need API keys.
OpenAI API Key
bash
# 1. Install GitHub CLI (if needed)
brew install gh # macOS
# or visit https://cli.github.com
# 2. Authenticate
gh auth login
# 3. Store your API key
gh secret set OPENAI_API_KEY
# Paste your key and press Enter
# 4. Verify it was stored
gh secret listWorkflows automatically use OPENAI_API_KEY secret.
GitHub Personal Access Token
bash
# 1. Create your PAT (see Option A steps 1-2 above)
# 2. Store in GitHub
gh secret set GH_PAT
# Paste your token and press Enter
# 3. Verify
gh secret listWorkflows automatically use GH_PAT secret.
Security Best Practices
✅ DO
- Store API keys in
.env.local(local testing) or GitHub Secrets (CI/CD) - Rotate keys periodically
- Use minimal required scopes (e.g.,
repo+projectfor GitHub, read-only for OpenAI) - Review GitHub Secrets quarterly
- Use separate keys for dev and production
❌ DON'T
- Commit
.env.localto Git (it's in.gitignore) - Share API keys in messages, PRs, or commit messages
- Use the same key for dev and production
- Grant unnecessary permissions (e.g., admin scopes)
- Leave expired or unused keys active
Troubleshooting
"OPENAI_API_KEY not found"
Local testing:
bash
# Check if .env.local exists
ls -la .env.local
# Check if key is set correctly
grep OPENAI_API_KEY .env.local
# If not set, add it
echo "OPENAI_API_KEY=sk-proj-YOUR_KEY_HERE" >> .env.localCI/CD:
bash
# Check if secret is stored
gh secret list
# If not, set it
gh secret set OPENAI_API_KEY"Invalid API key"
Verify your key:
- Starts with
sk-proj-(OpenAI) - Not expired at https://platform.openai.com/api-keys
- Has available credits
- Not revoked or disabled
"gh: command not found"
Install GitHub CLI:
bash
# macOS
brew install gh
# Ubuntu/Debian
sudo apt install gh
# Or visit https://cli.github.com"Not authenticated"
Authenticate with GitHub:
bash
gh auth login"Rate limited"
Wait before retrying. If using OpenAI API:
- Check billing at https://platform.openai.com/account/billing
- Consider rate limiting headers
- Use mock tests for rapid iteration (they're free)
Cost Estimation
| Service | Cost | Usage |
|---|---|---|
| OpenAI API | ~$0.0002 per issue triage | Mock tests: free |
| GitHub API | Free (with PAT) | Unlimited for Projects V2 |
Example monthly costs with 100 issues triaged with real API:
- OpenAI: ~$0.02
- GitHub: $0
- Total: <$0.02/month
Testing Your Setup
OpenAI API Key
bash
# Quick test with curl
curl https://api.openai.com/v1/models \
-H "Authorization: Bearer $OPENAI_API_KEY" | head -20Expected: List of available models (not an error)
GitHub PAT
bash
# Quick test
gh auth status
gh api user -q .loginExpected: Your GitHub username
See Also
- AI Issue Triage Testing - OpenAI setup guide
- GitHub Projects V2 Testing - PAT setup guide
- Workflows Overview - All workflows