|
18 | 18 | - name: Checkout code |
19 | 19 | uses: actions/checkout@v4 |
20 | 20 |
|
21 | | - - name: Test step |
22 | | - run: echo "Workflow is running successfully" |
| 21 | + - name: Build prompt |
| 22 | + run: | |
| 23 | + echo "You are a web developer creating a GitHub Pages site." > full_prompt.txt |
| 24 | + echo "" >> full_prompt.txt |
| 25 | + echo "Here are the requirements:" >> full_prompt.txt |
| 26 | + echo "" >> full_prompt.txt |
| 27 | + cat docs/site-prompt.md >> full_prompt.txt |
| 28 | + echo "" >> full_prompt.txt |
| 29 | + echo "Please generate a complete, production-ready index.html file following all requirements. Output ONLY the HTML code, no explanations or markdown code blocks." >> full_prompt.txt |
| 30 | +
|
| 31 | + - name: Generate site with Claude API |
| 32 | + env: |
| 33 | + ANTHROPIC_API_KEY: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} |
| 34 | + run: | |
| 35 | + # Build JSON request |
| 36 | + PROMPT=$(cat full_prompt.txt | jq -Rs .) |
| 37 | +
|
| 38 | + cat > request.json <<EOF |
| 39 | +{ |
| 40 | + "model": "claude-sonnet-4-20250514", |
| 41 | + "max_tokens": 8192, |
| 42 | + "messages": [{ |
| 43 | + "role": "user", |
| 44 | + "content": $PROMPT |
| 45 | + }] |
| 46 | +} |
| 47 | +EOF |
| 48 | + |
| 49 | + # Call Claude API |
| 50 | + curl -s https://api.anthropic.com/v1/messages \ |
| 51 | + -H "content-type: application/json" \ |
| 52 | + -H "x-api-key: $ANTHROPIC_API_KEY" \ |
| 53 | + -H "anthropic-version: 2023-06-01" \ |
| 54 | + -d @request.json > response.json |
| 55 | + |
| 56 | + # Extract HTML |
| 57 | + jq -r '.content[0].text' response.json > docs/index.html.new |
| 58 | + |
| 59 | + # Verify output |
| 60 | + if [ ! -s docs/index.html.new ]; then |
| 61 | + echo "Error: Generated HTML is empty" |
| 62 | + jq '.' response.json |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + mv docs/index.html.new docs/index.html |
| 67 | + echo "Generated $(wc -l < docs/index.html) lines" |
| 68 | + |
| 69 | + - name: Commit and push if changed |
| 70 | + run: | |
| 71 | + git config user.name 'github-actions[bot]' |
| 72 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 73 | + git add docs/index.html |
| 74 | +
|
| 75 | + if git diff --staged --quiet; then |
| 76 | + echo "No changes to commit" |
| 77 | + else |
| 78 | + git commit -m "Regenerate GitHub Pages site |
| 79 | +
|
| 80 | +Generated by Claude API from docs/site-prompt.md" |
| 81 | + git push |
| 82 | + fi |
0 commit comments