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