@@ -34,4 +34,143 @@ jobs:
3434
3535 # Step 3: Always get latest 3 committed *_uqi_config.json files
3636 - name : Get latest committed JSON files
37- id : detect-
37+ id : detect-files
38+ run : |
39+ mkdir -p scripts
40+ OUTPUT_FILE="files_to_process.txt"
41+
42+ # Get the 3 most recently committed *_uqi_config.json files
43+ cd integration-resources
44+ git log --pretty=format: --name-only -n 20 \
45+ | grep 'Generic UQI Creation/uqi_configs/.*_uqi_config.json' \
46+ | sort -u \
47+ | head -n 3 \
48+ > ../$OUTPUT_FILE
49+ cd ..
50+
51+ echo "Files to process:"
52+ cat $OUTPUT_FILE || echo "None found"
53+
54+ if [ ! -s "$OUTPUT_FILE" ]; then
55+ echo "❌ No recent JSON files found. Exiting."
56+ exit 0
57+ fi
58+
59+ echo "changes_found=true" >> $GITHUB_ENV
60+
61+ # Step 4: Process each file with OpenAI to generate docs
62+ - name : Process files with OpenAI
63+ if : env.changes_found == 'true'
64+ run : |
65+ mkdir -p generated_docs
66+ PROCESSED_COUNT=0
67+
68+ while IFS= read -r FILE_PATH; do
69+ FILE_NAME=$(basename "$FILE_PATH")
70+ echo "⏳ Processing $FILE_NAME"
71+
72+ FILE_URL="https://raw.githubusercontent.com/appsmithorg/integration-resources/main/Generic%20UQI%20Creation/uqi_configs/$FILE_NAME"
73+ echo "Fetching content from: $FILE_URL"
74+ curl -fsSL --max-time 60 "$FILE_URL" -o input_file.json || {
75+ echo "❌ Failed to fetch $FILE_NAME"
76+ continue
77+ }
78+
79+ SYSTEM_PROMPT=$(cat .github/prompts/extract_prompt.txt || echo "Extract important integration details.")
80+ USER_CONTENT=$(cat input_file.json)
81+
82+ PAYLOAD=$(jq -n \
83+ --arg system "$SYSTEM_PROMPT" \
84+ --arg user "$USER_CONTENT" \
85+ '{
86+ model: "gpt-4-1106-preview",
87+ messages: [
88+ {"role": "system", "content": $system},
89+ {"role": "user", "content": $user}
90+ ],
91+ max_tokens: 2000,
92+ temperature: 0
93+ }')
94+
95+ RESPONSE1=$(curl -s https://api.openai.com/v1/chat/completions \
96+ -H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
97+ -H "Content-Type: application/json" \
98+ -d "$PAYLOAD")
99+
100+ if echo "$RESPONSE1" | jq -e '.error' > /dev/null; then
101+ echo "❌ OpenAI error on Prompt 1"
102+ echo "$RESPONSE1" | jq .
103+ continue
104+ fi
105+ echo "$RESPONSE1" | jq -r '.choices[0].message.content' > extracted_info.md
106+
107+ SYSTEM_PROMPT=$(cat .github/prompts/generate_prompt.txt || echo "Generate reference documentation in markdown.")
108+ EXTRACTED_CONTENT=$(cat extracted_info.md)
109+
110+ PAYLOAD=$(jq -n \
111+ --arg system "$SYSTEM_PROMPT" \
112+ --arg user "$EXTRACTED_CONTENT" \
113+ '{
114+ model: "gpt-4-1106-preview",
115+ messages: [
116+ {"role": "system", "content": $system},
117+ {"role": "user", "content": $user}
118+ ],
119+ max_tokens: 4000,
120+ temperature: 0.3
121+ }')
122+
123+ RESPONSE2=$(curl -s https://api.openai.com/v1/chat/completions \
124+ -H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
125+ -H "Content-Type: application/json" \
126+ -d "$PAYLOAD")
127+
128+ if echo "$RESPONSE2" | jq -e '.error' > /dev/null; then
129+ echo "❌ OpenAI error on Prompt 2"
130+ echo "$RESPONSE2" | jq .
131+ continue
132+ fi
133+ echo "$RESPONSE2" | jq -r '.choices[0].message.content' > generated_doc.md
134+
135+ INTEGRATION=$(echo "$FILE_NAME" | sed 's/_uqi_config\.json//' | tr '[:upper:]' '[:lower:]')
136+ FINAL_PATH="website/docs/connect-data/reference/${INTEGRATION}.md"
137+
138+ mkdir -p "$(dirname "$FINAL_PATH")"
139+ cp generated_doc.md "$FINAL_PATH"
140+
141+ echo "$FILE_NAME" >> scripts/processed_files.txt
142+ PROCESSED_COUNT=$((PROCESSED_COUNT + 1))
143+ echo "✅ Finished $FILE_NAME"
144+
145+ done < files_to_process.txt
146+
147+ echo "processed_count=$PROCESSED_COUNT" >> $GITHUB_ENV
148+ if [ "$PROCESSED_COUNT" -gt 0 ]; then
149+ echo "content_generated=true" >> $GITHUB_ENV
150+ else
151+ echo "content_generated=false" >> $GITHUB_ENV
152+ fi
153+ rm -f input_file.json extracted_info.md generated_doc.md
154+
155+ # Step 5: Commit and raise a PR
156+ - name : Commit and open PR
157+ if : env.content_generated == 'true'
158+ uses : peter-evans/create-pull-request@v6
159+ with :
160+ token : ${{ secrets.REPO_ACCESS_TOKEN }}
161+ title : " docs: update integration docs for ${{ github.event.inputs.target_branch }}"
162+ commit-message : " docs: automated generation for ${{ github.event.inputs.target_branch }}\n\n Generated from latest committed integration configs."
163+ branch : " docs-update/${{ github.event.inputs.target_branch }}-${{ github.run_id }}"
164+ base : ${{ github.event.inputs.target_branch }}
165+ add-paths : |
166+ website/docs/connect-data/reference/
167+ scripts/processed_files.txt
168+ body : |
169+ ✅ Auto-generated PR from `appsmithorg/integration-resources`.
170+
171+ **Target Branch:** `${{ github.event.inputs.target_branch }}`
172+ **Source Repo:** `appsmithorg/integration-resources`
173+
174+ This PR includes:
175+ - New/updated docs from the latest committed integration files.
176+ - Tracking file update in `scripts/processed_files.txt`.
0 commit comments