Skip to content

Commit 0f7c2dc

Browse files
committed
Move site generation logic to external script
This avoids all YAML heredoc parsing issues by keeping the workflow file simple.
1 parent 1a7e5b4 commit 0f7c2dc

File tree

2 files changed

+40
-37
lines changed

2 files changed

+40
-37
lines changed

.github/scripts/generate-site.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Build prompt file
5+
echo "You are a web developer creating a GitHub Pages site." > full_prompt.txt
6+
echo "" >> full_prompt.txt
7+
echo "Here are the requirements:" >> full_prompt.txt
8+
echo "" >> full_prompt.txt
9+
cat docs/site-prompt.md >> full_prompt.txt
10+
echo "" >> full_prompt.txt
11+
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
12+
13+
# Build JSON request with jq
14+
jq -n \
15+
--arg model "claude-sonnet-4-20250514" \
16+
--rawfile content full_prompt.txt \
17+
'{model: $model, max_tokens: 8192, messages: [{role: "user", content: $content}]}' \
18+
> request.json
19+
20+
# Call Claude API
21+
curl -s https://api.anthropic.com/v1/messages \
22+
-H "content-type: application/json" \
23+
-H "x-api-key: $ANTHROPIC_API_KEY" \
24+
-H "anthropic-version: 2023-06-01" \
25+
-d @request.json > response.json
26+
27+
# Extract HTML
28+
jq -r '.content[0].text' response.json > docs/index.html.new
29+
30+
# Verify output
31+
if [ ! -s docs/index.html.new ]; then
32+
echo "Error: Generated HTML is empty"
33+
jq '.' response.json
34+
exit 1
35+
fi
36+
37+
mv docs/index.html.new docs/index.html
38+
echo "Generated $(wc -l < docs/index.html) lines"

.github/workflows/generate-site.yml

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
paths:
88
- 'docs/site-prompt.md'
99
- '.github/workflows/generate-site.yml'
10+
- '.github/scripts/generate-site.sh'
1011

1112
jobs:
1213
generate:
@@ -18,46 +19,10 @@ jobs:
1819
- name: Checkout code
1920
uses: actions/checkout@v4
2021

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-
3122
- name: Generate site with Claude API
3223
env:
3324
ANTHROPIC_API_KEY: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
34-
run: |
35-
# Build JSON request with jq
36-
jq -n \
37-
--arg model "claude-sonnet-4-20250514" \
38-
--rawfile content full_prompt.txt \
39-
"{model: \$model, max_tokens: 8192, messages: [{role: \"user\", content: \$content}]}" \
40-
> request.json
41-
42-
# Call Claude API
43-
curl -s https://api.anthropic.com/v1/messages \
44-
-H "content-type: application/json" \
45-
-H "x-api-key: $ANTHROPIC_API_KEY" \
46-
-H "anthropic-version: 2023-06-01" \
47-
-d @request.json > response.json
48-
49-
# Extract HTML
50-
jq -r '.content[0].text' response.json > docs/index.html.new
51-
52-
# Verify output
53-
if [ ! -s docs/index.html.new ]; then
54-
echo "Error: Generated HTML is empty"
55-
jq '.' response.json
56-
exit 1
57-
fi
58-
59-
mv docs/index.html.new docs/index.html
60-
echo "Generated $(wc -l < docs/index.html) lines"
25+
run: bash .github/scripts/generate-site.sh
6126

6227
- name: Commit and push if changed
6328
run: |

0 commit comments

Comments
 (0)