Skip to content

Fix PostgreSQL test 2: Check for postgres binary in correct location … #2

Fix PostgreSQL test 2: Check for postgres binary in correct location …

Fix PostgreSQL test 2: Check for postgres binary in correct location … #2

Workflow file for this run

name: Test PostgreSQL on Arm64
on:
workflow_call:
workflow_dispatch:
push:
branches:
- main
- smoke_tests
paths:
- 'content/opensource_packages/postgres.md'
- '.github/workflows/test-postgres.yml'
jobs:
test-postgres:
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set test metadata
id: metadata
run: |
echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
echo "package_slug=postgres" >> $GITHUB_OUTPUT
echo "dashboard_link=/opensource_packages/postgres" >> $GITHUB_OUTPUT
# ============================================================
# Install PostgreSQL
# ============================================================
- name: Install PostgreSQL
id: install
run: |
echo "Installing PostgreSQL..."
# Install PostgreSQL from Ubuntu repository
sudo apt-get update
sudo apt-get install -y postgresql postgresql-contrib
# Verify installation
if command -v psql &> /dev/null; then
echo "PostgreSQL installed successfully"
echo "install_status=success" >> $GITHUB_OUTPUT
else
echo "PostgreSQL installation failed"
echo "install_status=failed" >> $GITHUB_OUTPUT
exit 1
fi
# ============================================================
# Detect version
# ============================================================
- name: Detect PostgreSQL version
id: version
run: |
VERSION=$(psql --version | grep -oP '(?<=psql \(PostgreSQL\) )[0-9.]+')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected PostgreSQL version: $VERSION"
# ============================================================
# Run tests
# ============================================================
- name: Test 1 - Check psql client binary exists
id: test1
run: |
START_TIME=$(date +%s)
if command -v psql &> /dev/null; then
echo "✓ psql command found"
which psql
echo "status=passed" >> $GITHUB_OUTPUT
else
echo "✗ psql command not found"
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
fi
END_TIME=$(date +%s)
echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT
- name: Test 2 - Check postgres server binary exists
id: test2
run: |
START_TIME=$(date +%s)
# PostgreSQL server binary is in /usr/lib/postgresql/*/bin/ when installed via APT
if [ -f /usr/lib/postgresql/*/bin/postgres ]; then
echo "✓ postgres server binary found"
ls -la /usr/lib/postgresql/*/bin/postgres
echo "status=passed" >> $GITHUB_OUTPUT
else
echo "✗ postgres server binary not found"
echo "Searching for postgres binary:"
find /usr -name postgres -type f 2>/dev/null || echo "No postgres binary found"
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
fi
END_TIME=$(date +%s)
echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT
- name: Test 3 - Check PostgreSQL version command
id: test3
run: |
START_TIME=$(date +%s)
if psql --version | grep -q "PostgreSQL"; then
echo "✓ PostgreSQL version check passed"
psql --version
echo "status=passed" >> $GITHUB_OUTPUT
else
echo "✗ PostgreSQL version check failed"
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
fi
END_TIME=$(date +%s)
echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT
- name: Test 4 - Start PostgreSQL server
id: test4
run: |
START_TIME=$(date +%s)
# Start PostgreSQL service
sudo systemctl start postgresql
# Wait for PostgreSQL to be ready (with retries)
echo "Waiting for PostgreSQL to be ready..."
MAX_RETRIES=30
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if sudo -u postgres pg_isready -q; then
echo "✓ PostgreSQL server is ready"
break
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
echo "Waiting for PostgreSQL... ($RETRY_COUNT/$MAX_RETRIES)"
sleep 1
done
# Final check
if sudo systemctl is-active postgresql && sudo -u postgres pg_isready -q; then
echo "✓ PostgreSQL server started successfully and is accepting connections"
echo "status=passed" >> $GITHUB_OUTPUT
else
echo "✗ PostgreSQL server failed to start or is not accepting connections"
sudo systemctl status postgresql || true
echo "PostgreSQL log:"
sudo tail -20 /var/log/postgresql/postgresql-*.log 2>/dev/null || echo "Could not read PostgreSQL log"
echo "status=failed" >> $GITHUB_OUTPUT
exit 1
fi
END_TIME=$(date +%s)
echo "duration=$((END_TIME - START_TIME))" >> $GITHUB_OUTPUT
# ============================================================
# Calculate summary
# ============================================================
- name: Calculate test summary
if: always()
id: summary
run: |
PASSED=0
FAILED=0
TOTAL_DURATION=0
# Test 1
if [ "${{ steps.test1.outputs.status }}" == "passed" ]; then
PASSED=$((PASSED + 1))
else
FAILED=$((FAILED + 1))
fi
TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test1.outputs.duration || 0 }}))
# Test 2
if [ "${{ steps.test2.outputs.status }}" == "passed" ]; then
PASSED=$((PASSED + 1))
else
FAILED=$((FAILED + 1))
fi
TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test2.outputs.duration || 0 }}))
# Test 3
if [ "${{ steps.test3.outputs.status }}" == "passed" ]; then
PASSED=$((PASSED + 1))
else
FAILED=$((FAILED + 1))
fi
TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test3.outputs.duration || 0 }}))
# Test 4
if [ "${{ steps.test4.outputs.status }}" == "passed" ]; then
PASSED=$((PASSED + 1))
else
FAILED=$((FAILED + 1))
fi
TOTAL_DURATION=$((TOTAL_DURATION + ${{ steps.test4.outputs.duration || 0 }}))
echo "passed=$PASSED" >> $GITHUB_OUTPUT
echo "failed=$FAILED" >> $GITHUB_OUTPUT
echo "duration=$TOTAL_DURATION" >> $GITHUB_OUTPUT
if [ $FAILED -eq 0 ]; then
echo "overall_status=success" >> $GITHUB_OUTPUT
echo "badge_status=passing" >> $GITHUB_OUTPUT
else
echo "overall_status=failure" >> $GITHUB_OUTPUT
echo "badge_status=failing" >> $GITHUB_OUTPUT
fi
# ============================================================
# Generate JSON with PostgreSQL metadata
# ============================================================
- name: Generate test results JSON
if: always()
run: |
mkdir -p test-results
cat > test-results/postgres.json << EOF
{
"schema_version": "1.0",
"package": {
"name": "PostgreSQL",
"version": "${{ steps.version.outputs.version }}",
"language": "c",
"category": "Database"
},
"run": {
"id": "${{ github.run_id }}",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"timestamp": "${{ steps.metadata.outputs.timestamp }}",
"status": "${{ steps.summary.outputs.overall_status }}",
"runner": {
"os": "ubuntu-24.04",
"arch": "arm64"
}
},
"tests": {
"passed": ${{ steps.summary.outputs.passed }},
"failed": ${{ steps.summary.outputs.failed }},
"skipped": 0,
"duration_seconds": ${{ steps.summary.outputs.duration }},
"details": [
{
"name": "Check psql client binary exists",
"status": "${{ steps.test1.outputs.status }}",
"duration_seconds": ${{ steps.test1.outputs.duration || 0 }}
},
{
"name": "Check postgres server binary exists",
"status": "${{ steps.test2.outputs.status }}",
"duration_seconds": ${{ steps.test2.outputs.duration || 0 }}
},
{
"name": "Check PostgreSQL version command",
"status": "${{ steps.test3.outputs.status }}",
"duration_seconds": ${{ steps.test3.outputs.duration || 0 }}
},
{
"name": "Start PostgreSQL server",
"status": "${{ steps.test4.outputs.status }}",
"duration_seconds": ${{ steps.test4.outputs.duration || 0 }}
}
]
},
"metadata": {
"dashboard_link": "${{ steps.metadata.outputs.dashboard_link }}",
"badge_status": "${{ steps.summary.outputs.badge_status }}"
}
}
EOF
echo "Generated test results:"
cat test-results/postgres.json
# ============================================================
# STANDARD STEPS - Commit results to repository
# ============================================================
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: postgres-test-results
path: test-results/postgres.json
retention-days: 90
- name: Commit test results to repository
if: always() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/smoke_tests')
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
mkdir -p data/test-results
cp test-results/postgres.json data/test-results/postgres.json
git add data/test-results/postgres.json
if ! git diff --staged --quiet; then
git commit -m "Update postgres test results [skip ci]"
# Retry logic for push
MAX_RETRIES=5
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if git push origin ${{ github.ref_name }}; then
echo "Successfully pushed test results"
break
else
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
echo "Push failed, attempt $RETRY_COUNT of $MAX_RETRIES. Retrying in 5 seconds..."
sleep 5
git pull --rebase origin ${{ github.ref_name }}
else
echo "Failed to push after $MAX_RETRIES attempts"
exit 1
fi
fi
done
else
echo "No changes to commit"
fi