From de24fcd6fe9140ea5b65ac51187bf3dcea464b6a Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Mon, 14 Sep 2026 16:36:55 +0200 Subject: [PATCH] fix: report release tag or commit as extension version - arrow, flow_php and pg_query resolve version from env, release archive or git describe - untagged builds report semver build metadata, e.g. 0.43.0+107.gf998a45d0 - PIE CI jobs install from git archive and assert phpversion() --- .github/workflows/job-arrow-extension.yml | 17 +++- .github/workflows/job-flow-php-extension.yml | 17 +++- .github/workflows/job-pg-query-extension.yml | 17 +++- .nix/pkgs/php-pg-query-ext/package.nix | 2 + documentation/upgrading.md | 6 +- src/extension/arrow-ext/.git_archival.txt | 1 + src/extension/arrow-ext/.gitattributes | 3 + src/extension/arrow-ext/Cargo.lock | 2 +- src/extension/arrow-ext/Cargo.toml | 1 - src/extension/arrow-ext/build.rs | 87 ++++++++++++++++--- src/extension/arrow-ext/src/lib.rs | 1 + .../tests/phpt/038_extension_version.phpt | 8 ++ src/extension/flow-php-ext/.git_archival.txt | 1 + src/extension/flow-php-ext/.gitattributes | 3 + src/extension/flow-php-ext/Cargo.lock | 2 +- src/extension/flow-php-ext/Cargo.toml | 1 - src/extension/flow-php-ext/build.rs | 84 +++++++++++++++--- src/extension/flow-php-ext/src/lib.rs | 1 + ...xtension_version_is_release_or_commit.phpt | 10 +++ src/extension/pg-query-ext/.git_archival.txt | 1 + src/extension/pg-query-ext/.gitattributes | 3 + src/extension/pg-query-ext/ext/config.m4 | 20 +++++ src/extension/pg-query-ext/ext/php_pg_query.h | 5 +- .../tests/phpt/012_extension_version.phpt | 10 +++ 24 files changed, 262 insertions(+), 41 deletions(-) create mode 100644 src/extension/arrow-ext/.git_archival.txt create mode 100644 src/extension/arrow-ext/tests/phpt/038_extension_version.phpt create mode 100644 src/extension/flow-php-ext/.git_archival.txt create mode 100644 src/extension/flow-php-ext/tests/phpt/036_extension_version_is_release_or_commit.phpt create mode 100644 src/extension/pg-query-ext/.git_archival.txt create mode 100644 src/extension/pg-query-ext/tests/phpt/012_extension_version.phpt diff --git a/.github/workflows/job-arrow-extension.yml b/.github/workflows/job-arrow-extension.yml index 80773d1a8e..2ca7777052 100644 --- a/.github/workflows/job-arrow-extension.yml +++ b/.github/workflows/job-arrow-extension.yml @@ -20,6 +20,8 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + # git describe needs history and tags to resolve the extension version + fetch-depth: 0 - name: Setup PHP Environment uses: ./.github/actions/setup-php-env @@ -127,6 +129,8 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + # git describe needs history and tags to resolve the extension version + fetch-depth: 0 - name: Setup PHP Environment uses: ./.github/actions/setup-php-env @@ -179,17 +183,26 @@ jobs: pie --version - name: Prepare local package for PIE installation - working-directory: src/extension/arrow-ext run: | + # git archive applies export-subst like GitHub release archives, so the build resolves its version from .git_archival.txt + git archive HEAD src/extension/arrow-ext | tar -x -C "$RUNNER_TEMP" + cd "$RUNNER_TEMP/src/extension/arrow-ext" jq '. + {"version": "0.0.9999"}' composer.json > composer.tmp.json mv composer.tmp.json composer.json - name: Install extension via PIE (from local) run: | sudo pie repository:remove packagist.org - sudo pie repository:add path ${{ github.workspace }}/src/extension/arrow-ext + sudo pie repository:add path "$RUNNER_TEMP/src/extension/arrow-ext" sudo env "PATH=$PATH" "LIBCLANG_PATH=$LIBCLANG_PATH" ${CLANG_PATH:+"CLANG_PATH=$CLANG_PATH"} "RUSTUP_TOOLCHAIN=$RUSTUP_TOOLCHAIN" "CARGO_HOME=$CARGO_HOME" "RUSTUP_HOME=$RUSTUP_HOME" pie install flow-php/arrow-ext:0.0.9999@dev - name: Verify extension is loaded run: | php -m | grep arrow + + - name: Verify extension version + run: | + expected="$(git describe --tags --match '[0-9]*' | sed -E 's/-([0-9]+)-(g[0-9a-f]+)$/+\1.\2/')" + actual="$(php -r 'echo phpversion("arrow");')" + echo "expected: $expected, actual: $actual" + test "$actual" = "$expected" diff --git a/.github/workflows/job-flow-php-extension.yml b/.github/workflows/job-flow-php-extension.yml index 3e3d16cb02..ff650eb73f 100644 --- a/.github/workflows/job-flow-php-extension.yml +++ b/.github/workflows/job-flow-php-extension.yml @@ -20,6 +20,8 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + # git describe needs history and tags to resolve the extension version + fetch-depth: 0 - name: Setup PHP Environment uses: ./.github/actions/setup-php-env @@ -124,6 +126,8 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + # git describe needs history and tags to resolve the extension version + fetch-depth: 0 - name: Setup PHP Environment uses: ./.github/actions/setup-php-env @@ -176,15 +180,17 @@ jobs: pie --version - name: Prepare local package for PIE installation - working-directory: src/extension/flow-php-ext run: | + # git archive applies export-subst like GitHub release archives, so the build resolves its version from .git_archival.txt + git archive HEAD src/extension/flow-php-ext | tar -x -C "$RUNNER_TEMP" + cd "$RUNNER_TEMP/src/extension/flow-php-ext" jq '. + {"version": "0.0.9999"}' composer.json > composer.tmp.json mv composer.tmp.json composer.json - name: Install extension via PIE (from local) run: | sudo pie repository:remove packagist.org - sudo pie repository:add path ${{ github.workspace }}/src/extension/flow-php-ext + sudo pie repository:add path "$RUNNER_TEMP/src/extension/flow-php-ext" sudo env "PATH=$PATH" "LIBCLANG_PATH=$LIBCLANG_PATH" ${CLANG_PATH:+"CLANG_PATH=$CLANG_PATH"} "RUSTUP_TOOLCHAIN=$RUSTUP_TOOLCHAIN" "CARGO_HOME=$CARGO_HOME" "RUSTUP_HOME=$RUSTUP_HOME" pie install flow-php/flow-php-ext:0.0.9999@dev - name: Enable extension @@ -194,3 +200,10 @@ jobs: - name: Verify extension is loaded run: | php -m | grep flow_php + + - name: Verify extension version + run: | + expected="$(git describe --tags --match '[0-9]*' | sed -E 's/-([0-9]+)-(g[0-9a-f]+)$/+\1.\2/')" + actual="$(php -r 'echo phpversion("flow_php");')" + echo "expected: $expected, actual: $actual" + test "$actual" = "$expected" diff --git a/.github/workflows/job-pg-query-extension.yml b/.github/workflows/job-pg-query-extension.yml index 022be32327..355f4d2208 100644 --- a/.github/workflows/job-pg-query-extension.yml +++ b/.github/workflows/job-pg-query-extension.yml @@ -17,6 +17,8 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + # git describe needs history and tags to resolve the extension version + fetch-depth: 0 - name: Setup PHP Environment uses: ./.github/actions/setup-php-env @@ -68,6 +70,8 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + # git describe needs history and tags to resolve the extension version + fetch-depth: 0 - name: Setup PHP Environment uses: ./.github/actions/setup-php-env @@ -95,17 +99,26 @@ jobs: pie --version - name: Prepare local package for PIE installation - working-directory: src/extension/pg-query-ext run: | + # git archive applies export-subst like GitHub release archives, so the build resolves its version from .git_archival.txt + git archive HEAD src/extension/pg-query-ext | tar -x -C "$RUNNER_TEMP" + cd "$RUNNER_TEMP/src/extension/pg-query-ext" jq '. + {"version": "0.0.9999"}' composer.json > composer.tmp.json mv composer.tmp.json composer.json - name: Install extension via PIE (from local) run: | sudo pie repository:remove packagist.org - sudo pie repository:add path ${{ github.workspace }}/src/extension/pg-query-ext + sudo pie repository:add path "$RUNNER_TEMP/src/extension/pg-query-ext" sudo pie install flow-php/pg-query-ext:0.0.9999@dev - name: Verify extension is loaded run: | php -m | grep pg_query + + - name: Verify extension version + run: | + expected="$(git describe --tags --match '[0-9]*' | sed -E 's/-([0-9]+)-(g[0-9a-f]+)$/+\1.\2/')" + actual="$(php -r 'echo phpversion("pg_query");')" + echo "expected: $expected, actual: $actual" + test "$actual" = "$expected" diff --git a/.nix/pkgs/php-pg-query-ext/package.nix b/.nix/pkgs/php-pg-query-ext/package.nix index c6a1381d98..b01752cb89 100644 --- a/.nix/pkgs/php-pg-query-ext/package.nix +++ b/.nix/pkgs/php-pg-query-ext/package.nix @@ -66,6 +66,8 @@ php.buildPecl { buildInputs = [ protobufc libpg_query ]; + env.PG_QUERY_EXT_VERSION = "dev"; + configureFlags = [ "--with-pg-query=${libpg_query}" ]; diff --git a/documentation/upgrading.md b/documentation/upgrading.md index 1b29ec2d71..7dd212e559 100644 --- a/documentation/upgrading.md +++ b/documentation/upgrading.md @@ -1428,9 +1428,9 @@ Registering the commands in your own console application: drop the `setName()` / ### 98) `flow-php/flow-php-ext` - the `flow_php` extension must be reinstalled -| Before | After | -|----------------------------|----------------------------------------| -| `flow_php` extension 0.1.0 | 0.3.0, required by this `flow-php/etl` | +| Before | After | +|----------------------------|---------------------------------------------| +| `flow_php` extension 0.1.0 | same version as this `flow-php/etl` release | Reinstall it with the new release: `pie install flow-php/flow-php-ext`. diff --git a/src/extension/arrow-ext/.git_archival.txt b/src/extension/arrow-ext/.git_archival.txt new file mode 100644 index 0000000000..88fee028ea --- /dev/null +++ b/src/extension/arrow-ext/.git_archival.txt @@ -0,0 +1 @@ +describe-name: $Format:%(describe:tags=true,match=[0-9]*)$ diff --git a/src/extension/arrow-ext/.gitattributes b/src/extension/arrow-ext/.gitattributes index 1b17167edd..b83ec3200b 100644 --- a/src/extension/arrow-ext/.gitattributes +++ b/src/extension/arrow-ext/.gitattributes @@ -6,6 +6,9 @@ /.gitattributes export-ignore /.gitignore export-ignore +# Expand the version placeholder in release archives +/.git_archival.txt export-subst + # Ensure consistent line endings *.php text eol=lf *.rs text eol=lf diff --git a/src/extension/arrow-ext/Cargo.lock b/src/extension/arrow-ext/Cargo.lock index 3086ed4c43..11dbfb0a47 100644 --- a/src/extension/arrow-ext/Cargo.lock +++ b/src/extension/arrow-ext/Cargo.lock @@ -74,7 +74,7 @@ checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "arrow" -version = "0.1.0" +version = "0.0.0" dependencies = [ "arrow-array", "arrow-buffer", diff --git a/src/extension/arrow-ext/Cargo.toml b/src/extension/arrow-ext/Cargo.toml index 4692d6af47..39bcf58210 100644 --- a/src/extension/arrow-ext/Cargo.toml +++ b/src/extension/arrow-ext/Cargo.toml @@ -1,6 +1,5 @@ [package] name = "arrow" -version = "0.1.0" edition = "2021" publish = false diff --git a/src/extension/arrow-ext/build.rs b/src/extension/arrow-ext/build.rs index 20174665f5..0f9cd4c10d 100644 --- a/src/extension/arrow-ext/build.rs +++ b/src/extension/arrow-ext/build.rs @@ -1,20 +1,11 @@ +use std::path::Path; +use std::process::Command; + fn main() { - let version = std::env::var("ARROW_VERSION") - .ok() - .filter(|s| !s.is_empty()) - .or_else(|| { - std::process::Command::new("git") - .args(["describe", "--tags", "--always"]) - .output() - .ok() - .filter(|o| o.status.success()) - .and_then(|o| String::from_utf8(o.stdout).ok()) - .map(|s| s.trim().to_string()) - .filter(|s| !s.is_empty()) - }) - .unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()); + let version = extension_version("ARROW_VERSION"); println!("cargo:rustc-env=ARROW_VERSION={version}"); + println!("cargo:rerun-if-changed=Cargo.lock"); let arrow_version = resolve_dep_version("arrow-schema").unwrap_or_else(|| "unknown".to_string()); @@ -24,6 +15,74 @@ fn main() { println!("cargo:rustc-env=PARQUET_LIB_VERSION={parquet_version}"); } +fn extension_version(env_name: &str) -> String { + println!("cargo:rerun-if-env-changed={env_name}"); + println!("cargo:rerun-if-changed=.git_archival.txt"); + + let describe = std::env::var(env_name) + .ok() + .filter(|s| !s.is_empty()) + .or_else(archived_describe) + .or_else(git_describe) + .unwrap_or_else(|| { + panic!("cannot determine the extension version: set {env_name}, build from a GitHub release archive, or build from a git checkout with tags") + }); + + as_semver(&describe) +} + +/// GitHub archives expand the `$Format:...$` placeholder (export-subst), a git checkout leaves it verbatim. +fn archived_describe() -> Option { + std::fs::read_to_string(".git_archival.txt") + .ok()? + .lines() + .find_map(|line| line.strip_prefix("describe-name: ")) + .map(str::trim) + .filter(|describe| !describe.is_empty() && !describe.starts_with("$Format")) + .map(str::to_string) +} + +fn git_describe() -> Option { + let describe = git(&["describe", "--tags", "--match", "[0-9]*"])?; + + for path in ["HEAD", "refs/heads", "refs/tags", "packed-refs"] { + if let Some(watched) = git(&["rev-parse", "--path-format=absolute", "--git-path", path]) { + if Path::new(&watched).exists() { + println!("cargo:rerun-if-changed={watched}"); + } + } + } + + Some(describe) +} + +fn git(args: &[&str]) -> Option { + Command::new("git") + .args(args) + .output() + .ok() + .filter(|output| output.status.success()) + .and_then(|output| String::from_utf8(output.stdout).ok()) + .map(|stdout| stdout.trim().to_string()) + .filter(|stdout| !stdout.is_empty()) +} + +/// `0.43.0-107-gf998a45d0` (git describe) becomes `0.43.0+107.gf998a45d0`, semver build metadata Composer reads as 0.43.0. +fn as_semver(describe: &str) -> String { + let mut parts = describe.rsplitn(3, '-'); + + match (parts.next(), parts.next(), parts.next()) { + (Some(hash), Some(distance), Some(tag)) + if hash.starts_with('g') + && !distance.is_empty() + && distance.bytes().all(|b| b.is_ascii_digit()) => + { + format!("{tag}+{distance}.{hash}") + } + _ => describe.to_string(), + } +} + fn resolve_dep_version(crate_name: &str) -> Option { let lock_contents = std::fs::read_to_string("Cargo.lock").ok()?; let needle = format!("name = \"{crate_name}\""); diff --git a/src/extension/arrow-ext/src/lib.rs b/src/extension/arrow-ext/src/lib.rs index 142ba71973..3f477a690b 100644 --- a/src/extension/arrow-ext/src/lib.rs +++ b/src/extension/arrow-ext/src/lib.rs @@ -45,6 +45,7 @@ pub unsafe extern "C" fn module_startup(_type: i32, _module_number: i32) -> i32 #[php(startup = "module_startup")] pub fn get_module(module: ModuleBuilder) -> ModuleBuilder { module + .version(env!("ARROW_VERSION")) .info_function(php_module_info) .class::() .class::() diff --git a/src/extension/arrow-ext/tests/phpt/038_extension_version.phpt b/src/extension/arrow-ext/tests/phpt/038_extension_version.phpt new file mode 100644 index 0000000000..6f1f935c11 --- /dev/null +++ b/src/extension/arrow-ext/tests/phpt/038_extension_version.phpt @@ -0,0 +1,8 @@ +--TEST-- +extension version is the release tag, or the last tag with commit distance and hash +--FILE-- + +--EXPECT-- +int(1) diff --git a/src/extension/flow-php-ext/.git_archival.txt b/src/extension/flow-php-ext/.git_archival.txt new file mode 100644 index 0000000000..88fee028ea --- /dev/null +++ b/src/extension/flow-php-ext/.git_archival.txt @@ -0,0 +1 @@ +describe-name: $Format:%(describe:tags=true,match=[0-9]*)$ diff --git a/src/extension/flow-php-ext/.gitattributes b/src/extension/flow-php-ext/.gitattributes index 1b17167edd..b83ec3200b 100644 --- a/src/extension/flow-php-ext/.gitattributes +++ b/src/extension/flow-php-ext/.gitattributes @@ -6,6 +6,9 @@ /.gitattributes export-ignore /.gitignore export-ignore +# Expand the version placeholder in release archives +/.git_archival.txt export-subst + # Ensure consistent line endings *.php text eol=lf *.rs text eol=lf diff --git a/src/extension/flow-php-ext/Cargo.lock b/src/extension/flow-php-ext/Cargo.lock index 0708705fda..0d97510639 100644 --- a/src/extension/flow-php-ext/Cargo.lock +++ b/src/extension/flow-php-ext/Cargo.lock @@ -443,7 +443,7 @@ dependencies = [ [[package]] name = "flow_php" -version = "0.3.0" +version = "0.0.0" dependencies = [ "ext-php-rs", "serde", diff --git a/src/extension/flow-php-ext/Cargo.toml b/src/extension/flow-php-ext/Cargo.toml index 1f9cfb79ec..b7ed1188bb 100644 --- a/src/extension/flow-php-ext/Cargo.toml +++ b/src/extension/flow-php-ext/Cargo.toml @@ -1,6 +1,5 @@ [package] name = "flow_php" -version = "0.3.0" edition = "2021" publish = false diff --git a/src/extension/flow-php-ext/build.rs b/src/extension/flow-php-ext/build.rs index bcf686cea3..eccfc93922 100644 --- a/src/extension/flow-php-ext/build.rs +++ b/src/extension/flow-php-ext/build.rs @@ -1,18 +1,76 @@ +use std::path::Path; +use std::process::Command; + fn main() { - let version = std::env::var("FLOW_PHP_EXT_VERSION") + let version = extension_version("FLOW_PHP_EXT_VERSION"); + + println!("cargo:rustc-env=FLOW_PHP_EXT_VERSION={version}"); +} + +fn extension_version(env_name: &str) -> String { + println!("cargo:rerun-if-env-changed={env_name}"); + println!("cargo:rerun-if-changed=.git_archival.txt"); + + let describe = std::env::var(env_name) .ok() .filter(|s| !s.is_empty()) - .or_else(|| { - std::process::Command::new("git") - .args(["describe", "--tags", "--always"]) - .output() - .ok() - .filter(|o| o.status.success()) - .and_then(|o| String::from_utf8(o.stdout).ok()) - .map(|s| s.trim().to_string()) - .filter(|s| !s.is_empty()) - }) - .unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()); + .or_else(archived_describe) + .or_else(git_describe) + .unwrap_or_else(|| { + panic!("cannot determine the extension version: set {env_name}, build from a GitHub release archive, or build from a git checkout with tags") + }); - println!("cargo:rustc-env=FLOW_PHP_EXT_VERSION={version}"); + as_semver(&describe) +} + +/// GitHub archives expand the `$Format:...$` placeholder (export-subst), a git checkout leaves it verbatim. +fn archived_describe() -> Option { + std::fs::read_to_string(".git_archival.txt") + .ok()? + .lines() + .find_map(|line| line.strip_prefix("describe-name: ")) + .map(str::trim) + .filter(|describe| !describe.is_empty() && !describe.starts_with("$Format")) + .map(str::to_string) +} + +fn git_describe() -> Option { + let describe = git(&["describe", "--tags", "--match", "[0-9]*"])?; + + for path in ["HEAD", "refs/heads", "refs/tags", "packed-refs"] { + if let Some(watched) = git(&["rev-parse", "--path-format=absolute", "--git-path", path]) { + if Path::new(&watched).exists() { + println!("cargo:rerun-if-changed={watched}"); + } + } + } + + Some(describe) +} + +fn git(args: &[&str]) -> Option { + Command::new("git") + .args(args) + .output() + .ok() + .filter(|output| output.status.success()) + .and_then(|output| String::from_utf8(output.stdout).ok()) + .map(|stdout| stdout.trim().to_string()) + .filter(|stdout| !stdout.is_empty()) +} + +/// `0.43.0-107-gf998a45d0` (git describe) becomes `0.43.0+107.gf998a45d0`, semver build metadata Composer reads as 0.43.0. +fn as_semver(describe: &str) -> String { + let mut parts = describe.rsplitn(3, '-'); + + match (parts.next(), parts.next(), parts.next()) { + (Some(hash), Some(distance), Some(tag)) + if hash.starts_with('g') + && !distance.is_empty() + && distance.bytes().all(|b| b.is_ascii_digit()) => + { + format!("{tag}+{distance}.{hash}") + } + _ => describe.to_string(), + } } diff --git a/src/extension/flow-php-ext/src/lib.rs b/src/extension/flow-php-ext/src/lib.rs index a3621d8095..522c6459eb 100644 --- a/src/extension/flow-php-ext/src/lib.rs +++ b/src/extension/flow-php-ext/src/lib.rs @@ -251,6 +251,7 @@ impl RustRowHydratorNative { #[php(startup = "module_startup")] pub fn get_module(module: ModuleBuilder) -> ModuleBuilder { module + .version(env!("FLOW_PHP_EXT_VERSION")) .info_function(php_module_info) .class::() .class::() diff --git a/src/extension/flow-php-ext/tests/phpt/036_extension_version_is_release_or_commit.phpt b/src/extension/flow-php-ext/tests/phpt/036_extension_version_is_release_or_commit.phpt new file mode 100644 index 0000000000..9f3df11cf2 --- /dev/null +++ b/src/extension/flow-php-ext/tests/phpt/036_extension_version_is_release_or_commit.phpt @@ -0,0 +1,10 @@ +--TEST-- +extension version is the release tag, or the last tag with commit distance and hash +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(1) diff --git a/src/extension/pg-query-ext/.git_archival.txt b/src/extension/pg-query-ext/.git_archival.txt new file mode 100644 index 0000000000..88fee028ea --- /dev/null +++ b/src/extension/pg-query-ext/.git_archival.txt @@ -0,0 +1 @@ +describe-name: $Format:%(describe:tags=true,match=[0-9]*)$ diff --git a/src/extension/pg-query-ext/.gitattributes b/src/extension/pg-query-ext/.gitattributes index 5a16515323..7902a2837e 100644 --- a/src/extension/pg-query-ext/.gitattributes +++ b/src/extension/pg-query-ext/.gitattributes @@ -5,6 +5,9 @@ /.gitattributes export-ignore /.gitignore export-ignore +# Expand the version placeholder in release archives +/.git_archival.txt export-subst + # Ensure consistent line endings *.php text eol=lf *.c text eol=lf diff --git a/src/extension/pg-query-ext/ext/config.m4 b/src/extension/pg-query-ext/ext/config.m4 index cff0ccf7f2..c2ac294b4d 100644 --- a/src/extension/pg-query-ext/ext/config.m4 +++ b/src/extension/pg-query-ext/ext/config.m4 @@ -170,6 +170,26 @@ if test "$PHP_PG_QUERY" != "no"; then PHP_SUBST(PG_QUERY_SHARED_LIBADD) + dnl GitHub archives expand the $Format placeholder in .git_archival.txt (export-subst), a git checkout leaves it verbatim + AC_MSG_CHECKING([for pg_query extension version]) + PG_QUERY_EXT_DESCRIBE="$PG_QUERY_EXT_VERSION" + if test -z "$PG_QUERY_EXT_DESCRIBE"; then + PG_QUERY_EXT_DESCRIBE=`sed -n 's/^describe-name: //p' "$EXT_DIR/../.git_archival.txt" 2>/dev/null` + case "$PG_QUERY_EXT_DESCRIBE" in + *Format*) PG_QUERY_EXT_DESCRIBE="" ;; + esac + fi + if test -z "$PG_QUERY_EXT_DESCRIBE"; then + PG_QUERY_EXT_DESCRIBE=`cd "$EXT_DIR" && git describe --tags --match '[[0-9]]*' 2>/dev/null` + fi + if test -z "$PG_QUERY_EXT_DESCRIBE"; then + AC_MSG_ERROR([cannot determine the extension version: set PG_QUERY_EXT_VERSION, build from a GitHub release archive, or build from a git checkout with tags]) + fi + dnl 0.43.0-107-gf998a45d0 (git describe) becomes 0.43.0+107.gf998a45d0, semver build metadata Composer reads as 0.43.0 + PG_QUERY_EXT_SEMVER=`echo "$PG_QUERY_EXT_DESCRIBE" | sed -E 's/-([[0-9]]+)-(g[[0-9a-f]]+)$/+\1.\2/'` + AC_MSG_RESULT([$PG_QUERY_EXT_SEMVER]) + AC_DEFINE_UNQUOTED([PHP_PG_QUERY_VERSION], ["$PG_QUERY_EXT_SEMVER"], [pg_query extension version]) + dnl Define extension PHP_NEW_EXTENSION(pg_query, pg_query.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) diff --git a/src/extension/pg-query-ext/ext/php_pg_query.h b/src/extension/pg-query-ext/ext/php_pg_query.h index afa2257827..9aaedcf808 100644 --- a/src/extension/pg-query-ext/ext/php_pg_query.h +++ b/src/extension/pg-query-ext/ext/php_pg_query.h @@ -10,7 +10,10 @@ extern zend_module_entry pg_query_module_entry; #define phpext_pg_query_ptr &pg_query_module_entry -#define PHP_PG_QUERY_VERSION "0.1.0" +#ifndef PHP_PG_QUERY_VERSION +# error "PHP_PG_QUERY_VERSION is defined by config.m4, run phpize && ./configure" +#endif + #define PHP_PG_QUERY_EXTNAME "pg_query" #ifdef PHP_WIN32 diff --git a/src/extension/pg-query-ext/tests/phpt/012_extension_version.phpt b/src/extension/pg-query-ext/tests/phpt/012_extension_version.phpt new file mode 100644 index 0000000000..d21267a2a9 --- /dev/null +++ b/src/extension/pg-query-ext/tests/phpt/012_extension_version.phpt @@ -0,0 +1,10 @@ +--TEST-- +extension version is the release tag, or the last tag with commit distance and hash +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(1)