Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .evergreen/compile-extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ set -o errexit # Exit the script with error if any of the commands fail

PATH="$PHP_PATH/bin:$PATH"

# Turn EXTENSION_TARGET into the EXTENSION_BRANCH or EXTENSION_VERSION expected
# by install_extension. Both variables can also be set explicitly, e.g. in a
# patch build, in which case they take precedence over EXTENSION_TARGET.
resolve_extension_target ()
{
if [ "x${EXTENSION_BRANCH}" != "x" ] || [ "x${EXTENSION_VERSION}" != "x" ]; then
return
fi

# Assign before eval, so that a failure of the script stops the build
RESOLVED=$(php "${PROJECT_DIRECTORY}/tools/extension-version.php" "${EXTENSION_TARGET:-stable}")

eval "${RESOLVED}"
}

install_extension ()
{
rm -f ${PHP_PATH}/lib/php.ini
Expand Down Expand Up @@ -45,4 +60,5 @@ install_extension ()
php --ri mongodb
}

resolve_extension_target
install_extension
55 changes: 20 additions & 35 deletions .evergreen/config/generated/build/build-extension.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions .evergreen/config/templates/build/build-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
vars:
PHP_VERSION: "%phpVersion%"
- func: "compile extension"
# TODO: Remove vars to switch to latest stable version when 2.5.0 is released
vars:
EXTENSION_BRANCH: "v2.x"
EXTENSION_TARGET: "stable"
- func: "upload extension"
- name: "build-php-%phpVersion%-lowest"
tags: ["build", "php%phpVersion%", "lowest", "pr", "tag"]
Expand All @@ -16,9 +15,8 @@
vars:
PHP_VERSION: "%phpVersion%"
- func: "compile extension"
# TODO: Switch to EXTENSION_VERSION: "2.5.0" when 2.5.0 is released on PECL
vars:
EXTENSION_BRANCH: "v2.x"
EXTENSION_TARGET: "lowest"
- func: "upload extension"
- name: "build-php-%phpVersion%-next-stable"
tags: ["build", "php%phpVersion%", "next-stable", "pr", "tag"]
Expand All @@ -27,9 +25,8 @@
vars:
PHP_VERSION: "%phpVersion%"
- func: "compile extension"
# TODO: Switch to EXTENSION_VERSION: "2.5.0" when 2.5.0 is released on PECL
vars:
EXTENSION_BRANCH: "v2.x"
EXTENSION_TARGET: "next-stable"
- func: "upload extension"
- name: "build-php-%phpVersion%-next-minor"
tags: ["build", "php%phpVersion%", "next-minor"]
Expand All @@ -39,5 +36,5 @@
PHP_VERSION: "%phpVersion%"
- func: "compile extension"
vars:
EXTENSION_BRANCH: "v2.x"
EXTENSION_TARGET: "next-minor"
- func: "upload extension"
58 changes: 52 additions & 6 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ inputs:
description: "PHP version to install"
required: true
driver-version:
description: "MongoDB extension version to install"
required: true
description: "MongoDB extension version to install: \"stable\" for the highest version allowed by composer.json, \"lowest\" for the minimum required version"
required: false
default: "stable"
php-ini-values:
description: "INI values to pass along to setup-php action"
required: false
Expand All @@ -22,26 +23,59 @@ inputs:
runs:
using: composite
steps:
# The extension version is resolved by a PHP script, so PHP is installed
# first, without the extension. The second call below adds it.
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "${{ inputs.php-version }}"

- name: Resolve extension version
id: driver
shell: bash
run: |
# The ext-mongodb constraint is only declared in the composer.json of
# the library, at the root of the repository.
RESOLVED=$(php tools/extension-version.php "${{ inputs.driver-version }}")

eval "$RESOLVED"

if [ "$EXTENSION_VERSION" != "" ]; then
echo "ext-spec=mongodb-${EXTENSION_VERSION}" >> "$GITHUB_OUTPUT"
echo "ext-expected=${EXTENSION_VERSION}" >> "$GITHUB_OUTPUT"
echo "ext-cachable=true" >> "$GITHUB_OUTPUT"
else
# Source builds cannot be cached, and caching a moving branch under
# a stable key would freeze an outdated extension.
echo "ext-spec=mongodb-mongodb/mongo-php-driver@${EXTENSION_BRANCH}" >> "$GITHUB_OUTPUT"
echo "ext-cachable=false" >> "$GITHUB_OUTPUT"
fi

- name: Setup cache environment
id: extcache
if: steps.driver.outputs.ext-cachable == 'true'
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ inputs.php-version }}
extensions: "mongodb-${{ inputs.driver-version }}"
key: "extcache-${{ inputs.driver-version }}-${{ hashFiles('composer.json') }}"
extensions: "${{ steps.driver.outputs.ext-spec }}"
# The requested extension version is part of the key computed by the
# action. This value is only there to invalidate the cache by hand.
key: "extcache-v1"

- name: Cache extensions
if: steps.driver.outputs.ext-cachable == 'true'
uses: actions/cache@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Install PHP
- name: Install the mongodb extension
uses: shivammathur/setup-php@v2
with:
coverage: xdebug
extensions: "mongodb-${{ inputs.driver-version }}"
extensions: "${{ steps.driver.outputs.ext-spec }}"
php-version: "${{ inputs.php-version }}"
tools: cs2pr
ini-values: "${{ inputs.php-ini-values }}"
Expand All @@ -50,6 +84,18 @@ runs:
run: "php --ri mongodb"
shell: bash

- name: Check the expected driver version is installed
if: steps.driver.outputs.ext-expected != ''
shell: bash
run: |
INSTALLED=$(php -r 'echo phpversion("mongodb");')
EXPECTED="${{ steps.driver.outputs.ext-expected }}"

if [ "$INSTALLED" != "$EXPECTED" ]; then
echo "::error::Expected extension version $EXPECTED, got $INSTALLED"
exit 1
fi

- name: Install dependencies with Composer
uses: ramsey/composer-install@3.0.0
with:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ on:

env:
PHP_VERSION: "8.2"
# TODO: change to "stable" once 2.5.0 is released
# DRIVER_VERSION: "stable"
DRIVER_VERSION: "mongodb/mongo-php-driver@v2.x"

jobs:
phpcs:
Expand All @@ -30,7 +27,6 @@ jobs:
uses: "./.github/actions/setup"
with:
php-version: ${{ env.PHP_VERSION }}
driver-version: ${{ env.DRIVER_VERSION }}

# The -q option is required until phpcs v4 is released
- name: "Run PHP_CodeSniffer"
Expand All @@ -48,7 +44,6 @@ jobs:
uses: "./.github/actions/setup"
with:
php-version: ${{ env.PHP_VERSION }}
driver-version: ${{ env.DRIVER_VERSION }}

- name: "Run Rector"
run: "vendor/bin/rector --ansi --dry-run"
Loading
Loading