@@ -73,10 +73,10 @@ jobs:
7373 jq -R -s -c 'split("\n") | map(select(length > 0)) | unique')
7474 fi
7575 elif [ "${{ github.event_name }}" == "pull_request" ]; then
76- # For PRs, detect which versions were added or modified using GitHub API
77- echo "Detecting versions changed in PR #${{ github.event.pull_request.number }}"
76+ # For PRs, detect which versions were added or modified using smart detection
77+ echo "=== Smart Version Detection for PR #${{ github.event.pull_request.number }} === "
7878
79- # Get the list of changed files first
79+ # Get the list of changed files
8080 echo "Fetching changed files from PR..."
8181 CHANGED_FILES=$(curl -s -H "Authorization: token ${{ github.token }}" \
8282 -H "Accept: application/vnd.github.v3+json" \
@@ -86,46 +86,61 @@ jobs:
8686 echo "Changed files in PR:"
8787 echo "$CHANGED_FILES"
8888
89- # Check if releases.properties was changed
90- if echo "$CHANGED_FILES" | grep -q "^releases.properties$"; then
91- echo "releases.properties was modified in this PR"
92-
93- # Get the diff from GitHub API using curl
94- PATCH=$(curl -s -H "Authorization: token ${{ github.token }}" \
95- -H "Accept: application/vnd.github.v3+json" \
96- "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" | \
97- jq -r '.[] | select(.filename == "releases.properties") | .patch')
89+ # Primary Method: Extract version numbers from changed files in /bin directory
90+ echo ""
91+ echo "Primary Method: Checking /bin directory for version changes..."
92+ BIN_VERSIONS=$(echo "$CHANGED_FILES" | \
93+ grep "^bin/postgresql[0-9]" | \
94+ sed -E 's|^bin/postgresql([0-9]+\.[0-9]+)/.*|\1|' | \
95+ sort -u)
96+
97+ if [ -n "$BIN_VERSIONS" ]; then
98+ echo "✅ Versions detected from /bin directory:"
99+ echo "$BIN_VERSIONS"
100+ VERSIONS=$(echo "$BIN_VERSIONS" | jq -R -s -c 'split("\n") | map(select(length > 0)) | unique')
101+ else
102+ echo "❌ No versions found in /bin directory changes"
98103
99- echo "Analyzing diff for added/modified versions..."
104+ # Fallback Method: Extract version numbers from PR title
105+ echo ""
106+ echo "Fallback Method: Checking PR title for version numbers..."
107+ PR_TITLE="${{ github.event.pull_request.title }}"
108+ echo "PR Title: $PR_TITLE"
100109
101- # Extract ALL added lines (lines starting with +) that contain version numbers
102- # Test ALL versions added in the PR (including RC/beta/alpha)
103- CHANGED_VERSIONS=$(echo "$PATCH" | \
104- grep "^+" | \
105- grep -v "^+++" | \
106- grep -E "^\+[0-9]+\.[0-9]+" | \
107- sed 's/^+//' | \
108- cut -d'=' -f1 | \
109- tr -d ' ')
110+ # Extract version patterns like 17.5, 16.11, etc. from PR title
111+ TITLE_VERSIONS=$(echo "$PR_TITLE" | \
112+ grep -oE '[0-9]+\.[0-9]+' | \
113+ sort -u)
110114
111- if [ -z "$CHANGED_VERSIONS" ]; then
112- echo "No new versions found in releases.properties changes"
113- echo "Testing latest 5 versions as fallback"
114- VERSIONS=$(grep -E "^[0-9]+\.[0-9]+" releases.properties | \
115- cut -d'=' -f1 | \
116- tr -d ' ' | \
117- sort -V -r | \
118- head -5 | \
119- jq -R -s -c 'split("\n") | map(select(length > 0)) | unique')
115+ if [ -n "$TITLE_VERSIONS" ]; then
116+ echo "✅ Versions detected from PR title:"
117+ echo "$TITLE_VERSIONS"
118+
119+ # Verify these versions exist in releases.properties
120+ VALID_VERSIONS=""
121+ INVALID_VERSIONS=""
122+ for version in $TITLE_VERSIONS; do
123+ if grep -q "^${version}\s*=" releases.properties; then
124+ echo " ✓ Version $version found in releases.properties"
125+ VALID_VERSIONS="${VALID_VERSIONS}${version}"$'\n'
126+ else
127+ echo " ✗ Version $version NOT found in releases.properties"
128+ INVALID_VERSIONS="${INVALID_VERSIONS}${version}"$'\n'
129+ fi
130+ done
131+
132+ if [ -n "$VALID_VERSIONS" ]; then
133+ VERSIONS=$(echo "$VALID_VERSIONS" | jq -R -s -c 'split("\n") | map(select(length > 0)) | unique')
134+ else
135+ echo "❌ No valid versions found in PR title"
136+ echo "⏭️ Skipping tests - no valid versions to test"
137+ VERSIONS="[]"
138+ fi
120139 else
121- echo "Versions detected in PR: "
122- echo "$CHANGED_VERSIONS "
123- VERSIONS=$(echo "$CHANGED_VERSIONS" | jq -R -s -c 'split("\n") | map(select(length > 0)) | unique')
140+ echo "❌ No version numbers found in PR title "
141+ echo "⏭️ Skipping tests - no versions to test "
142+ VERSIONS="[]"
124143 fi
125- else
126- echo "releases.properties was NOT modified in this PR"
127- echo "Skipping tests - no versions to test"
128- VERSIONS="[]"
129144 fi
130145 else
131146 # For other events, test latest 5 versions
@@ -138,6 +153,8 @@ jobs:
138153 jq -R -s -c 'split("\n") | map(select(length > 0)) | unique')
139154 fi
140155
156+ echo ""
157+ echo "=== Final Version Selection ==="
141158 echo "versions=$VERSIONS" >> $GITHUB_OUTPUT
142159 echo "Versions to test: $VERSIONS"
143160
0 commit comments