Skip to content

Commit e791783

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

File tree

1 file changed

+57
-37
lines changed

1 file changed

+57
-37
lines changed

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

Lines changed: 57 additions & 37 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' # Weekly on Monday at 03:00 UTC
5+
- cron: '0 3 * * 1' # Every Monday at 03:00 UTC
66
workflow_dispatch:
77
inputs:
88
target_branch:
@@ -14,56 +14,63 @@ env:
1414
TARGET_BRANCH: ${{ github.event.inputs.target_branch || 'docs-staging' }}
1515

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

2020
steps:
21-
- name: Checkout appsmith-docs (target)
21+
- name: Checkout appsmith-docs
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
2827

29-
- name: Checkout appsmith repo
28+
- name: Checkout appsmith (release branch)
3029
uses: actions/checkout@v4
3130
with:
3231
repository: appsmithorg/appsmith
3332
token: ${{ secrets.REPO_ACCESS_TOKEN_WIDGETS }}
3433
ref: release
3534
path: appsmith
36-
fetch-depth: 10 # enough to get recent commit
35+
fetch-depth: 10
3736

38-
- name: Get most recently committed index.tsx file
37+
- name: Find last committed widget file
3938
id: latest-widget
4039
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+
4451
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."
4653
exit 0
4754
fi
4855
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
5158
echo "changes_found=true" >> $GITHUB_ENV
5259
53-
- name: Generate widget doc with OpenAI
60+
- name: Extract and generate documentation
5461
if: env.changes_found == 'true'
5562
run: |
5663
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")")")
6066
61-
cp "$FILE_PATH" widget_input.tsx
67+
echo "📦 Processing $WIDGET_NAME from $WIDGET_PATH"
68+
cp "appsmith/$WIDGET_PATH" widget_input.tsx
6269
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.")
6471
USER_CONTENT=$(cat widget_input.tsx)
6572
66-
# Prompt 1
73+
# Prompt 1: extract
6774
PAYLOAD1=$(jq -n \
6875
--arg system "$SYSTEM_PROMPT" \
6976
--arg user "$USER_CONTENT" \
@@ -82,14 +89,20 @@ jobs:
8289
-H "Content-Type: application/json" \
8390
-d "$PAYLOAD1")
8491
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
8699
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)
90103
91104
PAYLOAD2=$(jq -n \
92-
--arg system "$SYSTEM_PROMPT2" \
105+
--arg system "$SYSTEM_PROMPT" \
93106
--arg user "$EXTRACTED_CONTENT" \
94107
'{
95108
model: "gpt-4-1106-preview",
@@ -106,27 +119,34 @@ jobs:
106119
-H "Content-Type: application/json" \
107120
-d "$PAYLOAD2")
108121
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
113127
128+
echo "$RESPONSE2" | jq -r '.choices[0].message.content' > "website/docs/widgets/${WIDGET_NAME}.md"
129+
echo "$WIDGET_PATH" > processed_widget.txt
114130
echo "content_generated=true" >> $GITHUB_ENV
115131
116-
- name: Create PR
132+
rm -f widget_input.tsx extracted.md
133+
134+
- name: Commit and create PR
117135
if: env.content_generated == 'true'
118136
uses: peter-evans/create-pull-request@v6
119137
with:
120138
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 }}"
124144
base: ${{ env.TARGET_BRANCH }}
125145
add-paths: |
126146
website/docs/widgets/
127-
scripts/processed_widgets.txt
128147
body: |
129-
📦 Widget doc updated for latest committed widget in `release` branch.
148+
🛠 Auto-generated docs for latest widget from `appsmithorg/appsmith`.
130149
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

Comments
 (0)