forked from Dolibarr/dolibarr
-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (164 loc) · 7.17 KB
/
windows-ci.yaml
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
---
name: Win CI
on:
push:
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
PHPUNIT_LOG: phpunit_tests.log
DOLIBARR_LOG: documents/dolibarr.log
PHPSERVER_LOG: phpserver.log
PHPSERVER_DOMAIN_PORT: 127.0.0.1:8000 # could be 127.0.0.1:8000 if config modified
CACHE_KEY_PART: ${{ ( github.event_name == 'pull_request' ) && github.base_ref }}${{ ( github.event_name == 'pull_request' ) && '-' }}${{ github.head_ref }}
PHP_INI_SCAN_DIR: "C:\\myphpini"
CKEY: win-ci-2
jobs:
win-test:
strategy:
matrix:
os: [windows-latest]
# php_version: [7.4, 8.0] # Add more versions if needed
php_version: [7.4] # Add more versions if needed
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup MariaDB
uses: ankane/setup-mariadb@v1
with:
# mariadb-version: ${{ matrix.mariadb-version }}
database: travis # Specify your database name
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
# ini-values: post_max_size=256M, max_execution_time=180
extensions: >
calendar, gd, imagick, imap, intl, json, ldap, mbstring,
mcrypt, mysql, mysqli, opcache, pgsql, sqlite3, xml, zip
tools: >
composer,
phpunit:9.5
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# phpts: ts # ts for thread-safe, default nts
# Restore cache
- name: Restore cache
id: cache
uses: actions/cache/restore@v4
with:
path: |
db_init.sql
db_init.sql.md5
key: ${{ matrix.os }}-${{ env.ckey }}-${{ matrix.php_version }}-${{ env.CACHE_KEY_PART }}-${{ github.run_id }}
restore-keys: |
${{ matrix.os }}-${{ env.ckey }}-${{ matrix.php_version }}-${{ env.CACHE_KEY_PART }}-
${{ matrix.os }}-${{ env.ckey }}-${{ matrix.php_version }}-${{ github.head_ref }}-
${{ matrix.os }}-${{ env.ckey }}-${{ matrix.php_version }}-${{ github.base_ref }}-
${{ matrix.os }}-${{ env.ckey }}-${{ matrix.php_version }}-
- name: Create local php.ini
shell: cmd
if: false
# Note: Setting the basedir before initialising the database results in open_basedir errors
# Objective: separate step, and before database initialisation to verify open_basedir restrictions
run: |-
ECHO "==== Show INI file usage before our configuration ==="
php --ini
ECHO "==== Set PHP_INI_SCAN_DIR to include the INI File we create ==="
mkdir %PHP_INI_SCAN_DIR%
SET INIFILE="%PHP_INI_SCAN_DIR%\dolibarr.ini"
SET HTDOCS_DIR=%CD%\htdocs
SET DATA_DIR=%CD%\documents
SET TEST_DIR=%CD%\test
SET INITDEMO_DIR=%CD%\dev\initdemo
ECHO "==== Create INI file to set open_basedir ==="
echo [php] > %INIFILE%
echo open_basedir^="%HTDOCS_DIR%;%DATA_DIR%;%TEST_DIR%;%INITDEMO_DIR%;%PHPROOT%" >> %INIFILE%
ECHO "==== Show contents of INI file to set open_basedir ==="
type %INIFILE%
REM Next line disables open_basedir limitation (to limit errors)
SET PHP_INI_SCAN_DIR=
ECHO "==== Verify it is used by PHP ==="
php --ini
- name: Run Bash script
# Note this is bash (MSYS) on Windows
shell: bash
# Note: Initialise the database (possibly from cache) and set some variables.
run: |
# Check if database cache is present (visually, to remove once ok)
ls -l
# Run bash script to initialise database
${SHELL} -xv dev/setup/phpunit/setup_conf.sh
sed -i -e 's/stopOnFailure="[^"]*"/stopOnFailure="false"/' test/phpunit/phpunittest.xml
# Check if database cache is present after the script (visually, to remove once ok)
ls -l
echo "TEE=$(cygpath -w "$(which tee)")" >> "$GITHUB_ENV"
echo "BASEDIR=$(realpath .)" >> "$GITHUB_ENV"
- name: Start web server
id: server
if: false
# Objective: Start php server in separate step (but after open_basedir restriction setup!)
run: |
Start-Process -FilePath "php.exe" -WindowStyle Hidden -ArgumentList "-S ${{ env.PHPSERVER_DOMAIN_PORT }} -t htdocs > ${{ env.PHPSERVER_LOG }}" -PassThru
curl "http://${{ env.PHPSERVER_DOMAIN_PORT }}"
shell: powershell
- name: Run PHPUnit tests
continue-on-error: true
shell: cmd
# setting up php.ini, starting the php server are currently in this step
run: |-
echo "BASEDIR=%CD%" >> %GITHUB_ENV%
start /B php -S %PHPSERVER_DOMAIN_PORT% -t htdocs >> %PHPSERVER_LOG% 2>&1
curl "http://${{ env.PHPSERVER_DOMAIN_PORT }}"
ECHO "==== Show INI file usage before our configuration ==="
php --ini
ECHO "==== Set PHP_INI_SCAN_DIR to include the INI File we create ==="
mkdir %PHP_INI_SCAN_DIR%
SET INIFILE="%PHP_INI_SCAN_DIR%\dolibarr.ini"
SET HTDOCS_DIR=%CD%\htdocs
SET DATA_DIR=%CD%\documents
SET TEST_DIR=%CD%\test
SET INITDEMO_DIR=%CD%\dev\initdemo
ECHO "==== Create INI file to set open_basedir ==="
echo [php] > %INIFILE%
echo open_basedir^="%HTDOCS_DIR%;%DATA_DIR%;%TEST_DIR%;%INITDEMO_DIR%;%PHPROOT%" >> %INIFILE%
REM Unset PHP_INI_SCAN_DIR to disable open_basedir restritions (to limit debug effort)
REM SET PHP_INI_SCAN_DIR=
ECHO "==== Show contents of INI file to set open_basedir ==="
type %INIFILE%
ECHO "==== Verify it is used by PHP ==="
php --ini
echo $dolibarr_main_url_root="http://${{ env.PHPSERVER_DOMAIN_PORT }}"; >> htdocs/conf/conf.php
cat htdocs/conf/conf.php
curl "http://${{ env.PHPSERVER_DOMAIN_PORT }}"
REM 'DOSKEY' USED to recover error code (no pipefile equivalent in windows?)
( php "%PHPROOT%\phpunit" -d memory_limit=-1 -c %CD%\test\phpunit\phpunittest.xml "test\phpunit\AllTests.php" & call doskey /exename=err err=%%^^errorlevel%% ) | "${{ env.TEE }}" "${{ env.PHPUNIT_LOG }}"
for /f "tokens=2 delims==" %%A in ('doskey /m:err') do EXIT /B %%A
- name: Convert Raw Log to Annotations
uses: mdeweerd/logToCheckStyle@v2024.2.9
if: ${{ failure() }}
with:
in: ${{ env.PHPUNIT_LOG }}
- name: Provide dolibarr and phpunit logs as artifact
uses: actions/upload-artifact@v4
if: ${{ ! cancelled() }}
with:
name: win-ci-logs
path: |
${{ env.PHPUNIT_LOG }}
${{ env.DOLIBARR_LOG }}
${{ env.PHPSERVER_LOG }}
db_init.sql
db_init.sql.md5
retention-days: 2
# Save cache
- name: "Save cache"
uses: actions/cache/save@v4
if: ${{ ! cancelled() }}
with:
key: ${{ steps.cache.outputs.cache-primary-key }}
path: db_init.*