-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
1079 lines (888 loc) · 40.4 KB
/
azure-pipelines.yml
File metadata and controls
1079 lines (888 loc) · 40.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
variables:
server: 'localhost,1433'
host: 'sql1'
sqlsrv_db: 'sqlsrv_testdb'
pdo_sqlsrv_db: 'pdo_sqlsrv_testdb'
uid: 'sa'
trigger:
- dev
- fix/*
pr:
- dev
jobs:
- job: macOS
pool:
vmImage: 'macos-latest'
timeoutInMinutes: 90
variables:
phpver: '8.5'
macOS_sqlsrv_db: 'macos_sqlsrv_testdb'
macOS_pdo_sqlsrv_db: 'macos_pdo_sqlsrv_testdb'
REPO_ROOT: $(Build.SourcesDirectory)
steps:
- checkout: self
clean: true
fetchDepth: 1
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'
#########################################
# Install Prerequisites (Homebrew)
#########################################
- script: |
set -e
echo "Installing prerequisites via Homebrew..."
# Single brew update for all installations
brew update
echo "Installing build tools in parallel..."
# Use install (faster than reinstall) and run in parallel where possible
brew install autoconf automake libtool pkg-config libiconv bison re2c icu4c 2>/dev/null || true
echo "Setting up environment..."
echo "##vso[task.prependpath]/usr/local/opt/bison/bin"
echo "##vso[task.prependpath]/opt/homebrew/opt/bison/bin"
echo "Prerequisites installed successfully!"
displayName: 'Install Prerequisites'
#########################################
# Install Docker (Colima) and Start SQL Server
#########################################
- script: |
set -e
echo "Setting up Docker using Colima..."
brew install --cask docker || true
brew install colima
echo "Starting Colima..."
colima start --cpu 2 --memory 4
echo "Verifying Docker..."
docker ps
echo "Docker setup complete!"
displayName: 'Setup Docker (Colima)'
- powershell: |
$guid = [guid]::NewGuid().ToString()
Write-Host "##vso[task.setvariable variable=macpwd;issecret=true]$guid"
displayName: 'Generate Password for macOS'
- script: |
set -e
echo "Starting SQL Server Docker container..."
docker run -e 'ACCEPT_EULA=Y' -e "SA_PASSWORD=$(macpwd)" \
-p 1433:1433 --name sqlserver \
-d mcr.microsoft.com/mssql/server:2022-latest
echo "Waiting for SQL Server to start..."
sleep 30
docker ps -a
docker logs sqlserver || true
echo "SQL Server container started!"
displayName: 'Start SQL Server in Docker'
#########################################
# Install ODBC Driver and Tools
#########################################
- script: |
set -e
echo "Installing Microsoft ODBC Driver 18 for SQL Server..."
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18
# Verify installation
if [[ $(brew list --verbose msodbcsql18) ]]; then
echo "ODBC driver is installed successfully"
else
echo "ODBC driver did not install properly"
exit 1
fi
if [[ $(brew list --verbose mssql-tools18) ]]; then
echo "TOOLS installed successfully"
else
echo "TOOLS did not install properly"
exit 1
fi
# OpenSSL workaround for ODBC driver compatibility
echo "Configuring OpenSSL..."
brew reinstall openssl@1.1 || true
# Add tools to PATH
echo "##vso[task.prependpath]/opt/homebrew/opt/mssql-tools18/bin"
echo "##vso[task.prependpath]/usr/local/opt/mssql-tools18/bin"
displayName: 'Install ODBC Driver 18 and Tools'
- script: |
set -e
echo "Verifying SQL Server connection..."
# Wait a bit more for SQL Server to be fully ready
sleep 10
# Try to connect
/opt/homebrew/opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 \
-U $(uid) -P "$(macpwd)" -No -C \
-Q "SELECT @@Version" || \
/usr/local/opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 \
-U $(uid) -P "$(macpwd)" -No -C \
-Q "SELECT @@Version"
echo "SQL Server connection verified!"
displayName: 'Verify SQL Server Connection'
#########################################
# Build PHP from Source
#########################################
- script: |
set -e
cd $(Build.SourcesDirectory)
echo "Cloning PHP $(phpver) source..."
PHP_BRANCH="PHP-$(phpver)"
echo "Cloning PHP branch: $PHP_BRANCH (shallow clone for speed)"
git clone https://github.com/php/php-src.git -b $PHP_BRANCH --single-branch --depth 1 --filter=blob:none
echo "PHP source cloned!"
displayName: 'Clone PHP Source'
- script: |
set -e
cd $(REPO_ROOT)/source
echo "Running packagize.sh..."
chmod +x packagize.sh
./packagize.sh
echo "Copying sqlsrv to PHP extensions..."
cp -R sqlsrv $(Build.SourcesDirectory)/php-src/ext/
echo "Copying pdo_sqlsrv to PHP extensions..."
cp -R pdo_sqlsrv $(Build.SourcesDirectory)/php-src/ext/
echo "Driver source prepared!"
ls -la $(Build.SourcesDirectory)/php-src/ext/sqlsrv
ls -la $(Build.SourcesDirectory)/php-src/ext/pdo_sqlsrv
displayName: 'Prepare Driver Source'
- script: |
set -e
cd $(Build.SourcesDirectory)/php-src
echo "Configuring PHP build environment..."
export PATH="/usr/local/opt/bison/bin:/opt/homebrew/opt/bison/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/bison/lib -L/opt/homebrew/opt/bison/lib"
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig:/opt/homebrew/opt/icu4c/lib/pkgconfig"
echo "Running buildconf..."
./buildconf --force
echo "Configuring PHP $(phpver)..."
./configure \
--disable-all \
--enable-cli \
--enable-pdo \
--enable-sqlsrv=shared \
--with-pdo_sqlsrv=shared
echo "Building PHP..."
make -j$(sysctl -n hw.ncpu)
echo "Build complete!"
ls -la modules/
# Copy drivers to output
mkdir -p $(Build.SourcesDirectory)/out
cp modules/sqlsrv.so $(Build.SourcesDirectory)/out/
cp modules/pdo_sqlsrv.so $(Build.SourcesDirectory)/out/
echo "Drivers built:"
ls -la $(Build.SourcesDirectory)/out/
displayName: 'Build PHP with Drivers'
- script: |
set -e
cd $(Build.SourcesDirectory)/php-src
php_path=sapi/cli/php
if [[ ! -f $php_path ]]; then
echo "PHP build failed!"
exit 1
fi
echo "PHP build successful!"
$php_path --version
# Set PHP path for later tasks
echo "##vso[task.setvariable variable=PHP_PATH]$(Build.SourcesDirectory)/php-src/sapi/cli/php"
echo "##vso[task.setvariable variable=PHP_DIR]$(Build.SourcesDirectory)/php-src"
displayName: 'Verify PHP Build'
#########################################
# Configure PHP Extensions
#########################################
- script: |
set -e
cd $(Build.SourcesDirectory)/php-src
echo "Creating php.ini..."
cp php.ini-development php.ini
echo "extension=$(Build.SourcesDirectory)/php-src/modules/sqlsrv.so" >> php.ini
echo "extension=$(Build.SourcesDirectory)/php-src/modules/pdo_sqlsrv.so" >> php.ini
echo "Verifying extensions..."
sapi/cli/php -c php.ini -m | grep -i sqlsrv
sapi/cli/php -c php.ini --ri sqlsrv
sapi/cli/php -c php.ini --ri pdo_sqlsrv
echo "Extensions configured successfully!"
displayName: 'Configure PHP Extensions'
#########################################
# Setup Test Databases
#########################################
- script: |
set -e
cd $(REPO_ROOT)/test/functional/setup
export TEST_PHP_SQL_SERVER='127.0.0.1'
export TEST_PHP_SQL_UID='$(uid)'
export TEST_PHP_SQL_PWD='$(macpwd)'
# Add sqlcmd and bcp tools to PATH
export PATH="/opt/homebrew/opt/mssql-tools18/bin:/usr/local/opt/mssql-tools18/bin:$PATH"
echo "Setting up database $(macOS_sqlsrv_db)..."
python3 setup_dbs.py -dbname $(macOS_sqlsrv_db)
echo "Setting up database $(macOS_pdo_sqlsrv_db)..."
python3 setup_dbs.py -dbname $(macOS_pdo_sqlsrv_db)
echo "Test databases created!"
displayName: 'Setup Test Databases'
#########################################
# Configure Test Connection Settings
#########################################
- script: |
set -e
cd $(REPO_ROOT)/test/functional
SQL_SERVER="127.0.0.1"
SQL_USER="$(uid)"
SQL_PWD="$(macpwd)"
SRV_DB="$(macOS_sqlsrv_db)"
PDO_DB="$(macOS_pdo_sqlsrv_db)"
echo "Configuring sqlsrv MsSetup.inc..."
sed -i '' -e "s/TARGET_SERVER/${SQL_SERVER}/g" sqlsrv/MsSetup.inc
sed -i '' -e "s/TARGET_DATABASE/${SRV_DB}/g" sqlsrv/MsSetup.inc
sed -i '' -e "s/TARGET_USERNAME/${SQL_USER}/g" sqlsrv/MsSetup.inc
sed -i '' -e "s/TARGET_PASSWORD/${SQL_PWD}/g" sqlsrv/MsSetup.inc
echo "Configuring pdo_sqlsrv MsSetup.inc..."
sed -i '' -e "s/TARGET_SERVER/${SQL_SERVER}/g" pdo_sqlsrv/MsSetup.inc
sed -i '' -e "s/TARGET_DATABASE/${PDO_DB}/g" pdo_sqlsrv/MsSetup.inc
sed -i '' -e "s/TARGET_USERNAME/${SQL_USER}/g" pdo_sqlsrv/MsSetup.inc
sed -i '' -e "s/TARGET_PASSWORD/${SQL_PWD}/g" pdo_sqlsrv/MsSetup.inc
echo "=== sqlsrv/MsSetup.inc (first 50 lines) ==="
head -50 sqlsrv/MsSetup.inc
echo ""
echo "Test configuration completed"
displayName: 'Configure Test Connection Settings'
#########################################
# Get run-tests.php
#########################################
- script: |
set -e
cd $(Build.SourcesDirectory)
# Copy from PHP build
if [[ -f php-src/run-tests.php ]]; then
cp php-src/run-tests.php $(REPO_ROOT)/test/functional/
else
echo "Downloading run-tests.php..."
curl -o run-tests.php https://raw.githubusercontent.com/php/php-src/master/run-tests.php
cp run-tests.php $(REPO_ROOT)/test/functional/
fi
ls -la $(REPO_ROOT)/test/functional/run-tests.php
displayName: 'Get run-tests.php'
#########################################
# Run PHP Functional Tests
#########################################
- script: |
set -e
echo "Running tests..."
PHP_BIN=$(Build.SourcesDirectory)/php-src/sapi/cli/php
PHP_INI=$(Build.SourcesDirectory)/php-src/php.ini
cd $(REPO_ROOT)/test/functional
export TEST_PHP_EXECUTABLE=$PHP_BIN
export LC_ALL='en_US.UTF-8'
export LANG='en_US.UTF-8'
export LANGUAGE='en_US:en'
# Connection environment variables
export MSSQL_SERVER='127.0.0.1'
export MSSQL_USER='$(uid)'
export MSSQL_PASSWORD='$(macpwd)'
export MSSQL_DATABASE_NAME='$(macOS_sqlsrv_db)'
export MSSQL_DRIVER_NAME='ODBC Driver 18 for SQL Server'
export TEST_PHP_SQL_SERVER='127.0.0.1'
export TEST_PHP_SQL_UID='$(uid)'
export TEST_PHP_SQL_PWD='$(macpwd)'
# Verify connection before running tests
echo "Verifying database connection before tests..."
$PHP_BIN -c $PHP_INI -r "
\$server = '127.0.0.1';
\$options = array('Database' => '$(macOS_sqlsrv_db)', 'UID' => '$(uid)', 'PWD' => '$(macpwd)', 'Encrypt' => 'no');
\$conn = sqlsrv_connect(\$server, \$options);
if (\$conn === false) {
print_r(sqlsrv_errors());
exit(1);
}
echo 'SQL Server connection successful!' . PHP_EOL;
sqlsrv_close(\$conn);
"
# Verify extensions are loaded
echo "Verifying extensions are loaded..."
$PHP_BIN -c $PHP_INI -m | grep -i sqlsrv
# Set PHPRC so child processes find php.ini
export PHPRC=$(dirname $PHP_INI)
echo "PHPRC set to: $PHPRC"
# Set TEST_PHP_ARGS
export TEST_PHP_ARGS="-c $PHP_INI"
echo "Running sqlsrv tests..."
$PHP_BIN run-tests.php -p $PHP_BIN -c $PHP_INI -P sqlsrv/*.phpt --no-color 2>&1 | tee sqlsrv-macos.log || true
# Show diff files
for f in sqlsrv/*.diff; do
if [[ -f "$f" ]]; then
echo "=== DIFF: $f ==="
cat "$f"
fi
done
# Update environment for pdo tests
export MSSQL_DATABASE_NAME='$(macOS_pdo_sqlsrv_db)'
echo "Running pdo_sqlsrv tests..."
$PHP_BIN run-tests.php -p $PHP_BIN -c $PHP_INI -P pdo_sqlsrv/*.phpt --no-color 2>&1 | tee pdo_sqlsrv-macos.log || true
# Show diff files
for f in pdo_sqlsrv/*.diff; do
if [[ -f "$f" ]]; then
echo "=== DIFF: $f ==="
cat "$f"
fi
done
echo "Tests completed!"
displayName: 'Run PHP Functional Tests'
#########################################
# Process and Publish Results
#########################################
- script: |
echo "Processing test results..."
mkdir -p $(Build.SourcesDirectory)/out/Logs
cd $(REPO_ROOT)/test/functional/
cp *.log $(Build.SourcesDirectory)/out/Logs/ 2>/dev/null || true
for f in sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; echo ''; done || true
for f in pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; echo ''; done || true
# Generate JUnit XML
python3 output.py
ls -l *.xml
displayName: 'Process Test Logs'
condition: always()
- task: PublishTestResults@2
displayName: 'Publish Test Results'
condition: always()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/*.xml'
searchFolder: '$(REPO_ROOT)/test/functional/'
failTaskOnFailedTests: false
testRunTitle: 'macOS-PHP$(phpver)'
#########################################
# Cleanup
#########################################
- script: |
cd $(REPO_ROOT)/test/functional/
rm -f *.log *.xml 2>/dev/null || true
displayName: 'Cleanup Test Files'
condition: always()
- script: |
export TEST_PHP_SQL_SERVER='127.0.0.1'
export TEST_PHP_SQL_UID='$(uid)'
export TEST_PHP_SQL_PWD='$(macpwd)'
echo "Dropping test databases..."
python3 $(REPO_ROOT)/test/functional/setup/cleanup_dbs.py -dbname $(macOS_sqlsrv_db) || true
python3 $(REPO_ROOT)/test/functional/setup/cleanup_dbs.py -dbname $(macOS_pdo_sqlsrv_db) || true
displayName: 'Drop Test Databases'
condition: always()
- script: |
echo "Stopping SQL Server container..."
docker stop sqlserver 2>/dev/null || true
docker rm sqlserver 2>/dev/null || true
echo "Stopping Colima..."
colima stop 2>/dev/null || true
echo "Cleanup complete!"
displayName: 'Cleanup Docker'
condition: always()
- job: Linux
variables:
phpver: 8.5
pool:
vmImage: 'ubuntu-22.04'
steps:
- checkout: self
clean: true
fetchDepth: 1
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'
- script: |
echo "Installing PHP $(phpver) and dependencies..."
# Add ondrej/php PPA for PHP 8.5
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
# Install PHP 8.5 and required extensions
sudo apt-get install -y php$(phpver)-cli php$(phpver)-dev php$(phpver)-xml php$(phpver)-intl
# Set PHP 8.5 as default
sudo update-alternatives --set php /usr/bin/php$(phpver)
sudo update-alternatives --set phpize /usr/bin/phpize$(phpver)
sudo update-alternatives --set php-config /usr/bin/php-config$(phpver)
# Ensure conf.d directory exists for PHP 8.5
sudo mkdir -p /etc/php/$(phpver)/cli/conf.d
# Disable xdebug if present
sudo phpdismod xdebug 2>/dev/null || true
php -version
displayName: 'Install PHP $(phpver)'
- script: |
echo "Installing ODBC Driver 18 and dependencies..."
# 1ES images' Microsoft repos have priority 1001, causing apt to prefer
# unixodbc 2.3.7 from Microsoft over 2.3.9 from Ubuntu. Pin unixODBC
# packages to prefer Ubuntu's versions.
printf '%s\n' \
'Package: unixodbc unixodbc-dev unixodbc-common libodbc1 libodbc2 libodbcinst2 odbcinst odbcinst1debian2' \
'Pin: origin packages.microsoft.com' \
'Pin-Priority: 100' \
| sudo tee /etc/apt/preferences.d/unixodbc-pin
if ! dpkg -s packages-microsoft-prod &>/dev/null; then
curl -sSL -O https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
fi
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 mssql-tools18 unixodbc-dev
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
odbcinst -j
odbcinst -q -d -n "ODBC Driver 18 for SQL Server"
displayName: 'Install ODBC Driver 18'
- powershell: |
$guid = [guid]::NewGuid().ToString()
Write-Host "##vso[task.setvariable variable=pwd;issecret=true]$guid"
displayName: 'Generate Password'
- script: |
# Start SQL Server container (only SQL Server in Docker, not tests)
docker pull mcr.microsoft.com/mssql/server:2022-latest
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=$(pwd)' -p 1433:1433 -h $(host) --name=$(host) -d mcr.microsoft.com/mssql/server:2022-latest
docker ps -a
sleep 10
# Verify SQL Server is running
docker exec -t $(host) /opt/mssql-tools18/bin/sqlcmd -S $(server) -C -U $(uid) -P $(pwd) -Q 'SELECT @@VERSION'
displayName: 'Run SQL Server for Linux'
- script: |
echo "Generating locales for testing..."
# Enable required locales in locale.gen
sudo sed -i 's/# en_US ISO-8859-1/en_US ISO-8859-1/g' /etc/locale.gen
sudo sed -i 's/# en_US.ISO-8859-1 ISO-8859-1/en_US.ISO-8859-1 ISO-8859-1/g' /etc/locale.gen
sudo sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
sudo sed -i 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/g' /etc/locale.gen
sudo sed -i 's/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g' /etc/locale.gen
sudo sed -i 's/# fr_FR ISO-8859-1/fr_FR ISO-8859-1/g' /etc/locale.gen
sudo sed -i 's/# fr_FR@euro ISO-8859-15/fr_FR@euro ISO-8859-15/g' /etc/locale.gen
sudo sed -i 's/# fr_FR.ISO-8859-15 ISO-8859-15/fr_FR.ISO-8859-15 ISO-8859-15/g' /etc/locale.gen
sudo sed -i 's/# zh_CN GB2312/zh_CN GB2312/g' /etc/locale.gen
sudo sed -i 's/# zh_CN.GB18030 GB18030/zh_CN.GB18030 GB18030/g' /etc/locale.gen
sudo sed -i 's/# zh_CN.gb18030 GB18030/zh_CN.gb18030 GB18030/g' /etc/locale.gen
sudo sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
# Generate all locales
sudo locale-gen
# Verify locales were generated
echo "Available locales:"
locale -a | grep -E "en_US|de_DE|fr_FR|zh_CN" || true
displayName: 'Generate locales for testing'
- script: |
echo "Setting up test databases..."
export TEST_PHP_SQL_SERVER='$(server)'
export TEST_PHP_SQL_UID='$(uid)'
export TEST_PHP_SQL_PWD='$(pwd)'
cd $(Build.SourcesDirectory)/test/functional/setup
python3 ./setup_dbs.py -dbname $(sqlsrv_db)
python3 ./setup_dbs.py -dbname $(pdo_sqlsrv_db)
displayName: 'Set up test databases'
- script: |
echo "Building PHP extensions..."
cd $(Build.SourcesDirectory)/source
chmod a+x packagize.sh
./packagize.sh
# Get the PHP conf.d directory, removing any quotes and whitespace
dest=$(php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||" | tr -d '[:space:]"')
echo "PHP conf.d directory: $dest"
# Verify the directory exists
if [ ! -d "$dest" ]; then
echo "Creating conf.d directory: $dest"
sudo mkdir -p "$dest"
fi
cd $(Build.SourcesDirectory)/source/sqlsrv
phpize && ./configure LDFLAGS="-lgcov" CXXFLAGS="-O0 --coverage" && make && sudo make install
cp run-tests.php $(Build.SourcesDirectory)/test/functional/sqlsrv/
echo extension=sqlsrv.so | sudo tee "$dest/20-sqlsrv.ini"
cd $(Build.SourcesDirectory)/source/pdo_sqlsrv
phpize && ./configure LDFLAGS="-lgcov" CXXFLAGS="-O0 --coverage" && make && sudo make install
cp run-tests.php $(Build.SourcesDirectory)/test/functional/pdo_sqlsrv/
echo extension=pdo_sqlsrv.so | sudo tee "$dest/30-pdo_sqlsrv.ini"
sudo touch "$dest/99-overrides.ini"
sudo chmod 666 "$dest/99-overrides.ini"
php --ri sqlsrv
php --ri pdo_sqlsrv
displayName: 'Build and install drivers'
- script: |
echo "Updating MsSetup.inc files..."
cd $(Build.SourcesDirectory)/test/functional/sqlsrv
sed -i -e 's/TARGET_SERVER/'"$(server)"'/g' MsSetup.inc
sed -i -e 's/TARGET_DATABASE/'"$(sqlsrv_db)"'/g' MsSetup.inc
sed -i -e 's/TARGET_USERNAME/'"$(uid)"'/g' MsSetup.inc
sed -i -e 's/TARGET_PASSWORD/'"$(pwd)"'/g' MsSetup.inc
cd $(Build.SourcesDirectory)/test/functional/pdo_sqlsrv
sed -i -e 's/TARGET_SERVER/'"$(server)"'/g' MsSetup.inc
sed -i -e 's/TARGET_DATABASE/'"$(pdo_sqlsrv_db)"'/g' MsSetup.inc
sed -i -e 's/TARGET_USERNAME/'"$(uid)"'/g' MsSetup.inc
sed -i -e 's/TARGET_PASSWORD/'"$(pwd)"'/g' MsSetup.inc
echo "MsSetup.inc files updated"
displayName: 'Update test configuration files'
- script: |
cd $(Build.SourcesDirectory)/test/functional/sqlsrv
export MSSQL_SERVER='$(server)'
export MSSQL_USER='$(uid)'
export MSSQL_PASSWORD='$(pwd)'
export MSSQL_DATABASE_NAME='$(sqlsrv_db)'
export MSSQL_DRIVER_NAME='ODBC Driver 18 for SQL Server'
export TZ='Asia/Shanghai'
export LC_ALL='en_US.UTF-8'
php run-tests.php *.phpt --no-color --show-diff --set-timeout 600 2>&1 | tee ../sqlsrv.log
displayName: 'Run sqlsrv functional tests'
- script: |
cd $(Build.SourcesDirectory)/test/functional/pdo_sqlsrv
export MSSQL_SERVER='$(server)'
export MSSQL_USER='$(uid)'
export MSSQL_PASSWORD='$(pwd)'
export MSSQL_DATABASE_NAME='$(pdo_sqlsrv_db)'
export MSSQL_DRIVER_NAME='ODBC Driver 18 for SQL Server'
export TZ='Asia/Shanghai'
export LC_ALL='en_US.UTF-8'
php run-tests.php *.phpt --no-color --show-diff --set-timeout 600 2>&1 | tee ../pdo_sqlsrv.log
displayName: 'Run pdo_sqlsrv functional tests'
- script: |
pip install gcovr
cd $(Build.SourcesDirectory)/source
gcovr --root . \
--filter 'sqlsrv/' --filter 'pdo_sqlsrv/' --filter 'shared/' \
--exclude '.*test/.*' \
--exclude '.*localization.*' --exclude '.*globalization.*' \
--cobertura -o $(Build.SourcesDirectory)/coverage.xml
echo "Coverage report generated:"
ls -la $(Build.SourcesDirectory)/coverage.xml
displayName: 'Collect code coverage'
- script: |
docker logs -t $(host)
cd $(Build.SourcesDirectory)/test/functional/
for f in sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; echo ''; done || true
for f in pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; echo ''; done || true
python output.py
ls -l *.xml
displayName: 'Processing test results'
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
failTaskOnFailedTests: true
searchFolder: '$(Build.SourcesDirectory)/test/functional/'
- script: |
docker stop $(host)
docker rm $(host)
displayName: 'Stop SQL Server for Linux'
condition: always()
- script: |
mkdir -p $(Build.SourcesDirectory)/coverage-artifacts
cp $(Build.SourcesDirectory)/coverage*.xml $(Build.SourcesDirectory)/coverage-artifacts/ 2>/dev/null || true
ls -la $(Build.SourcesDirectory)/coverage-artifacts/
displayName: 'Stage coverage artifacts'
condition: always()
- task: PublishPipelineArtifact@1
displayName: 'Publish coverage artifacts'
inputs:
targetPath: '$(Build.SourcesDirectory)/coverage-artifacts'
artifact: 'coverage-linux'
publishLocation: 'pipeline'
condition: always()
- job: Windows
variables:
phpVersion: 8.5
pool:
vmImage: 'windows-latest'
steps:
- checkout: self
clean: true
fetchDepth: 1
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
architecture: 'x64'
- powershell: |
# Download and install PHP 8.5 to match the drivers we're building
$client = New-Object Net.WebClient
$client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0")
$client.DownloadFile("http://windows.php.net/downloads/releases/releases.json", "releases.json");
$jsondata = Get-Content -Path .\releases.json | ConvertFrom-Json
# Get the PHP version string properly
$phpVer = "$(phpVersion)"
Write-Host "Looking for PHP version: $phpVer"
# Access the version property correctly
$version = $jsondata.$phpVer.version
if (-not $version) {
Write-Host "##[error]Could not find PHP $phpVer in releases.json"
Write-Host "Available versions:"
$jsondata.PSObject.Properties.Name | ForEach-Object { Write-Host " $_" }
throw "PHP version $phpVer not found"
}
Write-Host "Installing PHP $(phpVersion) version $version"
# PHP 8.5+ uses VS17, earlier versions use VS16
$vsVersion = if ([version]$version -ge [version]"8.5.0") { "vs17" } else { "vs16" }
# Download PHP NTS x64
$phpUrl = "https://windows.php.net/downloads/releases/php-$version-nts-Win32-$vsVersion-x64.zip"
Write-Host "Downloading from: $phpUrl"
try {
# Set user agent again for the PHP download
$client.Headers.Set("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0")
$client.DownloadFile($phpUrl, "php.zip")
$fileSize = (Get-Item php.zip).Length
Write-Host "Download completed. File size: $fileSize bytes"
# Validate file size (should be at least 20MB for a valid PHP zip)
if ($fileSize -lt 20000000) {
Write-Host "##[error]Downloaded file is too small ($fileSize bytes). This is likely an error page."
Get-Content php.zip | Select-Object -First 10 | Write-Host
throw "Invalid PHP zip file downloaded"
}
} catch {
Write-Host "##[error]Failed to download PHP: $_"
throw
}
# Extract to C:\tools\php
if (Test-Path C:\tools\php) {
Remove-Item C:\tools\php -Recurse -Force
}
Expand-Archive -Path php.zip -DestinationPath C:\tools\php -Force
# Configure php.ini
if (Test-Path C:\tools\php\php.ini-development) {
Copy-Item C:\tools\php\php.ini-development C:\tools\php\php.ini -Force
}
Add-Content C:\tools\php\php.ini "`nextension_dir=C:\tools\php\ext"
php -v
displayName: 'Install PHP $(phpVersion)'
- powershell: |
$guid = [guid]::NewGuid().ToString()
Write-Host "##vso[task.setvariable variable=pwd;issecret=true]$guid"
displayName: 'Generate Password'
- powershell: |
Write-Host "Starting SQL Server LocalDB..."
# Create and start LocalDB instance
sqllocaldb create MSSQLLocalDB
sqllocaldb start MSSQLLocalDB
# Wait for it to be ready
Start-Sleep -Seconds 5
# Get instance info
sqllocaldb info MSSQLLocalDB
# Enable SQL Authentication and set sa password
Write-Host "Configuring SQL Authentication..."
sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "ALTER LOGIN sa WITH PASSWORD = N'$(pwd)'; ALTER LOGIN sa ENABLE;"
sqlcmd -S "(localdb)\MSSQLLocalDB" -Q "EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2"
# Restart LocalDB to apply changes
Write-Host "Restarting LocalDB to apply authentication changes..."
sqllocaldb stop MSSQLLocalDB
sqllocaldb start MSSQLLocalDB
Start-Sleep -Seconds 5
# Test connection with SQL Auth using named pipe
Write-Host "Testing connection to LocalDB with SQL Authentication..."
sqlcmd -S "(localdb)\MSSQLLocalDB" -U $(uid) -P "$(pwd)" -Q "SELECT @@VERSION"
Write-Host "SQL Server LocalDB is ready"
displayName: 'Start SQL Server LocalDB'
- powershell: |
# Update connection strings to use LocalDB named pipe
$server = "(localdb)\MSSQLLocalDB"
cd $(Build.SourcesDirectory)\test\functional\sqlsrv
(Get-Content .\MsSetup.inc) | ForEach-Object {
$_ -replace "TARGET_SERVER", $server `
-replace "TARGET_DATABASE", "$(sqlsrv_db)" `
-replace "TARGET_USERNAME", "$(uid)" `
-replace "TARGET_PASSWORD", "$(pwd)"
} | Set-Content .\MsSetup.inc
Write-Host "Updated sqlsrv MsSetup.inc:"
Select-String "server|Database" .\MsSetup.inc
cd $(Build.SourcesDirectory)\test\functional\pdo_sqlsrv
(Get-Content .\MsSetup.inc) | ForEach-Object {
$_ -replace "TARGET_SERVER", $server `
-replace "TARGET_DATABASE", "$(pdo_sqlsrv_db)" `
-replace "TARGET_USERNAME", "$(uid)" `
-replace "TARGET_PASSWORD", "$(pwd)"
} | Set-Content .\MsSetup.inc
Write-Host "Updated pdo_sqlsrv MsSetup.inc:"
Select-String "server|Database" .\MsSetup.inc
cd $(Build.SourcesDirectory)\test\bvt\sqlsrv
(Get-Content .\connect.inc) | ForEach-Object {
$_ -replace '(\$server = )[^;]+;', "`$1'$server';" `
-replace '(\$databaseName = )[^;]+;', "`$1'$(sqlsrv_db)';" `
-replace '(\$uid = )[^;]+;', "`$1'$(uid)';" `
-replace '(\$pwd = )[^;]+;', "`$1'$(pwd)';"
} | Set-Content .\connect.inc
cd $(Build.SourcesDirectory)\test\bvt\pdo_sqlsrv
(Get-Content .\connect.inc) | ForEach-Object {
$_ -replace '(\$server = )[^;]+;', "`$1'$server';" `
-replace '(\$databaseName = )[^;]+;', "`$1'$(pdo_sqlsrv_db)';" `
-replace '(\$uid = )[^;]+;', "`$1'$(uid)';" `
-replace '(\$pwd = )[^;]+;', "`$1'$(pwd)';"
} | Set-Content .\connect.inc
displayName: 'Update connection credentials'
- powershell: |
Write-Host "Downloading ODBC Driver 18 for SQL Server..."
$client = New-Object Net.WebClient
# Download ODBC Driver 18 MSI
$client.DownloadFile('https://go.microsoft.com/fwlink/?linkid=2345415', '$(Build.SourcesDirectory)\msodbcsql.msi')
Write-Host "Downloaded msodbcsql.msi"
dir $(Build.SourcesDirectory)\msodbcsql.msi
displayName: 'Download ODBC Driver 18 MSI'
- script: |
cd $(Build.SourcesDirectory)
msiexec /i "msodbcsql.msi" /q IACCEPTMSODBCSQLLICENSETERMS=YES ADDLOCAL=ALL
echo "Verifying ODBC Driver 18 installation..."
reg query "HKLM\SOFTWARE\ODBC\odbcinst.ini\ODBC Driver 18 for SQL Server"
dir %WINDIR%\System32\msodbcsql*.dll
displayName: 'Install ODBC Driver 18'
- powershell: |
Write-Host "Verifying ODBC Driver 18 installation..."
Get-OdbcDriver | Where-Object { $_.Name -like "*SQL Server*" } | Format-Table Name, Platform -AutoSize
$driver18 = Get-OdbcDriver | Where-Object { $_.Name -eq "ODBC Driver 18 for SQL Server" }
if (-not $driver18) {
Write-Host "##[error]ODBC Driver 18 for SQL Server NOT found after installation!"
exit 1
}
Write-Host "✓ ODBC Driver 18 for SQL Server installed successfully"
displayName: 'Verify ODBC Driver 18 installation'
- powershell: |
$client = New-Object Net.WebClient
$client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0")
$client.DownloadFile("http://windows.php.net/downloads/releases/releases.json", "releases.json");
$jsondata = Get-Content -Path .\releases.json | ConvertFrom-Json
$env:VERSION = $jsondata.{$(phpVersion)}.version
Write-Host "Latest PHP $(phpVersion) is ${env:VERSION}"
cd $(Build.SourcesDirectory)\buildscripts\
python -u builddrivers.py --PHPVER=${env:VERSION} --DRIVER=sqlsrv --ARCH=x64 --THREAD=nts --SOURCE=$(Build.SourcesDirectory)\source --TESTING --NO_RENAME
if ($LASTEXITCODE -ne 0) { throw "sqlsrv build failed" }
Write-Host "Listing built DLLs and PDBs:"
dir *.dll,*.pdb
# Copy sqlsrv DLL and PDB immediately (before pdo_sqlsrv build overwrites the build tree)
Write-Host "Copying sqlsrv DLL and PDB to C:\tools\php\ext\"
Copy-Item *sqlsrv*.dll C:\tools\php\ext\ -Verbose
Copy-Item *sqlsrv*.pdb C:\tools\php\ext\ -Verbose -ErrorAction SilentlyContinue
python -u builddrivers.py --PHPVER=${env:VERSION} --DRIVER=pdo_sqlsrv --ARCH=x64 --THREAD=nts --SOURCE=$(Build.SourcesDirectory)\source --TESTING --NO_RENAME
if ($LASTEXITCODE -ne 0) { throw "pdo_sqlsrv build failed" }
Write-Host "Listing built DLLs and PDBs:"
dir *.dll,*.pdb
# Copy pdo_sqlsrv DLL and PDB
Write-Host "Copying pdo_sqlsrv DLL and PDB to C:\tools\php\ext\"
Copy-Item *pdo_sqlsrv*.dll C:\tools\php\ext\ -Verbose
Copy-Item *pdo_sqlsrv*.pdb C:\tools\php\ext\ -Verbose -ErrorAction SilentlyContinue
Write-Host "Verifying DLLs and PDBs in destination:"
dir C:\tools\php\ext\*sqlsrv*
# Add extensions to php.ini
Write-Host "Adding extensions to php.ini"
Add-Content C:\tools\php\php.ini "extension=php_sqlsrv.dll"
Add-Content C:\tools\php\php.ini "extension=php_pdo_sqlsrv.dll"
# Verify extensions are loaded
Write-Host "Verifying extensions:"
php --ri sqlsrv
php --ri pdo_sqlsrv
# Copy run-tests.php to test directories
Copy-Item $(Build.SourcesDirectory)\buildscripts\php-sdk\phpdev\vs17\x64\php-${env:VERSION}-src\run-tests.php $(Build.SourcesDirectory)\test\functional\sqlsrv -Verbose
Copy-Item $(Build.SourcesDirectory)\buildscripts\php-sdk\phpdev\vs17\x64\php-${env:VERSION}-src\run-tests.php $(Build.SourcesDirectory)\test\functional\pdo_sqlsrv -Verbose
displayName: 'Build drivers for PHP $(phpVersion)'
- powershell: |
Write-Host "Setting up test databases..."
# Set environment variables for the Python script
$env:TEST_PHP_SQL_SERVER = "(localdb)\MSSQLLocalDB"
$env:TEST_PHP_SQL_UID = "$(uid)"
$env:TEST_PHP_SQL_PWD = "$(pwd)"
cd $(Build.SourcesDirectory)\test\functional\setup
python setup_dbs.py -dbname $(sqlsrv_db)
python setup_dbs.py -dbname $(pdo_sqlsrv_db)
Write-Host "Database setup complete!"
displayName: 'Set up test databases'
- powershell: |
Write-Host "Installing OpenCppCoverage..."
choco install opencppcoverage -y
$env:Path = "C:\Program Files\OpenCppCoverage;$env:Path"
# Verify install by checking the executable exists
if (Test-Path "C:\Program Files\OpenCppCoverage\OpenCppCoverage.exe") {
Write-Host "OpenCppCoverage installed successfully"
} else {
throw "OpenCppCoverage executable not found"
}
displayName: 'Install OpenCppCoverage'
- script: |
set PATH=C:\Program Files\OpenCppCoverage;%PATH%
cd $(Build.SourcesDirectory)\test\functional\sqlsrv
set MSSQL_SERVER=(localdb)\MSSQLLocalDB
set MSSQL_USER=$(uid)
set MSSQL_PASSWORD=$(pwd)
set MSSQL_DATABASE_NAME=$(sqlsrv_db)
OpenCppCoverage --sources $(Build.SourcesDirectory)\buildscripts --modules php_sqlsrv.dll --cover_children --export_type cobertura:$(Build.SourcesDirectory)\coverage-sqlsrv.xml -- php run-tests.php *.phpt --no-color --show-diff 2>&1 | tee ..\sqlsrv.log
displayName: 'Run sqlsrv functional tests'
- script: |
set PATH=C:\Program Files\OpenCppCoverage;%PATH%
cd $(Build.SourcesDirectory)\test\functional\pdo_sqlsrv
set MSSQL_SERVER=(localdb)\MSSQLLocalDB
set MSSQL_USER=$(uid)
set MSSQL_PASSWORD=$(pwd)
set MSSQL_DATABASE_NAME=$(pdo_sqlsrv_db)
OpenCppCoverage --sources $(Build.SourcesDirectory)\buildscripts --modules php_pdo_sqlsrv.dll --cover_children --export_type cobertura:$(Build.SourcesDirectory)\coverage-pdo_sqlsrv.xml -- php run-tests.php *.phpt --no-color --show-diff 2>&1 | tee ..\pdo_sqlsrv.log
displayName: 'Run pdo_sqlsrv functional tests'
- script: |
cd $(Build.SourcesDirectory)\test\functional\
dir sqlsrv\*.diff 2>nul && type sqlsrv\*.diff || echo No sqlsrv diff files
dir pdo_sqlsrv\*.diff 2>nul && type pdo_sqlsrv\*.diff || echo No pdo_sqlsrv diff files
cd $(Build.SourcesDirectory)\test\bvt\
dir sqlsrv\*.diff 2>nul && type sqlsrv\*.diff || echo No BVT sqlsrv diff files
dir pdo_sqlsrv\*.diff 2>nul && type pdo_sqlsrv\*.diff || echo No BVT pdo_sqlsrv diff files
cd $(Build.SourcesDirectory)\test\functional\
python output.py
dir *.xml
displayName: 'Processing test results'
- task: PublishTestResults@2