@@ -2,7 +2,7 @@ name: Widget Doc Generator
2
2
3
3
on :
4
4
schedule :
5
- - cron : ' 0 3 * * 1' # Every Monday at 03:00 UTC
5
+ - cron : ' 0 3 * * 1' # Weekly on Monday at 03:00 UTC
6
6
workflow_dispatch :
7
7
inputs :
8
8
target_branch :
@@ -14,157 +14,119 @@ env:
14
14
TARGET_BRANCH : ${{ github.event.inputs.target_branch || 'docs-staging' }}
15
15
16
16
jobs :
17
- generate_widget_docs :
17
+ generate_latest_widget_doc :
18
18
runs-on : ubuntu-latest
19
19
20
20
steps :
21
- - name : Checkout appsmith-docs
21
+ - name : Checkout appsmith-docs (target)
22
22
uses : actions/checkout@v4
23
23
with :
24
24
token : ${{ secrets.REPO_ACCESS_TOKEN_WIDGETS }}
25
25
ref : ${{ env.TARGET_BRANCH }}
26
26
fetch-depth : 0
27
+ persist-credentials : false
27
28
28
- - name : Checkout appsmith (release branch)
29
+ - name : Checkout appsmith repo
29
30
uses : actions/checkout@v4
30
31
with :
31
32
repository : appsmithorg/appsmith
32
33
token : ${{ secrets.REPO_ACCESS_TOKEN_WIDGETS }}
33
34
ref : release
34
35
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
43
37
44
- - name : Filter widget `widget/index.tsx` files
38
+ - name : Get most recently committed index.tsx file
39
+ id : latest-widget
45
40
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."
53
46
exit 0
54
47
fi
55
48
49
+ echo "Found: $LAST_FILE"
50
+ echo "widget_file_path=appsmith/app/client/src/widgets/$LAST_FILE" >> $GITHUB_OUTPUT
56
51
echo "changes_found=true" >> $GITHUB_ENV
57
52
58
- - name : Generate documentation with OpenAI
53
+ - name : Generate widget doc with OpenAI
59
54
if : env.changes_found == 'true'
60
55
run : |
61
56
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
150
117
if : env.content_generated == 'true'
151
118
uses : peter-evans/create-pull-request@v6
152
119
with :
153
120
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 }}"
160
124
base : ${{ env.TARGET_BRANCH }}
161
125
add-paths : |
162
126
website/docs/widgets/
163
127
scripts/processed_widgets.txt
164
128
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.
170
130
131
+ - Source: `appsmithorg/appsmith`
132
+ - Widget file: `$(cat scripts/processed_widgets.txt)`
0 commit comments