Skip to content

Commit c664ab8

Browse files
authored
Update widget-doc-generator.yml
1 parent 8b9181b commit c664ab8

File tree

1 file changed

+82
-120
lines changed

1 file changed

+82
-120
lines changed

.github/workflows/widget-doc-generator.yml

Lines changed: 82 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Widget Doc Generator
22

33
on:
44
schedule:
5-
- cron: '0 3 * * 1' # Every Monday at 03:00 UTC
5+
- cron: '0 3 * * 1' # Weekly on Monday at 03:00 UTC
66
workflow_dispatch:
77
inputs:
88
target_branch:
@@ -14,157 +14,119 @@ env:
1414
TARGET_BRANCH: ${{ github.event.inputs.target_branch || 'docs-staging' }}
1515

1616
jobs:
17-
generate_widget_docs:
17+
generate_latest_widget_doc:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21-
- name: Checkout appsmith-docs
21+
- name: Checkout appsmith-docs (target)
2222
uses: actions/checkout@v4
2323
with:
2424
token: ${{ secrets.REPO_ACCESS_TOKEN_WIDGETS }}
2525
ref: ${{ env.TARGET_BRANCH }}
2626
fetch-depth: 0
27+
persist-credentials: false
2728

28-
- name: Checkout appsmith (release branch)
29+
- name: Checkout appsmith repo
2930
uses: actions/checkout@v4
3031
with:
3132
repository: appsmithorg/appsmith
3233
token: ${{ secrets.REPO_ACCESS_TOKEN_WIDGETS }}
3334
ref: release
3435
path: appsmith
35-
fetch-depth: 0
36-
37-
- name: Get changed widget files
38-
id: changed-files
39-
uses: tj-actions/changed-files@v46
40-
with:
41-
path: appsmith/app/client/src/widgets
42-
since_last_remote_commit: true
36+
fetch-depth: 10 # enough to get recent commit
4337

44-
- name: Filter widget `widget/index.tsx` files
38+
- name: Get most recently committed index.tsx file
39+
id: latest-widget
4540
run: |
46-
mkdir -p scripts
47-
echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' |
48-
grep '/widget/index.tsx$' > widget_files_to_process.txt
49-
50-
cat widget_files_to_process.txt
51-
if [ ! -s widget_files_to_process.txt ]; then
52-
echo "No relevant widget changes found. Exiting."
41+
cd appsmith/app/client/src/widgets
42+
LAST_FILE=$(git log -1 --pretty=format: --name-only | grep '/widget/index.tsx$' | head -n 1)
43+
44+
if [ -z "$LAST_FILE" ]; then
45+
echo "No recent widget/index.tsx found. Exiting."
5346
exit 0
5447
fi
5548
49+
echo "Found: $LAST_FILE"
50+
echo "widget_file_path=appsmith/app/client/src/widgets/$LAST_FILE" >> $GITHUB_OUTPUT
5651
echo "changes_found=true" >> $GITHUB_ENV
5752
58-
- name: Generate documentation with OpenAI
53+
- name: Generate widget doc with OpenAI
5954
if: env.changes_found == 'true'
6055
run: |
6156
mkdir -p website/docs/widgets
62-
PROCESSED_COUNT=0
63-
64-
while IFS= read -r FILE_PATH; do
65-
echo "📦 Processing $FILE_PATH"
66-
67-
WIDGET_NAME=$(basename "$(dirname "$(dirname "$FILE_PATH")")")
68-
cp "$FILE_PATH" widget_input.tsx
69-
70-
SYSTEM_PROMPT=$(cat .github/prompts/extract_prompt_widget.txt || echo "Extract important widget info from the following code.")
71-
USER_CONTENT=$(cat widget_input.tsx)
72-
73-
# Step 1: Extraction
74-
PAYLOAD1=$(jq -n \
75-
--arg system "$SYSTEM_PROMPT" \
76-
--arg user "$USER_CONTENT" \
77-
'{
78-
model: "gpt-4-1106-preview",
79-
messages: [
80-
{"role": "system", "content": $system},
81-
{"role": "user", "content": $user}
82-
],
83-
max_tokens: 2000,
84-
temperature: 0
85-
}')
86-
87-
RESPONSE1=$(curl -s https://api.openai.com/v1/chat/completions \
88-
-H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
89-
-H "Content-Type: application/json" \
90-
-d "$PAYLOAD1")
91-
92-
if echo "$RESPONSE1" | jq -e '.error' > /dev/null; then
93-
echo "❌ OpenAI error on prompt 1 for $WIDGET_NAME"
94-
echo "$RESPONSE1" | jq .
95-
continue
96-
fi
97-
98-
echo "$RESPONSE1" | jq -r '.choices[0].message.content' > extracted_info.md
99-
100-
# Step 2: Generate Markdown
101-
SYSTEM_PROMPT=$(cat .github/prompts/generate_prompt_widget.txt || echo "Generate markdown documentation for the widget.")
102-
EXTRACTED_CONTENT=$(cat extracted_info.md)
103-
104-
PAYLOAD2=$(jq -n \
105-
--arg system "$SYSTEM_PROMPT" \
106-
--arg user "$EXTRACTED_CONTENT" \
107-
'{
108-
model: "gpt-4-1106-preview",
109-
messages: [
110-
{"role": "system", "content": $system},
111-
{"role": "user", "content": $user}
112-
],
113-
max_tokens: 4000,
114-
temperature: 0.3
115-
}')
116-
117-
RESPONSE2=$(curl -s https://api.openai.com/v1/chat/completions \
118-
-H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
119-
-H "Content-Type: application/json" \
120-
-d "$PAYLOAD2")
121-
122-
if echo "$RESPONSE2" | jq -e '.error' > /dev/null; then
123-
echo "❌ OpenAI error on prompt 2 for $WIDGET_NAME"
124-
echo "$RESPONSE2" | jq .
125-
continue
126-
fi
127-
128-
echo "$RESPONSE2" | jq -r '.choices[0].message.content' > generated_doc.md
129-
130-
FINAL_PATH="website/docs/widgets/${WIDGET_NAME}.md"
131-
mkdir -p "$(dirname "$FINAL_PATH")"
132-
cp generated_doc.md "$FINAL_PATH"
133-
echo "$FILE_PATH" >> scripts/processed_widgets.txt
134-
135-
PROCESSED_COUNT=$((PROCESSED_COUNT + 1))
136-
echo "✅ Generated doc for $WIDGET_NAME"
137-
138-
done < widget_files_to_process.txt
139-
140-
echo "processed_count=$PROCESSED_COUNT" >> $GITHUB_ENV
141-
if [ "$PROCESSED_COUNT" -gt 0 ]; then
142-
echo "content_generated=true" >> $GITHUB_ENV
143-
else
144-
echo "content_generated=false" >> $GITHUB_ENV
145-
fi
146-
147-
rm -f widget_input.tsx extracted_info.md generated_doc.md
148-
149-
- name: Commit and open PR
57+
FILE_PATH="${{ steps.latest-widget.outputs.widget_file_path }}"
58+
FILE_NAME=$(basename "$FILE_PATH")
59+
WIDGET_NAME=$(basename "$(dirname "$(dirname "$FILE_PATH")")")
60+
61+
cp "$FILE_PATH" widget_input.tsx
62+
63+
SYSTEM_PROMPT=$(cat .github/prompts/extract_prompt_widget.txt || echo "Extract widget info for docs.")
64+
USER_CONTENT=$(cat widget_input.tsx)
65+
66+
# Prompt 1
67+
PAYLOAD1=$(jq -n \
68+
--arg system "$SYSTEM_PROMPT" \
69+
--arg user "$USER_CONTENT" \
70+
'{
71+
model: "gpt-4-1106-preview",
72+
messages: [
73+
{"role": "system", "content": $system},
74+
{"role": "user", "content": $user}
75+
],
76+
max_tokens: 2000,
77+
temperature: 0
78+
}')
79+
80+
RESPONSE1=$(curl -s https://api.openai.com/v1/chat/completions \
81+
-H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
82+
-H "Content-Type: application/json" \
83+
-d "$PAYLOAD1")
84+
85+
echo "$RESPONSE1" | jq -r '.choices[0].message.content' > extracted_widget_info.md
86+
87+
# Prompt 2
88+
SYSTEM_PROMPT2=$(cat .github/prompts/generate_prompt_widget.txt || echo "Convert extracted info to markdown.")
89+
EXTRACTED_CONTENT=$(cat extracted_widget_info.md)
90+
91+
PAYLOAD2=$(jq -n \
92+
--arg system "$SYSTEM_PROMPT2" \
93+
--arg user "$EXTRACTED_CONTENT" \
94+
'{
95+
model: "gpt-4-1106-preview",
96+
messages: [
97+
{"role": "system", "content": $system},
98+
{"role": "user", "content": $user}
99+
],
100+
max_tokens: 4000,
101+
temperature: 0.3
102+
}')
103+
104+
RESPONSE2=$(curl -s https://api.openai.com/v1/chat/completions \
105+
-H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
106+
-H "Content-Type: application/json" \
107+
-d "$PAYLOAD2")
108+
109+
echo "$RESPONSE2" | jq -r '.choices[0].message.content' > generated_widget_doc.md
110+
111+
cp generated_widget_doc.md "website/docs/widgets/${WIDGET_NAME}.md"
112+
echo "$FILE_PATH" > scripts/processed_widgets.txt
113+
114+
echo "content_generated=true" >> $GITHUB_ENV
115+
116+
- name: Create PR
150117
if: env.content_generated == 'true'
151118
uses: peter-evans/create-pull-request@v6
152119
with:
153120
token: ${{ secrets.REPO_ACCESS_TOKEN_WIDGETS }}
154-
title: "docs: update widget docs for ${{ env.TARGET_BRANCH }}"
155-
commit-message: |
156-
docs: auto-generated widget documentation
157-
158-
Generated markdown for updated widgets from `appsmithorg/appsmith`.
159-
branch: "widgets-update/${{ env.TARGET_BRANCH }}-${{ github.run_id }}"
121+
title: "docs: auto-gen widget doc for ${{ env.TARGET_BRANCH }}"
122+
commit-message: "docs: auto-generated docs for updated widget"
123+
branch: "widget-doc-update/${{ github.run_id }}"
160124
base: ${{ env.TARGET_BRANCH }}
161125
add-paths: |
162126
website/docs/widgets/
163127
scripts/processed_widgets.txt
164128
body: |
165-
📘 Auto-generated docs for updated widgets from `appsmithorg/appsmith`.
166-
167-
**Branch:** `${{ env.TARGET_BRANCH }}`
168-
**Processed Files:**
169-
$(cat scripts/processed_widgets.txt | sed 's/^/- /')
129+
📦 Widget doc updated for latest committed widget in `release` branch.
170130
131+
- Source: `appsmithorg/appsmith`
132+
- Widget file: `$(cat scripts/processed_widgets.txt)`

0 commit comments

Comments
 (0)