|
| 1 | +name: Test Doc Generator |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + generate_docs: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + |
| 10 | + steps: |
| 11 | + - name: Checkout appsmith-docs |
| 12 | + uses: actions/checkout@v4 |
| 13 | + with: |
| 14 | + token: ${{ secrets.test_REPO_ACCESS_TOKEN }} |
| 15 | + |
| 16 | + - name: Create exclusion list for test |
| 17 | + run: | |
| 18 | + cat > saas_exclusions.txt << EOF |
| 19 | + EOF |
| 20 | +
|
| 21 | + - name: Ensure scripts directory exists |
| 22 | + run: | |
| 23 | + mkdir -p scripts |
| 24 | + [ -f scripts/processed_files.txt ] || touch scripts/processed_files.txt |
| 25 | + [ -f scripts/file_hashes.json ] || echo "{}" > scripts/file_hashes.json |
| 26 | +
|
| 27 | + - name: Fetch file list from test repo |
| 28 | + id: fetch_files |
| 29 | + run: | |
| 30 | + curl -s --max-time 30 -H "Authorization: Bearer ${{ secrets.test_REPO_ACCESS_TOKEN }}" \ |
| 31 | + -H "Accept: application/vnd.github+json" \ |
| 32 | + https://api.github.com/repos/harshilp24/integration-resources-test/contents/Generic%20UQI%20Creation/uqi_configs \ |
| 33 | + -o response.json |
| 34 | +
|
| 35 | + jq -r '.[] | select(.type=="file") | [.name, .sha] | @tsv' response.json > latest_files_with_sha.txt |
| 36 | + jq -r '.[] | select(.type=="file") | .name' response.json > latest_files.txt |
| 37 | +
|
| 38 | + echo "files_found=true" >> $GITHUB_ENV |
| 39 | +
|
| 40 | + - name: Identify new and modified files |
| 41 | + id: detect_changes |
| 42 | + run: | |
| 43 | + PREV_HASHES=$(cat scripts/file_hashes.json) |
| 44 | + NEW_FILES=$(comm -23 <(sort latest_files.txt) <(sort scripts/processed_files.txt) || true) |
| 45 | + MODIFIED_FILES="" |
| 46 | + while IFS=$'\t' read -r FILE_NAME FILE_SHA; do |
| 47 | + PREV_SHA=$(echo "$PREV_HASHES" | jq -r --arg file "$FILE_NAME" '.[$file] // ""') |
| 48 | + if [ -n "$PREV_SHA" ] && [ "$PREV_SHA" != "$FILE_SHA" ] && grep -q "^$FILE_NAME$" scripts/processed_files.txt; then |
| 49 | + MODIFIED_FILES="$MODIFIED_FILES$FILE_NAME"$'\n' |
| 50 | + fi |
| 51 | + done < latest_files_with_sha.txt |
| 52 | + { echo "$NEW_FILES"; echo "$MODIFIED_FILES"; } | grep -v "^$" > files_to_process.txt |
| 53 | + if [ -s files_to_process.txt ]; then |
| 54 | + echo "changes_found=true" >> $GITHUB_ENV |
| 55 | + else |
| 56 | + echo "changes_found=false" >> $GITHUB_ENV |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Exit if no files to process |
| 60 | + if: env.changes_found != 'true' |
| 61 | + run: exit 0 |
| 62 | + |
| 63 | + - name: Process files from test repo |
| 64 | + run: | |
| 65 | + mkdir -p generated_docs |
| 66 | + HASHES_JSON=$(cat scripts/file_hashes.json) |
| 67 | + PROCESSED_COUNT=0 |
| 68 | + while IFS= read -r FILE_NAME; do |
| 69 | + FILE_URL="https://raw.githubusercontent.com/harshilp24/integration-resources-test/main/Generic%20UQI%20Creation/uqi_configs/$FILE_NAME" |
| 70 | + curl -sSL --max-time 30 "$FILE_URL" -o "input_file.json" |
| 71 | +
|
| 72 | + FILE_SHA=$(grep "$FILE_NAME" latest_files_with_sha.txt | cut -f2) |
| 73 | + HASHES_JSON=$(echo "$HASHES_JSON" | jq --arg file "$FILE_NAME" --arg sha "$FILE_SHA" '.[$file] = $sha') |
| 74 | +
|
| 75 | + SYSTEM_PROMPT=$(cat .github/prompts/extract_prompt.txt) |
| 76 | + USER_CONTENT=$(cat input_file.json) |
| 77 | + PAYLOAD=$(jq -n --arg prompt "System: $SYSTEM_PROMPT\n\nUser: $USER_CONTENT" '{ |
| 78 | + model: "gpt-4.1", |
| 79 | + prompt: $prompt, |
| 80 | + max_tokens: 2000, |
| 81 | + temperature: 0 |
| 82 | + }') |
| 83 | + RESPONSE=$(curl -s https://api.openai.com/v1/completions \ |
| 84 | + -H "Authorization: Bearer ${{ secrets.test_OPENAI_API_KEY }}" \ |
| 85 | + -H "Content-Type: application/json" \ |
| 86 | + -d "$PAYLOAD") |
| 87 | + echo "$RESPONSE" | jq -r '.choices[0].text' > "extracted_info.md" |
| 88 | +
|
| 89 | + SYSTEM_PROMPT=$(cat .github/prompts/generate_prompt.txt) |
| 90 | + EXTRACTED_CONTENT=$(cat extracted_info.md) |
| 91 | + PAYLOAD=$(jq -n --arg prompt "System: $SYSTEM_PROMPT\n\nUser: $EXTRACTED_CONTENT" '{ |
| 92 | + model: "gpt-4.1", |
| 93 | + prompt: $prompt, |
| 94 | + max_tokens: 4000, |
| 95 | + temperature: 0.3 |
| 96 | + }') |
| 97 | + RESPONSE=$(curl -s https://api.openai.com/v1/completions \ |
| 98 | + -H "Authorization: Bearer ${{ secrets.test_OPENAI_API_KEY }}" \ |
| 99 | + -H "Content-Type: application/json" \ |
| 100 | + -d "$PAYLOAD") |
| 101 | + echo "$RESPONSE" | jq -r '.choices[0].text' > "generated_doc.md" |
| 102 | +
|
| 103 | + INTEGRATION=$(echo "$FILE_NAME" | sed 's/_uqi_config\.json//' | tr '[:upper:]' '[:lower:]') |
| 104 | + FINAL_PATH="website/docs/connect-data/reference/${INTEGRATION}.md" |
| 105 | + mkdir -p "$(dirname "$FINAL_PATH")" |
| 106 | + cp "generated_doc.md" "$FINAL_PATH" |
| 107 | + cp "generated_doc.md" "generated_docs/${INTEGRATION}.md" |
| 108 | + echo "$FILE_NAME" >> scripts/processed_files.txt |
| 109 | + PROCESSED_COUNT=$((PROCESSED_COUNT + 1)) |
| 110 | + done < files_to_process.txt |
| 111 | +
|
| 112 | + echo "$HASHES_JSON" > scripts/file_hashes.json |
| 113 | + echo "processed_count=$PROCESSED_COUNT" >> $GITHUB_ENV |
| 114 | + echo "content_generated=true" >> $GITHUB_ENV |
| 115 | +
|
| 116 | + - name: Commit and open PR |
| 117 | + if: env.content_generated == 'true' |
| 118 | + uses: peter-evans/create-pull-request@v5 |
| 119 | + with: |
| 120 | + token: ${{ secrets.test_REPO_ACCESS_TOKEN }} |
| 121 | + title: "test: generate integration docs from test repo" |
| 122 | + commit-message: "test: generated docs from harshilp24/integration-resources-test" |
| 123 | + branch: "test/docs-update-${{ github.run_id }}" |
| 124 | + base: main |
| 125 | + add-paths: | |
| 126 | + website/docs/connect-data/reference/ |
| 127 | + scripts/processed_files.txt |
| 128 | + scripts/file_hashes.json |
| 129 | + body: | |
| 130 | + ✅ Test PR: Generated integration documentation from your test repo. |
| 131 | + Source: [harshilp24/integration-resources-test](https://github.com/harshilp24/integration-resources-test/tree/main/Generic%20UQI%20Creation/uqi_configs) |
0 commit comments