Skip to content

Commit 51f0dd5

Browse files
authored
PHPC-2143: Build Windows DLLs with GitHub Actions (#1380)
* Fix APM and CSFLE tests for Windows CI * Add Windows to GitHub CI and build DLLs for releases * Add --enable-debug-pack configure opt to generate PDB files * Reminder to check for Windows build artifacts before publishing releases * Revise advice on publicizing releases
1 parent 4f7f14d commit 51f0dd5

File tree

9 files changed

+166
-28
lines changed

9 files changed

+166
-28
lines changed

.github/workflows/get-build-dir.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@ECHO OFF
2+
grep "BUILD_DIR=" Makefile | sed 's/BUILD_DIR=//g' | awk '{$1=$1};1'

.github/workflows/tests.yml

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151

5252
steps:
5353
- name: "Checkout"
54-
uses: "actions/checkout@v2"
54+
uses: "actions/checkout@v3"
5555
with:
5656
fetch-depth: 2
5757
submodules: true
@@ -78,3 +78,89 @@ jobs:
7878
run: TEST_PHP_ARGS="-q -x --show-diff -g FAIL,XFAIL,BORK,WARN,LEAK,SKIP" make test
7979
env:
8080
MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }}
81+
82+
windows-tests:
83+
name: "Windows Tests"
84+
runs-on: ${{ matrix.os }}
85+
defaults:
86+
run:
87+
shell: cmd
88+
89+
strategy:
90+
fail-fast: true
91+
matrix:
92+
os: [ windows-2019, windows-2022 ]
93+
php: [ "7.2", "7.3", "8.0", "8.1", "8.2" ]
94+
arch: [ x64, x86 ]
95+
ts: [ ts, nts ]
96+
exclude:
97+
- { os: windows-2019, php: "8.2" }
98+
- { os: windows-2019, php: "8.1" }
99+
- { os: windows-2019, php: "8.0" }
100+
- { os: windows-2019, php: "7.4" }
101+
- { os: windows-2019, php: "7.3" }
102+
- { os: windows-2022, php: "7.2" }
103+
104+
steps:
105+
- uses: actions/checkout@v3
106+
with:
107+
fetch-depth: 2
108+
submodules: true
109+
110+
- name: Setup PHP SDK
111+
id: setup-php
112+
uses: cmb69/[email protected]
113+
with:
114+
version: ${{ matrix.php }}
115+
arch: ${{ matrix.arch }}
116+
ts: ${{ matrix.ts }}
117+
deps: openssl
118+
119+
- name: Enable Developer Command Prompt
120+
uses: ilammy/msvc-dev-cmd@v1
121+
with:
122+
arch: ${{ matrix.arch }}
123+
toolset: ${{ steps.setup-php.outputs.toolset }}
124+
125+
- name: phpize
126+
run: phpize
127+
128+
- name: configure
129+
run: configure --enable-mongodb --with-mongodb-sasl=yes --with-mongodb-client-side-encryption=yes --enable-debug-pack --with-prefix=${{ steps.setup-php.outputs.prefix }}
130+
131+
- name: nmake
132+
run: nmake /nologo
133+
134+
- name: Start MongoDB
135+
run: |
136+
sc config MongoDB start= auto
137+
sc start MongoDB
138+
139+
- name: Wait until MongoDB is available
140+
run: .github/workflows/wait-for-mongodb.bat
141+
142+
- name: Run Tests
143+
run: nmake /nologo test
144+
env:
145+
NO_INTERACTION: 1
146+
REPORT_EXIT_STATUS: 1
147+
TESTS: --show-diff
148+
149+
- name: Copy DLL and PDB files to CWD
150+
if: ${{ github.event_name == 'push' }}
151+
run: |
152+
cp .github/workflows/get-build-dir.bat .
153+
for /F "usebackq tokens=*" %%i in (`get-build-dir.bat`) do set BUILD_DIR=%%i
154+
echo BUILD_DIR=%BUILD_DIR%
155+
cp %BUILD_DIR%\php_mongodb.dll .
156+
cp %BUILD_DIR%\php_mongodb.pdb .
157+
158+
- name: Upload DLL and PDB files as build artifacts
159+
if: ${{ github.event_name == 'push' }}
160+
uses: actions/upload-artifact@v3
161+
with:
162+
name: php_mongodb-${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
163+
path: |
164+
php_mongodb.dll
165+
php_mongodb.pdb
166+
retention-days: 3
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@ECHO OFF
2+
:repeat
3+
powershell -nop -c "& {sleep 1}"
4+
mongo --quiet --eval 'db.runCommand({ping:1})' || goto :repeat
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "Windows Release Build"
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
7+
jobs:
8+
windows-release-build:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
# Note: keep this in sync with the Windows matrix in tests.yml
13+
php: [ "7.2", "7.3", "8.0", "8.1", "8.2" ]
14+
arch: [ x64, x86 ]
15+
ts: [ ts, nts ]
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Download DLL and PDB files
23+
uses: dawidd6/action-download-artifact@v2
24+
with:
25+
workflow: tests.yml
26+
workflow_conclusion: success
27+
commit: ${{ github.sha }}
28+
# Note: keep this in sync with the uploaded artifact name in tests.yml
29+
name: php_mongodb-${{ github.sha }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}
30+
31+
- name: Create and attach release archive
32+
run: |
33+
ARCHIVE=php_mongodb-${{ github.ref_name }}-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.arch }}.zip
34+
zip $ARCHIVE php_mongodb.dll php_mongodb.pdb CREDITS CONTRIBUTING.md LICENSE README.md THIRD_PARTY_NOTICES
35+
hub release edit -a $ARCHIVE -m "" $GITHUB_REF_NAME
36+
env:
37+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

CONTRIBUTING.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,6 @@ generation script.
284284
The follow steps outline the release process for a maintenance branch (e.g.
285285
releasing the `vX.Y` branch as X.Y.Z).
286286

287-
### Ensure PHP version compatibility
288-
289-
Ensure that the library test suite completes on supported versions of PHP.
290-
291-
### Ensure Windows compatibility
292-
293-
PECL will create Windows DLLs for new releases; however, you must ensure that
294-
the extension successfully builds on Windows before releasing. Windows builds
295-
are tested by [AppVeyor](.appveyor.yml).
296-
297-
See the [internals wiki](https://wiki.php.net/internals/windows/stepbystepbuild)
298-
for more information.
299-
300287
### Transition JIRA issues and version
301288

302289
All issues associated with the release version should be in the "Closed" state
@@ -420,6 +407,21 @@ $ git push
420407
$ git push --tags
421408
```
422409

410+
### Ensure Windows build artifacts exist
411+
412+
Windows builds are tested by GitHub Actions. Each successful build for a pushed
413+
commit will produce a build artifact consisting of DLL and PDB files for that
414+
environment (e.g. 8.0-nts-x64). These build artifacts are later used to create
415+
release assets (see:
416+
[windows-release-build.yml])(.github/workflows/windows-release-build.yml).
417+
Before publishing a release in GitHub, ensure that all Windows builds for the
418+
tag's commit have succeeded and that the necessary build artifacts have been
419+
created.
420+
421+
Note: the "published" event applies to both releases and pre-releases. See
422+
[Events that trigger workflows: release](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release)
423+
for more details.
424+
423425
### Release PECL package
424426

425427
The PECL package may be published via the
@@ -468,8 +470,7 @@ or update with:
468470
469471
pecl upgrade mongodb-X.Y.Z
470472
471-
Windows binaries are available on PECL:
472-
https://pecl.php.net/package/mongodb
473+
Windows binaries are attached to the GitHub release notes.
473474
```
474475

475476
> **Note:** If this is an alpha or beta release, the installation examples
@@ -492,7 +493,8 @@ Thanks for our community contributors for X.Y.Z:
492493
* [$CONTRIBUTOR_NAME](https://github.com/$GITHUB_USERNAME)
493494
```
494495

495-
Release announcements should also be posted in the [MongoDB Product & Driver Announcements: Driver Releases](https://www.mongodb.com/community/forums/tags/c/announcements/driver-releases/110/php) forum and shared on Twitter.
496+
Significant release announcements should also be posted in the
497+
[MongoDB Product & Driver Announcements: Driver Releases](https://www.mongodb.com/community/forums/tags/c/announcements/driver-releases/110/php) forum.
496498

497499
### Update compatibility tables in MongoDB docs
498500

tests/apm/commandFailedEvent-001.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
MongoDB\Driver\Monitoring\CommandFailedEvent
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5-
<?php skip_if_appveyor(); /* TODO: PHPC-1613 */ ?>
65
<?php skip_if_not_live(); ?>
76
<?php skip_if_not_clean(); ?>
87
--FILE--
@@ -16,6 +15,13 @@ class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
1615
public function commandStarted( \MongoDB\Driver\Monitoring\CommandStartedEvent $event ): void
1716
{
1817
echo "started: ", $event->getCommandName(), "\n";
18+
19+
/* bson_get_monotonic_time() may only have 10-16 millisecond precision
20+
* on Windows. Sleep to ensure that a non-zero value is reported for
21+
* CommandFailedEvent's duration. */
22+
if (PHP_OS_FAMILY === 'Windows') {
23+
usleep(25000);
24+
}
1925
}
2026

2127
public function commandSucceeded( \MongoDB\Driver\Monitoring\CommandSucceededEvent $event ): void

tests/apm/commandSucceededEvent-001.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
MongoDB\Driver\Monitoring\CommandSucceededEvent
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5-
<?php skip_if_appveyor(); /* TODO: PHPC-1613 */ ?>
65
<?php skip_if_not_live(); ?>
76
<?php skip_if_not_clean(); ?>
87
--FILE--
@@ -16,6 +15,13 @@ class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
1615
public function commandStarted( \MongoDB\Driver\Monitoring\CommandStartedEvent $event ): void
1716
{
1817
echo "started: ", $event->getCommandName(), "\n";
18+
19+
/* bson_get_monotonic_time() may only have 10-16 millisecond precision
20+
* on Windows. Sleep to ensure that a non-zero value is reported for
21+
* CommandSucceededEvent's duration. */
22+
if (PHP_OS_FAMILY === 'Windows') {
23+
usleep(25000);
24+
}
1925
}
2026

2127
public function commandSucceeded( \MongoDB\Driver\Monitoring\CommandSucceededEvent $event ): void

tests/manager/manager-ctor-auto_encryption-001.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
MongoDB\Driver\Manager::__construct(): autoEncryption options
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5-
<?php skip_if_appveyor(); /* AppVeyor does not have mongocryptd installed */ ?>
65
<?php skip_if_not_libmongocrypt(); ?>
76
--FILE--
87
<?php
@@ -12,6 +11,10 @@ require_once __DIR__ . '/../utils/basic.inc';
1211
$baseOptions = [
1312
'keyVaultNamespace' => CSFLE_KEY_VAULT_NS,
1413
'kmsProviders' => ['local' => ['key' => new MongoDB\BSON\Binary(CSFLE_LOCAL_KEY, 0)]],
14+
/* Testing the schemaMap option requires either crypt_shared or mongocryptd
15+
* for automatic encryption. Disable mongocryptd spawning to avoid a test
16+
* failure if crypt_shared and mongocryptd are both unavailable. */
17+
'extraOptions' => ['mongocryptdBypassSpawn' => true],
1518
];
1619

1720
$tests = [
@@ -40,7 +43,6 @@ $tests = [
4043
'bsonType' => 'object',
4144
],
4245
]],
43-
['extraOptions' => ['mongocryptdBypassSpawn' => true]],
4446
];
4547

4648
foreach ($tests as $autoEncryptionOptions) {

tests/utils/skipif.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,6 @@ function skip_if_no_mongo_orchestration()
479479
}
480480
}
481481

482-
function skip_if_appveyor()
483-
{
484-
if (getenv('APPVEYOR')) {
485-
exit('skip Test cannot be run on AppVeyor');
486-
}
487-
}
488-
489482
function skip_if_crypt_shared()
490483
{
491484
// Intentionally ignore empty values for CRYPT_SHARED_LIB_PATH

0 commit comments

Comments
 (0)