Skip to content

PHPC-2233: Split Windows Builds #1460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 2, 2023
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
78 changes: 0 additions & 78 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,81 +78,3 @@ jobs:
run: TEST_PHP_ARGS="-q -x --show-diff -g FAIL,XFAIL,BORK,WARN,LEAK,SKIP" make test
env:
MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }}

windows-tests:
name: "Windows Tests"
runs-on: windows-2022
defaults:
run:
shell: cmd

strategy:
fail-fast: true
matrix:
php: [ "7.4", "8.0", "8.1", "8.2" ]
arch: [ x64, x86 ]
ts: [ ts, nts ]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: true

- name: Setup PHP SDK
id: setup-php
uses: cmb69/[email protected]
with:
version: ${{ matrix.php }}
arch: ${{ matrix.arch }}
ts: ${{ matrix.ts }}
deps: openssl

- name: Enable Developer Command Prompt
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
toolset: ${{ steps.setup-php.outputs.toolset }}

- name: phpize
run: phpize

- name: configure
run: configure --enable-mongodb --with-mongodb-sasl=yes --with-mongodb-client-side-encryption=yes --enable-debug-pack --with-prefix=${{ steps.setup-php.outputs.prefix }}

- name: nmake
run: nmake /nologo

- name: Start MongoDB
run: |
sc config MongoDB start= auto
sc start MongoDB

- name: Wait until MongoDB is available
run: .github/workflows/wait-for-mongodb.bat

- name: Run Tests
run: nmake /nologo test
env:
NO_INTERACTION: 1
REPORT_EXIT_STATUS: 1
TESTS: --show-diff

- name: Copy DLL and PDB files to CWD
if: ${{ github.event_name == 'push' }}
run: |
cp .github/workflows/get-build-dir.bat .
for /F "usebackq tokens=*" %%i in (`get-build-dir.bat`) do set BUILD_DIR=%%i
echo BUILD_DIR=%BUILD_DIR%
cp %BUILD_DIR%\php_mongodb.dll .
cp %BUILD_DIR%\php_mongodb.pdb .

- name: Upload DLL and PDB files as build artifacts
if: ${{ github.event_name == 'push' }}
uses: actions/upload-artifact@v3
with:
name: php_mongodb-${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
path: |
php_mongodb.dll
php_mongodb.pdb
retention-days: 3
2 changes: 1 addition & 1 deletion .github/workflows/windows-release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
workflow: tests.yml
workflow_conclusion: success
commit: ${{ github.sha }}
# Note: keep this in sync with the uploaded artifact name in tests.yml
# Note: keep this in sync with the uploaded artifact name in windows-tests.yml
name: php_mongodb-${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}

- name: Create and attach release archive
Expand Down
132 changes: 132 additions & 0 deletions .github/workflows/windows-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: "Windows Tests"

on:
pull_request:
branches:
- "v*.*"
- "master"
- "feature/*"
push:
tags:
- "*"
branches:
- "v*.*"
- "master"
- "feature/*"

jobs:
build:
name: "Build Windows DLLs"
runs-on: windows-2022
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to enforce that this is standardized between both jobs?

jobs.<job_id>.runs-on suggests that this can be a variable.

Not sure this is needed since we only have two jobs, but wanted to ask anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Workflow syntax documentation, the only other place where to put such values is env. However, values set there can't be arrays, so even though we could reference an environment variable in the matrix definition, we can't set the list of PHP versions in an environment variable to reuse it in both matrixes.

defaults:
run:
shell: cmd

strategy:
# This matrix intentionally uses fail-fast: false to ensure other builds are finished
fail-fast: false
matrix:
php: [ "7.4", "8.0", "8.1", "8.2" ]
arch: [ x64, x86 ]
ts: [ ts, nts ]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: true

- name: Prepare build environment
id: prepare-build
uses: ./.github/workflows/windows/prepare-build
with:
version: ${{ matrix.php }}
arch: ${{ matrix.arch }}
ts: ${{ matrix.ts }}

- name: Build driver
run: nmake /nologo

- name: Cache build artifacts for subsequent builds
id: cache-build-artifacts
uses: actions/cache/save@v3
with:
key: ${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
path: |
${{ steps.prepare-build.outputs.build-dir }}\php_mongodb.dll
${{ steps.prepare-build.outputs.build-dir }}\php_mongodb.pdb

- name: Copy DLL and PDB files to CWD
if: ${{ github.event_name == 'push' }}
run: |
cp .github/workflows/get-build-dir.bat .
for /F "usebackq tokens=*" %%i in (`get-build-dir.bat`) do set BUILD_DIR=%%i
echo BUILD_DIR=%BUILD_DIR%
cp %BUILD_DIR%\php_mongodb.dll .
cp %BUILD_DIR%\php_mongodb.pdb .

- name: Upload DLL and PDB files as build artifacts
if: ${{ github.event_name == 'push' }}
uses: actions/upload-artifact@v3
with:
name: php_mongodb-${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
path: |
php_mongodb.dll
php_mongodb.pdb
retention-days: 3

test:
name: "Windows Tests"
runs-on: windows-2022
# Run tests only when pushing to a branch. When pushing a tag, we're only interested in building the DLLs.
if: ${{ github.ref_type == 'branch' }}
needs: build
defaults:
run:
shell: cmd

strategy:
fail-fast: true
matrix:
php: [ "7.4", "8.0", "8.1", "8.2" ]
arch: [ x64, x86 ]
ts: [ ts, nts ]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
submodules: true

- name: Prepare build environment
id: prepare-build
uses: ./.github/workflows/windows/prepare-build
with:
version: ${{ matrix.php }}
arch: ${{ matrix.arch }}
ts: ${{ matrix.ts }}

- name: Restore cached build artifacts
id: cache-build-artifacts
uses: actions/cache/restore@v3
with:
fail-on-cache-miss: true
key: ${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
path: |
${{ steps.prepare-build.outputs.build-dir }}\php_mongodb.dll
${{ steps.prepare-build.outputs.build-dir }}\php_mongodb.pdb

- name: Start MongoDB
run: |
sc config MongoDB start= auto
sc start MongoDB

- name: Wait until MongoDB is available
run: .github/workflows/wait-for-mongodb.bat

- name: Run Tests
run: nmake /nologo test
env:
NO_INTERACTION: 1
REPORT_EXIT_STATUS: 1
TESTS: --show-diff
53 changes: 53 additions & 0 deletions .github/workflows/windows/prepare-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: "Setup PHP driver build environment"
description: "Prepares the PHP build environment for the MongoDB driver"
inputs:
version:
description: "PHP version to build for"
required: true
arch:
description: "The architecture to build for (x64 or x86)"
required: true
ts:
description: "Thread-safety (nts or ts)"
required: true
outputs:
build-dir:
description: "The build directory to be used"
value: ${{steps.get-build-dir.outputs.build_dir}}
runs:
using: composite
steps:
- name: Setup PHP SDK
id: setup-php
uses: cmb69/[email protected]
with:
version: ${{ inputs.version }}
arch: ${{ inputs.arch }}
ts: ${{ inputs.ts }}
deps: openssl

- name: Enable Developer Command Prompt
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
toolset: ${{ steps.setup-php.outputs.toolset }}

- name: phpize
run: phpize
shell: cmd

- name: configure
run: configure --enable-mongodb --with-mongodb-sasl=yes --with-mongodb-client-side-encryption=yes --enable-debug-pack --with-prefix=${{ steps.setup-php.outputs.prefix }}
shell: cmd

- name: Get build directory
id: get-build-dir
shell: cmd
# The last echo command to set the output variable intentionally omits a space between the environment variable
# and the output redirector to avoid a trailing space in the generated output variable. Do not add a space.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good comment.

run: |
cp .github/workflows/get-build-dir.bat .
for /F "usebackq tokens=*" %%i in (`get-build-dir.bat`) do set BUILD_DIR=%%i
echo BUILD_DIR=%BUILD_DIR%
@chcp 65001>nul
echo build_dir=%BUILD_DIR%>> %GITHUB_OUTPUT%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this script adapted from another action, or did you come up with this yourself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first two lines were present previously in the steps that publish the DLL as build artifact. The second lines took me a while to figure out, as the syntax to set an output variable for a step depends on the shell being used. This StackOverflow answer ultimately showed me the correct syntax for this to work in cmd.