|
| 1 | +name: Claude API Test |
| 2 | + |
| 3 | +"on": |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + issues: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + test-api: |
| 12 | + if: contains(github.event.issue.title, 'test-claude-api') |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Test Claude API |
| 17 | + env: |
| 18 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 19 | + run: | |
| 20 | + echo "Testing Claude API connection..." |
| 21 | + |
| 22 | + # Check if API key exists |
| 23 | + if [ -z "$ANTHROPIC_API_KEY" ]; then |
| 24 | + echo "❌ ANTHROPIC_API_KEY is not set!" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + |
| 28 | + echo "✅ API key is set (length: ${#ANTHROPIC_API_KEY})" |
| 29 | + |
| 30 | + # Test API call with detailed error output |
| 31 | + RESPONSE=$(curl -v https://api.anthropic.com/v1/messages \ |
| 32 | + -H "Content-Type: application/json" \ |
| 33 | + -H "x-api-key: $ANTHROPIC_API_KEY" \ |
| 34 | + -d '{ |
| 35 | + "model": "claude-sonnet-4-20250514", |
| 36 | + "max_tokens": 100, |
| 37 | + "messages": [{ |
| 38 | + "role": "user", |
| 39 | + "content": "Say hello" |
| 40 | + }] |
| 41 | + }' 2>&1) |
| 42 | + |
| 43 | + echo "Full response:" |
| 44 | + echo "$RESPONSE" |
| 45 | + |
| 46 | + # Try to extract error |
| 47 | + ERROR=$(echo "$RESPONSE" | jq -r '.error.message // "No error field"' 2>/dev/null || echo "Could not parse JSON") |
| 48 | + |
| 49 | + echo "" |
| 50 | + echo "Error message: $ERROR" |
| 51 | + |
| 52 | + # Save response |
| 53 | + echo "$RESPONSE" > api_test.txt |
| 54 | +
|
| 55 | + - name: Post result |
| 56 | + uses: actions/github-script@v7 |
| 57 | + with: |
| 58 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + script: | |
| 60 | + const fs = require('fs'); |
| 61 | + let result = 'Could not read test results'; |
| 62 | + try { |
| 63 | + result = fs.readFileSync('api_test.txt', 'utf8'); |
| 64 | + } catch (e) { |
| 65 | + result = 'Error reading file: ' + e.message; |
| 66 | + } |
| 67 | + |
| 68 | + await github.rest.issues.createComment({ |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + issue_number: context.issue.number, |
| 72 | + body: `## 🔍 Claude API Test Results\n\n\`\`\`\n${result}\n\`\`\`` |
| 73 | + }); |
0 commit comments