diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index c12cda4..bc02708 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - postgres_version: ["18", "17", "17.6", "16", "16.10"] + postgres_version: ["latest", "18", "17", "17.6", "16", "16.10"] fail-fast: false steps: diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index d0fced7..cf0d11a 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -4,8 +4,12 @@ on: pull_request: types: [opened, synchronize, reopened, ready_for_review] +permissions: + contents: read + pull-requests: read + concurrency: - group: pr-${{ github.event.pull_request.number }} + group: pr-build-${{ github.event.pull_request.number }} cancel-in-progress: true jobs: @@ -14,8 +18,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - postgres_version: ["18", "17", "17.6", "16", "16.10"] - platform: ["linux/amd64", "linux/arm64"] + postgres_version: ["latest", "18", "17", "17.6", "16", "16.10"] + platform: ["linux/amd64"] fail-fast: false steps: @@ -36,11 +40,9 @@ jobs: context: . platforms: ${{ matrix.platform }} push: false - # Do not load into local Docker daemon to avoid platform mismatches on runner; - # we only want to verify that the multi-arch build completes successfully. load: false tags: | - pr-test/${{ github.repository }}:postgres-${{ matrix.postgres_version }}-pr${{ github.event.number }} + pr-test/${{ github.repository }}:postgres-${{ matrix.postgres_version }}-pr${{ github.event.pull_request.number }} build-args: | POSTGRES_VERSION=${{ matrix.postgres_version }} cache-from: type=gha @@ -48,5 +50,25 @@ jobs: - name: Output build metadata run: | + echo "✅ Build completed successfully" echo "Built (multi-arch) for POSTGRES_VERSION=${{ matrix.postgres_version }} PLATFORM=${{ matrix.platform }}" - echo "Tag used: pr-test/${{ github.repository }}:postgres-${{ matrix.postgres_version }}-pr${{ github.event.number }}" + echo "Tag used: pr-test/${{ github.repository }}:postgres-${{ matrix.postgres_version }}-pr${{ github.event.pull_request.number }}" + + # Job resumen que agrupa todos los builds de la matriz + build-complete: + name: All builds passed + runs-on: ubuntu-latest + needs: build + if: always() + + steps: + - name: Check build matrix status + if: needs.build.result != 'success' + run: | + echo "❌ One or more builds failed" + exit 1 + + - name: All builds passed + run: | + echo "✅ All PostgreSQL versions built successfully" + echo "Ready to merge!" diff --git a/Dockerfile b/Dockerfile index 0b8bde6..1ec55fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG POSTGRES_VERSION=17.5 +ARG POSTGRES_VERSION=latest # Builder stage: compile the Rust binary FROM rust:slim AS builder diff --git a/src/common.rs b/src/common.rs index 638ce5c..02dd5b4 100644 --- a/src/common.rs +++ b/src/common.rs @@ -11,3 +11,20 @@ pub fn run(cmd: &str) { panic!("Command failed: {}", cmd); } } + +/// Run a shell command and return its stdout as a trimmed String. +/// Panics if the command fails to execute or returns a non-zero exit code. +pub fn run_output(cmd: &str) -> String { + let output = Command::new("sh") + .arg("-c") + .arg(cmd) + .output() + .expect("Failed to execute command"); + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + panic!("Command failed: {}\nstderr: {}", cmd, stderr); + } + + String::from_utf8_lossy(&output.stdout).trim().to_string() +} diff --git a/src/main.rs b/src/main.rs index cf03fff..af84b20 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::env; -use crate::common::run; +use crate::common::{run, run_output}; mod common; mod extensions; @@ -14,7 +14,25 @@ async fn main() { panic!("Insert PostgreSQL version as argument"); } - let pg_version = &args[1]; + // If user passed "latest", detect the numeric version from the installed postgres binary. + // Otherwise use the provided version string (e.g. "15.3" or "15"). + let mut pg_version = args[1].clone(); + if pg_version.eq_ignore_ascii_case("latest") { + println!("🔎 Detecting PostgreSQL version from the base image (requested: latest)..."); + // Try `postgres --version`. This requires that the base image already provides the postgres binary. + let ver_output = run_output("postgres --version"); + // Typical output: "postgres (PostgreSQL) 15.3" + // We take the last whitespace-separated token as the numeric version. + let numeric_version = ver_output + .split_whitespace() + .last() + .expect("Failed to parse postgres --version output") + .to_string(); + + println!("â„šī¸ Detected PostgreSQL version: {}", numeric_version); + pg_version = numeric_version; + } + let pg_major = pg_version.split(".").next().unwrap(); println!(