Skip to content

Commit 71510e2

Browse files
authored
PHPC-2584: Run driver test with system libraries (#1831)
* Add build action to build libmongoc system libraries * Build driver with system libs * Install libmongocrypt as system library * Run tests with system libs * Move system library tests to tests workflow
1 parent b5f3c8e commit 71510e2

File tree

5 files changed

+164
-1
lines changed

5 files changed

+164
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: "Build libmongoc"
2+
description: "Builds and install libmongoc"
3+
inputs:
4+
prefix:
5+
description: "Prefix to install libmongoc to"
6+
default: "/usr/local"
7+
version:
8+
description: "Libmongoc version to build"
9+
required: true
10+
runs:
11+
using: composite
12+
13+
steps:
14+
- name: Download libmongoc
15+
shell: bash
16+
working-directory: /tmp
17+
run: wget "https://github.com/mongodb/mongo-c-driver/archive/refs/tags/${LIBMONGOC_VERSION}.tar.gz" --output-document="mongo-c-driver.tar.gz"
18+
env:
19+
LIBMONGOC_VERSION: ${{ inputs.version }}
20+
21+
- name: Extract libmongoc
22+
shell: bash
23+
working-directory: /tmp
24+
run: tar xf "mongo-c-driver.tar.gz"
25+
26+
- name: Configure cmake
27+
shell: bash
28+
working-directory: /tmp
29+
run: |
30+
cmake \
31+
-S "mongo-c-driver-${LIBMONGOC_VERSION}" \
32+
-B _build \
33+
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
34+
-D BUILD_VERSION="${LIBMONGOC_VERSION}" \
35+
-D ENABLE_MONGOC=ON \
36+
-D ENABLE_TRACING=ON \
37+
-D ENABLE_CLIENT_SIDE_ENCRYPTION=ON
38+
env:
39+
LIBMONGOC_VERSION: ${{ inputs.version }}
40+
41+
- name: Build libmongoc
42+
shell: bash
43+
working-directory: /tmp
44+
run: cmake --build _build --config RelWithDebInfo --parallel
45+
46+
- name: Install libmongoc
47+
shell: bash
48+
working-directory: /tmp
49+
run: sudo cmake --install _build --prefix "${PREFIX}" --config RelWithDebInfo
50+
env:
51+
PREFIX: ${{ inputs.prefix }}
52+
53+
- name: Check pkg-config availability
54+
shell: bash
55+
run: pkg-config --modversion mongoc2
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "Build libmongocrypt"
2+
description: "Installs libmongocrypt"
3+
inputs:
4+
version:
5+
description: "Libmongocrypt version to install (major.minor)"
6+
required: true
7+
runs:
8+
using: composite
9+
10+
steps:
11+
- name: Add repository key
12+
shell: bash
13+
run: sudo sh -c 'curl -s --location https://pgp.mongodb.com/libmongocrypt.asc | gpg --dearmor >/etc/apt/trusted.gpg.d/libmongocrypt.gpg'
14+
15+
- name: Add repository
16+
shell: bash
17+
working-directory: /tmp
18+
# Note: no packages for Ubuntu 24.04 noble exist, so we use those for 22.04
19+
run: echo "deb https://libmongocrypt.s3.amazonaws.com/apt/ubuntu jammy/libmongocrypt/${LIBMONGOCRYPT_VERSION} universe" | sudo tee /etc/apt/sources.list.d/libmongocrypt.list
20+
env:
21+
LIBMONGOCRYPT_VERSION: ${{ inputs.version }}
22+
23+
- name: Update apt sources
24+
shell: bash
25+
run: sudo apt-get update
26+
27+
- name: Install libmongocrypt
28+
shell: bash
29+
run: sudo apt-get install -y libmongocrypt-dev

.github/actions/linux/build/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ inputs:
44
version:
55
description: "PHP version to build for"
66
required: true
7+
configureOpts:
8+
description: "Extra options to use for the call to ./configure"
9+
default: ""
10+
711
runs:
812
using: composite
913
steps:
@@ -17,6 +21,8 @@ runs:
1721
- name: "Configure driver"
1822
run: .github/workflows/configure.sh
1923
shell: bash
24+
env:
25+
CONFIGURE_OPTS: ${{ inputs.configureOpts }}
2026

2127
- name: "Build driver"
2228
run: "make all"

.github/workflows/tests.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,54 @@ jobs:
128128
php: [ "8.1", "8.2", "8.3", "8.4" ]
129129
arch: [ x64, x86 ]
130130
ts: [ ts, nts ]
131+
132+
test-system-libs:
133+
name: "System Library Tests"
134+
runs-on: "ubuntu-latest"
135+
env:
136+
PHP_VERSION: "8.3"
137+
LIBMONGOCRYPT_VERSION: "1.14"
138+
LIBMONGOC_VERSION: "2.0.1"
139+
SERVER_VERSION: "8.0"
140+
141+
steps:
142+
- name: "Checkout"
143+
uses: "actions/checkout@v4"
144+
with:
145+
submodules: true
146+
147+
- name: "Install libmongocrypt"
148+
uses: ./.github/actions/linux/build-libmongocrypt
149+
with:
150+
version: ${{ env.LIBMONGOCRYPT_VERSION }}
151+
152+
- name: "Build libmongoc"
153+
uses: ./.github/actions/linux/build-libmongoc
154+
with:
155+
version: ${{ env.LIBMONGOC_VERSION }}
156+
157+
- name: "Build Driver"
158+
uses: ./.github/actions/linux/build
159+
with:
160+
version: ${{ env.PHP_VERSION }}
161+
configureOpts: "--with-mongodb-system-libs=yes"
162+
163+
- name: "Check driver version"
164+
shell: bash
165+
run: make show-config
166+
167+
- uses: actions/setup-python@v5
168+
with:
169+
python-version: "3.13"
170+
171+
- name: Setup MongoDB
172+
id: setup-mongodb
173+
uses: ./tests/drivers-evergreen-tools
174+
with:
175+
version: ${{ ENV.SERVER_VERSION }}
176+
topology: "server"
177+
178+
- name: "Run Tests"
179+
run: TEST_PHP_ARGS="-q -x --show-diff -g FAIL,XFAIL,BORK,WARN,LEAK,SKIP" make test
180+
env:
181+
MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }}

Makefile.frag

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: mv-coverage lcov-coveralls lcov-local coverage coveralls format format-changed format-check test-clean package package.xml libmongocrypt-version-current generate-function-map
1+
.PHONY: mv-coverage lcov-coveralls lcov-local coverage coveralls format format-changed format-check test-clean package package.xml libmongocrypt-version-current generate-function-map show-config
22

33
ifneq (,$(realpath $(EXTENSION_DIR)/json.so))
44
PHP_TEST_SHARED_EXTENSIONS := "-d" "extension=$(EXTENSION_DIR)/json.so" $(PHP_TEST_SHARED_EXTENSIONS)
@@ -88,6 +88,28 @@ generate-function-map: all
8888
echo "ERROR: Cannot generate function maps without CLI sapi."; \
8989
fi
9090

91+
show-config: all
92+
@if test ! -z "$(PHP_EXECUTABLE)" && test -x "$(PHP_EXECUTABLE)"; then \
93+
INI_FILE=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/null`; \
94+
if test "$$INI_FILE"; then \
95+
$(EGREP) -h -v $(PHP_DEPRECATED_DIRECTIVES_REGEX) "$$INI_FILE" > $(top_builddir)/tmp-php.ini; \
96+
else \
97+
echo > $(top_builddir)/tmp-php.ini; \
98+
fi; \
99+
INI_SCANNED_PATH=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r '$$a = explode(",\n", trim(php_ini_scanned_files())); echo $$a[0];' 2> /dev/null`; \
100+
if test "$$INI_SCANNED_PATH"; then \
101+
INI_SCANNED_PATH=`$(top_srcdir)/build/shtool path -d $$INI_SCANNED_PATH`; \
102+
$(EGREP) -h -v $(PHP_DEPRECATED_DIRECTIVES_REGEX) "$$INI_SCANNED_PATH"/*.ini >> $(top_builddir)/tmp-php.ini; \
103+
fi; \
104+
CC="$(CC)" \
105+
$(PHP_EXECUTABLE) -n -c $(top_builddir)/tmp-php.ini -d extension_dir=$(top_builddir)/modules/ $(PHP_TEST_SHARED_EXTENSIONS) --ri mongodb; \
106+
RESULT_EXIT_CODE=$$?; \
107+
rm $(top_builddir)/tmp-php.ini; \
108+
exit $$RESULT_EXIT_CODE; \
109+
else \
110+
echo "ERROR: Cannot show config without CLI sapi."; \
111+
fi
112+
91113
test-no-build:
92114
@if test ! -z "$(PHP_EXECUTABLE)" && test -x "$(PHP_EXECUTABLE)"; then \
93115
INI_FILE=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/null`; \

0 commit comments

Comments
 (0)