@@ -2,7 +2,7 @@ name: Widget Doc Generator
2
2
3
3
on :
4
4
schedule :
5
- - cron : ' 0 3 * * 1' # Weekly on Monday at 03:00 UTC
5
+ - cron : ' 0 3 * * 1' # Every Monday at 03:00 UTC
6
6
workflow_dispatch :
7
7
inputs :
8
8
target_branch :
14
14
TARGET_BRANCH : ${{ github.event.inputs.target_branch || 'docs-staging' }}
15
15
16
16
jobs :
17
- generate_latest_widget_doc :
17
+ generate_widget_docs :
18
18
runs-on : ubuntu-latest
19
19
20
20
steps :
21
- - name : Checkout appsmith-docs (target)
21
+ - name : Checkout appsmith-docs
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
28
27
29
- - name : Checkout appsmith repo
28
+ - name : Checkout appsmith (release branch)
30
29
uses : actions/checkout@v4
31
30
with :
32
31
repository : appsmithorg/appsmith
33
32
token : ${{ secrets.REPO_ACCESS_TOKEN_WIDGETS }}
34
33
ref : release
35
34
path : appsmith
36
- fetch-depth : 10 # enough to get recent commit
35
+ fetch-depth : 10
37
36
38
- - name : Get most recently committed index.tsx file
37
+ - name : Find last committed widget file
39
38
id : latest-widget
40
39
run : |
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
-
40
+ cd appsmith
41
+
42
+ LAST_COMMIT=$(git log -n 1 --pretty=format:%H -- app/client/src/widgets/*/widget/index.tsx)
43
+
44
+ if [ -z "$LAST_COMMIT" ]; then
45
+ echo "No recent widget/index.tsx commit found. Exiting."
46
+ exit 0
47
+ fi
48
+
49
+ LAST_FILE=$(git diff-tree --no-commit-id --name-only -r $LAST_COMMIT | grep 'app/client/src/widgets/.*/widget/index.tsx' | head -n 1)
50
+
44
51
if [ -z "$LAST_FILE" ]; then
45
- echo "No recent widget/ index.tsx found. Exiting."
52
+ echo "No index.tsx file found in that commit . Exiting."
46
53
exit 0
47
54
fi
48
55
49
- echo "Found: $LAST_FILE"
50
- echo "widget_file_path=appsmith/app/client/src/widgets/ $LAST_FILE" >> $GITHUB_OUTPUT
56
+ echo "✅ Found: $LAST_FILE"
57
+ echo "widget_file_path=$LAST_FILE" >> $GITHUB_OUTPUT
51
58
echo "changes_found=true" >> $GITHUB_ENV
52
59
53
- - name : Generate widget doc with OpenAI
60
+ - name : Extract and generate documentation
54
61
if : env.changes_found == 'true'
55
62
run : |
56
63
mkdir -p website/docs/widgets
57
- FILE_PATH="${{ steps.latest-widget.outputs.widget_file_path }}"
58
- FILE_NAME=$(basename "$FILE_PATH")
59
- WIDGET_NAME=$(basename "$(dirname "$(dirname "$FILE_PATH")")")
64
+ WIDGET_PATH=${{ steps.latest-widget.outputs.widget_file_path }}
65
+ WIDGET_NAME=$(basename "$(dirname "$(dirname "$WIDGET_PATH")")")
60
66
61
- cp "$FILE_PATH" widget_input.tsx
67
+ echo "📦 Processing $WIDGET_NAME from $WIDGET_PATH"
68
+ cp "appsmith/$WIDGET_PATH" widget_input.tsx
62
69
63
- SYSTEM_PROMPT=$(cat .github/prompts/extract_prompt_widget.txt || echo "Extract widget info for docs .")
70
+ SYSTEM_PROMPT=$(cat .github/prompts/extract_prompt_widget.txt || echo "Extract important widget info.")
64
71
USER_CONTENT=$(cat widget_input.tsx)
65
72
66
- # Prompt 1
73
+ # Prompt 1: extract
67
74
PAYLOAD1=$(jq -n \
68
75
--arg system "$SYSTEM_PROMPT" \
69
76
--arg user "$USER_CONTENT" \
@@ -82,14 +89,20 @@ jobs:
82
89
-H "Content-Type: application/json" \
83
90
-d "$PAYLOAD1")
84
91
85
- echo "$RESPONSE1" | jq -r '.choices[0].message.content' > extracted_widget_info.md
92
+ if echo "$RESPONSE1" | jq -e '.error' > /dev/null; then
93
+ echo "❌ Error in extract step"
94
+ echo "$RESPONSE1" | jq .
95
+ exit 1
96
+ fi
97
+
98
+ echo "$RESPONSE1" | jq -r '.choices[0].message.content' > extracted.md
86
99
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)
100
+ # Prompt 2: generate markdown
101
+ SYSTEM_PROMPT =$(cat .github/prompts/generate_prompt_widget.txt || echo "Generate widget markdown documentation .")
102
+ EXTRACTED_CONTENT=$(cat extracted .md)
90
103
91
104
PAYLOAD2=$(jq -n \
92
- --arg system "$SYSTEM_PROMPT2 " \
105
+ --arg system "$SYSTEM_PROMPT " \
93
106
--arg user "$EXTRACTED_CONTENT" \
94
107
'{
95
108
model: "gpt-4-1106-preview",
@@ -106,27 +119,34 @@ jobs:
106
119
-H "Content-Type: application/json" \
107
120
-d "$PAYLOAD2")
108
121
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
122
+ if echo "$RESPONSE2" | jq -e '.error' > /dev/null; then
123
+ echo "❌ Error in generate step"
124
+ echo "$RESPONSE2" | jq .
125
+ exit 1
126
+ fi
113
127
128
+ echo "$RESPONSE2" | jq -r '.choices[0].message.content' > "website/docs/widgets/${WIDGET_NAME}.md"
129
+ echo "$WIDGET_PATH" > processed_widget.txt
114
130
echo "content_generated=true" >> $GITHUB_ENV
115
131
116
- - name : Create PR
132
+ rm -f widget_input.tsx extracted.md
133
+
134
+ - name : Commit and create PR
117
135
if : env.content_generated == 'true'
118
136
uses : peter-evans/create-pull-request@v6
119
137
with :
120
138
token : ${{ secrets.REPO_ACCESS_TOKEN_WIDGETS }}
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 }}"
139
+ title : " docs: update widget docs for ${{ env.TARGET_BRANCH }}"
140
+ commit-message : |
141
+ docs: auto-generated widget documentation
142
+ Generated markdown for latest widget.
143
+ branch : " widgets-update/${{ env.TARGET_BRANCH }}-${{ github.run_id }}"
124
144
base : ${{ env.TARGET_BRANCH }}
125
145
add-paths : |
126
146
website/docs/widgets/
127
- scripts/processed_widgets.txt
128
147
body : |
129
- 📦 Widget doc updated for latest committed widget in `release` branch .
148
+ 🛠 Auto-generated docs for latest widget from `appsmithorg/appsmith` .
130
149
131
- - Source: `appsmithorg/appsmith`
132
- - Widget file: `$(cat scripts/processed_widgets.txt)`
150
+ **Branch:** `${{ env.TARGET_BRANCH }}`
151
+ **Widget File:**
152
+ $(cat processed_widget.txt | sed 's/^/- /')
0 commit comments