Skip to content

Commit bc2dbcf

Browse files
authored
Update sample-file-trigger.yml
1 parent 4053332 commit bc2dbcf

File tree

1 file changed

+72
-19
lines changed

1 file changed

+72
-19
lines changed
Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,96 @@
1-
name: Process Sample Workflow Files
1+
name: Process Sample Files and Generate Docs
22

33
on:
44
push:
55
paths:
6-
- 'website/docs/sample-workflow-tests/**' # Only trigger when something changes inside this folder
6+
- 'website/docs/sample-workflow-tests/**'
77

88
jobs:
9-
detect_and_run_sample_api:
9+
process_sample_file:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- name: Checkout the repository
13+
- name: Checkout repository
1414
uses: actions/checkout@v4
1515

16-
- name: Detect newly added or modified files
16+
- name: Detect changed files
1717
id: detect_files
1818
run: |
1919
echo "Detecting changes..."
2020
git fetch origin main
21-
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} -- 'website/docs/sample-workflow-tests/' || true)
21+
CHANGED_FILE=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} -- 'website/docs/sample-workflow-tests/' | head -n 1 || true)
2222
23-
echo "Changed files:"
24-
echo "$CHANGED_FILES"
23+
if [ -z "$CHANGED_FILE" ]; then
24+
echo "No relevant file found. Exiting."
25+
exit 0
26+
fi
2527
26-
# Save changed files into output
27-
echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
28+
echo "Changed file detected: $CHANGED_FILE"
29+
echo "file_path=$CHANGED_FILE" >> $GITHUB_ENV
2830
29-
- name: Run Sample API if new file detected
30-
if: steps.detect_files.outputs.changed_files != ''
31+
- name: Read file content
32+
id: read_file
3133
run: |
32-
echo "Running Sample API call..."
33-
34-
curl https://api.openai.com/v1/chat/completions \
34+
echo "Reading file content..."
35+
CONTENT=$(cat ${{ env.file_path }} | jq -Rs .)
36+
echo "file_content=$CONTENT" >> $GITHUB_ENV
37+
38+
- name: Extract Details from JSON (OpenAI Part 1)
39+
id: extract_details
40+
run: |
41+
echo "Sending JSON to OpenAI to extract details..."
42+
43+
EXTRACTED=$(curl -s https://api.openai.com/v1/chat/completions \
44+
-H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
45+
-H "Content-Type: application/json" \
46+
-d '{
47+
"model": "gpt-4o",
48+
"messages": [
49+
{
50+
"role": "system",
51+
"content": "You are a technical extractor. From the following JSON input, extract and list all properties, labels, descriptions, controlTypes, and configProperties clearly in a flat structure."
52+
},
53+
{
54+
"role": "user",
55+
"content": '${{ env.file_content }}'
56+
}
57+
],
58+
"temperature": 0
59+
}' | jq -r '.choices[0].message.content')
60+
61+
echo "$EXTRACTED" > extracted_details.json
62+
echo "Extraction completed."
63+
64+
- name: Generate Documentation Text (OpenAI Part 2)
65+
id: generate_doc
66+
run: |
67+
echo "Sending extracted details to OpenAI to generate documentation..."
68+
69+
DETAILS=$(cat extracted_details.json | jq -Rs .)
70+
71+
GENERATED_DOC=$(curl -s https://api.openai.com/v1/chat/completions \
3572
-H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \
3673
-H "Content-Type: application/json" \
3774
-d '{
3875
"model": "gpt-4o",
39-
"messages": [{"role": "user", "content": "Test message from GitHub Actions"}],
40-
"temperature": 0.2
41-
}'
76+
"messages": [
77+
{
78+
"role": "system",
79+
"content": "You are a documentation generator. Given the extracted details, write a clean, structured Markdown documentation. Create a 'Properties' table listing each property, control type, label, and description."
80+
},
81+
{
82+
"role": "user",
83+
"content": '"$DETAILS"'
84+
}
85+
],
86+
"temperature": 0.3
87+
}' | jq -r '.choices[0].message.content')
88+
89+
echo "$GENERATED_DOC" > generated_doc.md
90+
echo "Documentation generated."
4291
43-
echo "Sample API call completed."
92+
- name: Upload generated documentation as artifact
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: generated-doc
96+
path: generated_doc.md

0 commit comments

Comments
 (0)