|
1 | | -name: Process Sample Workflow Files |
| 1 | +name: Process Sample Files and Generate Docs |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | paths: |
6 | | - - 'website/docs/sample-workflow-tests/**' # Only trigger when something changes inside this folder |
| 6 | + - 'website/docs/sample-workflow-tests/**' |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - detect_and_run_sample_api: |
| 9 | + process_sample_file: |
10 | 10 | runs-on: ubuntu-latest |
11 | 11 |
|
12 | 12 | steps: |
13 | | - - name: Checkout the repository |
| 13 | + - name: Checkout repository |
14 | 14 | uses: actions/checkout@v4 |
15 | 15 |
|
16 | | - - name: Detect newly added or modified files |
| 16 | + - name: Detect changed files |
17 | 17 | id: detect_files |
18 | 18 | run: | |
19 | 19 | echo "Detecting changes..." |
20 | 20 | 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) |
22 | 22 | |
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 |
25 | 27 | |
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 |
28 | 30 |
|
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 |
31 | 33 | 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 \ |
35 | 72 | -H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \ |
36 | 73 | -H "Content-Type: application/json" \ |
37 | 74 | -d '{ |
38 | 75 | "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." |
42 | 91 |
|
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