Skip to content

Commit ef04c29

Browse files
committed
Enhance PR version detection with smart multi-tier system and comprehensive documentation
1 parent af140d5 commit ef04c29

File tree

2 files changed

+112
-47
lines changed

2 files changed

+112
-47
lines changed

.github/workflows/postgresql-test.yml

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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

docs/CI-CD-TESTING.md

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,69 @@ The PostgreSQL testing workflow is triggered automatically on:
1616
The workflow intelligently determines which versions to test based on the context:
1717

1818
### Pull Request Testing
19-
- **Smart Detection**: Automatically detects which PostgreSQL versions were added or modified in the PR
20-
- **Targeted Testing**: Only tests the versions that changed in `releases.properties`
21-
- **Efficiency**: Reduces CI runtime by testing only relevant versions
22-
- **Fallback**: If no version changes detected, tests the latest 5 stable versions
23-
- **Exclusions**: Automatically excludes RC (Release Candidate), beta, and alpha versions
19+
20+
**Smart Detection**: Automatically detects which PostgreSQL versions are included in the PR using a three-tier detection system:
21+
22+
#### Primary Method: /bin Directory Detection
23+
- Extracts version numbers from changed files in the `/bin` directory
24+
- Pattern: `bin/postgresql{VERSION}/` (e.g., `bin/postgresql17.5/`, `bin/postgresql16.11/`)
25+
- Most reliable method as it directly detects new version directories
26+
- **Example**: If PR adds files to `bin/postgresql17.5/`, version `17.5` is tested
27+
28+
#### Fallback Method: PR Title Detection
29+
- If no versions found in `/bin`, extracts version numbers from the PR title
30+
- Pattern: Matches version numbers like `17.5`, `16.11`, `18.1`, etc.
31+
- Validates that detected versions exist in `releases.properties`
32+
- **Example**: PR title "Add PostgreSQL 17.5 and 16.11" → tests versions `17.5` and `16.11`
33+
- If no valid versions found in title, tests are skipped
34+
35+
**Efficiency**: Reduces CI runtime by testing only relevant versions instead of all versions
2436

2537
### Manual Testing
2638
- Tests a specific version provided as input parameter
2739
- Useful for re-testing or validating specific versions
40+
- Can also test latest 5 versions on demand
41+
42+
### How It Works
43+
44+
The typical workflow for adding new PostgreSQL versions:
45+
46+
1. **Pre-release Creation**: New versions are added to a pre-release (tagged with date, e.g., "2025.01.23")
47+
2. **Version Directories**: Version directories are created in `/bin` (e.g., `bin/postgresql17.5/`, `bin/postgresql16.11/`)
48+
3. **Properties Update**: The `releases.properties` file is updated with download URLs
49+
4. **PR Creation**: A PR is created from a release branch (e.g., "January") to `main`
50+
5. **Smart Detection**: This workflow detects changed files in `/bin` and extracts version numbers from directory names
51+
6. **Targeted Testing**: Tests are run only against the detected version(s)
2852

2953
### Example Scenarios
30-
- **Add PostgreSQL 17.5**: Only version 17.5 is tested
31-
- **Add versions 16.9 and 17.5**: Both versions are tested
32-
- **Modify existing version URL**: That specific version is tested
33-
- **Non-version changes**: Latest 5 stable versions tested as fallback
54+
55+
#### Scenario 1: New Version in /bin
56+
- **PR Changes**: Adds `bin/postgresql17.5/` directory with files
57+
- **Detection**: Primary method detects version `17.5` from `/bin` path
58+
- **Result**: Only version `17.5` is tested ✅
59+
60+
#### Scenario 2: Multiple Versions in /bin
61+
- **PR Changes**: Adds `bin/postgresql17.5/` and `bin/postgresql16.11/`
62+
- **Detection**: Primary method detects versions `17.5` and `16.11`
63+
- **Result**: Both versions are tested ✅
64+
65+
#### Scenario 3: Version in PR Title
66+
- **PR Changes**: Documentation updates only
67+
- **PR Title**: "Update docs for PostgreSQL 17.5"
68+
- **Detection**: Fallback method extracts `17.5` from title
69+
- **Result**: Version `17.5` is tested (if it exists in `releases.properties`) ✅
70+
71+
#### Scenario 4: No Version Detection
72+
- **PR Changes**: General code improvements
73+
- **PR Title**: "Refactor build scripts"
74+
- **Detection**: No versions found in `/bin` or title
75+
- **Result**: Tests are skipped - no versions to test ⏭️
76+
77+
#### Scenario 5: Invalid Version in Title
78+
- **PR Changes**: Documentation updates
79+
- **PR Title**: "Add PostgreSQL 99.99 docs"
80+
- **Detection**: Version `99.99` extracted but not found in `releases.properties`
81+
- **Result**: Tests are skipped - no valid versions to test ⏭️
3482

3583
## Test Phases
3684

0 commit comments

Comments
 (0)