@@ -26,89 +26,124 @@ jobs:
2626 uses : actions/checkout@v4
2727 with :
2828 token : ${{ secrets.REPO_ACCESS_TOKEN }} # Use a PAT with access to both repos
29+ fetch-depth : 0 # Fetch all history to check last commit
2930
3031 - name : Ensure scripts directory exists
3132 run : |
3233 mkdir -p scripts
3334 if [ ! -f scripts/processed_files.txt ]; then
3435 touch scripts/processed_files.txt
3536 fi
36- if [ ! -f scripts/file_hashes.json ]; then
37- echo "{}" > scripts/file_hashes.json
37+ if [ ! -f scripts/last_commit_sha.txt ]; then
38+ touch scripts/last_commit_sha.txt
39+ fi
40+
41+ - name : Get last processed commit
42+ id : last_commit
43+ run : |
44+ if [ -s scripts/last_commit_sha.txt ]; then
45+ LAST_COMMIT=$(cat scripts/last_commit_sha.txt)
46+ echo "last_commit=$LAST_COMMIT" >> $GITHUB_ENV
47+ echo "Last processed commit: $LAST_COMMIT"
48+ else
49+ echo "No previous commit found, will process all files"
50+ echo "last_commit=" >> $GITHUB_ENV
3851 fi
3952
4053 - name : Fetch file list and metadata from integration-resources
4154 run : |
55+ # Get the latest commit SHA from integration-resources repo
56+ LATEST_COMMIT=$(curl -s -H "Authorization: Bearer ${{ secrets.REPO_ACCESS_TOKEN }}" \
57+ -H "Accept: application/vnd.github+json" \
58+ https://api.github.com/repos/appsmithorg/integration-resources/commits/main | \
59+ jq -r '.sha' )
60+
61+ echo "Latest commit in integration-resources: $LATEST_COMMIT"
62+ echo "latest_commit=$LATEST_COMMIT" >> $GITHUB_ENV
63+
64+ # Get all files in the repo
4265 curl -s -H "Authorization: Bearer ${{ secrets.REPO_ACCESS_TOKEN }}" \
4366 -H "Accept: application/vnd.github+json" \
4467 https://api.github.com/repos/appsmithorg/integration-resources/contents/Generic%20UQI%20Creation/uqi_configs \
4568 -o response.json
4669
47- # Validate it's an array (not an error message)
70+ # Validate it's an array (not an error message )
4871 if ! jq 'type == "array"' response.json | grep -q true; then
4972 echo "❌ GitHub API did not return a file list. Possible error:"
5073 cat response.json
5174 exit 1
5275 fi
5376
54- # Extract file names and their SHA hashes
55- jq -r '.[] | select(.type=="file") | [.name, .sha] | @tsv' response.json > latest_files_with_sha.txt
77+ # Extract file names
5678 jq -r '.[] | select(.type=="file") | .name' response.json > latest_files.txt
5779
58- - name : Identify new and modified files
80+ - name : Identify changed files since last commit
5981 id : detect_changes
6082 run : |
61- # Load previous file hashes
62- PREV_HASHES=$(cat scripts/file_hashes.json)
63-
6483 # Force check all files if requested
6584 if [ "${{ github.event.inputs.force_check_all }}" == "true" ]; then
6685 echo "🔄 Force checking all files as requested"
6786 cat latest_files.txt > files_to_process.txt
6887 echo "files_found=true" >> $GITHUB_ENV
88+ elif [ -z "${{ env.last_commit }}" ]; then
89+ # No previous commit, process all files
90+ cat latest_files.txt > files_to_process.txt
91+ echo "files_found=true" >> $GITHUB_ENV
6992 else
70- # Find new files (not in processed_files.txt)
71- NEW_FILES=$(comm -23 <(sort latest_files.txt) <(sort scripts/processed_files.txt) || true)
72-
73- # Check for modified files (SHA changed)
74- MODIFIED_FILES=""
75- while IFS=$'\t' read -r FILE_NAME FILE_SHA; do
76- PREV_SHA=$(echo "$PREV_HASHES" | jq -r --arg file "$FILE_NAME" '.[$file] // ""')
77- if [ -n "$PREV_SHA" ] && [ "$PREV_SHA" != "$FILE_SHA" ] && grep -q "^$FILE_NAME$" scripts/processed_files.txt; then
78- echo "🔄 File modified: $FILE_NAME (SHA changed)"
79- MODIFIED_FILES="$MODIFIED_FILES$FILE_NAME"$'\n'
80- fi
81- done < latest_files_with_sha.txt
82-
83- # Combine new and modified files
84- { echo "$NEW_FILES"; echo "$MODIFIED_FILES"; } | grep -v "^$" > files_to_process.txt
85-
86- if [ -s files_to_process.txt ]; then
87- echo "🆕 Found files to process:"
93+ # Get files changed since last commit
94+ echo "🔍 Finding files changed since commit ${{ env.last_commit }}"
95+
96+ # Get list of files changed between commits
97+ CHANGED_FILES=$(curl -s -H "Authorization: Bearer ${{ secrets.REPO_ACCESS_TOKEN }}" \
98+ -H "Accept: application/vnd.github+json" \
99+ "https://api.github.com/repos/appsmithorg/integration-resources/compare/${{ env.last_commit }}...${{ env.latest_commit }}" | \
100+ jq -r '.files[] | select(.filename | startswith("Generic UQI Creation/uqi_configs/" )) | .filename | split("/") | last' | \
101+ grep -v "^$")
102+
103+ if [ -n "$CHANGED_FILES" ]; then
104+ echo "$CHANGED_FILES" > files_to_process.txt
105+ echo "🆕 Found files changed since last commit:"
88106 cat files_to_process.txt
89107 echo "files_found=true" >> $GITHUB_ENV
90108 else
91- echo "✅ No new or modified files to process ."
109+ echo "✅ No files changed since last commit ."
92110 echo "files_found=false" >> $GITHUB_ENV
93111 fi
94112 fi
95113
114+ # Check for existing documentation
115+ if [ "${{ env.files_found }}" == "true" ]; then
116+ echo "🔍 Checking for existing documentation..."
117+ FILTERED_FILES=""
118+ while IFS= read -r FILE_NAME; do
119+ INTEGRATION=$(echo "$FILE_NAME" | sed 's/_uqi_config\.json//' | tr '[:upper:]' '[:lower:]')
120+ DOC_PATH="website/docs/connect-data/reference/${INTEGRATION}.md"
121+
122+ if [ -f "$DOC_PATH" ]; then
123+ echo "🔄 Documentation exists for $INTEGRATION, will update"
124+ fi
125+
126+ FILTERED_FILES="${FILTERED_FILES}${FILE_NAME}"$'\n'
127+ done < files_to_process.txt
128+
129+ echo "$FILTERED_FILES" | grep -v "^$" > files_to_process.txt
130+ fi
131+
96132 # Count files to process
97133 FILE_COUNT=$(wc -l < files_to_process.txt || echo "0")
98134 echo "file_count=$FILE_COUNT" >> $GITHUB_ENV
99135
100136 - name : Exit if no files to process
101- if : env.files_found != 'true'
102- run : exit 0
137+ if : env.files_found != 'true' || env.file_count == '0'
138+ run : |
139+ echo "No files to process. Exiting."
140+ exit 0
103141
104142 - name : Process files
105143 run : |
106144 # Create a directory for generated docs
107145 mkdir -p generated_docs
108146
109- # Update file hashes JSON for tracking changes
110- HASHES_JSON=$(cat scripts/file_hashes.json)
111-
112147 # Process each file
113148 while IFS= read -r FILE_NAME; do
114149 echo "⏳ Processing: $FILE_NAME"
@@ -117,11 +152,7 @@ jobs:
117152 FILE_URL="https://raw.githubusercontent.com/appsmithorg/integration-resources/main/Generic%20UQI%20Creation/uqi_configs/$FILE_NAME"
118153 curl -sSL "$FILE_URL" -o "input_file.json"
119154
120- # Update hash in our tracking JSON
121- FILE_SHA=$(grep "$FILE_NAME" latest_files_with_sha.txt | cut -f2)
122- HASHES_JSON=$(echo "$HASHES_JSON" | jq --arg file "$FILE_NAME" --arg sha "$FILE_SHA" '.[$file] = $sha')
123-
124- # Process with OpenAI API (using completion API, not chat)
155+ # Process with OpenAI API (using completion API, not chat )
125156 echo "🧠 Extracting information with OpenAI API..."
126157
127158 # Extract information using OpenAI API
@@ -144,7 +175,7 @@ jobs:
144175 # Generate documentation
145176 echo "📝 Generating documentation..."
146177
147- SYSTEM_PROMPT=$(cat .github/prompts/generate_prompt.txt || echo "Generate comprehensive markdown documentation based on the extracted information.")
178+ SYSTEM_PROMPT=$(cat .github/prompts/generate_prompt.txt || echo "Generate comprehensive markdown documentation based on the extracted information." )
148179 EXTRACTED_CONTENT=$(cat extracted_info.md)
149180
150181 # Use OpenAI Completion API again
@@ -161,7 +192,7 @@ jobs:
161192 -d "$PAYLOAD" | jq -r '.choices[0].text' > "generated_doc.md"
162193
163194 # Prepare final path
164- INTEGRATION=$(echo "$FILE_NAME" | sed 's/_uqi_config\.json//' | tr '[:upper:]' '[:lower:]')
195+ INTEGRATION=$(echo "$FILE_NAME" | sed 's/_uqi_config\.json//' | tr '[:upper:]' '[:lower:]' )
165196 FINAL_PATH="website/docs/connect-data/reference/${INTEGRATION}.md"
166197 mkdir -p "$(dirname "$FINAL_PATH")"
167198
@@ -179,11 +210,11 @@ jobs:
179210 echo "✅ Completed processing: $FILE_NAME"
180211 done < files_to_process.txt
181212
182- # Save updated hashes
183- echo "$HASHES_JSON " > scripts/file_hashes.json
213+ # Save the latest commit SHA for next run
214+ echo "${{ env.latest_commit }} " > scripts/last_commit_sha.txt
184215
185216 - name : Commit and open PR
186- if : env.files_found == 'true'
217+ if : env.files_found == 'true' && env.file_count != '0'
187218 uses : peter-evans/create-pull-request@v5
188219 with :
189220 token : ${{ secrets.REPO_ACCESS_TOKEN }}
@@ -194,8 +225,8 @@ jobs:
194225 add-paths : |
195226 website/docs/connect-data/reference/
196227 scripts/processed_files.txt
197- scripts/file_hashes.json
228+ scripts/last_commit_sha.txt
198229 body : |
199230 This PR adds or updates integration reference documentation for **${{ env.file_count }}** integrations.
200231
201- Generated from the latest configuration files in the [integration-resources repository](https://github.com/appsmithorg/integration-resources/tree/main/Generic%20UQI%20Creation/uqi_configs).
232+ Generated from files changed since commit ${{ env.last_commit || 'initial' }} in the [integration-resources repository](https://github.com/appsmithorg/integration-resources/tree/main/Generic%20UQI%20Creation/uqi_configs ).
0 commit comments