Qual: Add exceptions for codespell (#28186)

* Dev: Add setup scripts for phpunit/database

# Dev: Add setup scripts for phpunit/database

Some scripts that helped to setup some unit testing.

* NEW Add Windows ci workflow

# NEW Add Windows ci workflow

This adds a workflow to execute ci on a windows platform

* Disable open_basedir for now, to test effect

* Qual: Exclude documents directory from codespell

# Qual: Exclude documents directory from codespell

Documents directory may be present during development (unit tests).
Do not check spelling there

* Qual: Add codespell exceptions

# Qual: Add codespell exceptions

Add new exceptions to codespell (var identified as misspelling).
This commit is contained in:
MDW 2024-02-15 14:49:09 +01:00 committed by GitHub
parent 306e594b8e
commit e5423d5c59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 327 additions and 1 deletions

127
.github/workflows/windows-ci.yaml vendored Normal file
View File

@ -0,0 +1,127 @@
---
name: Win CI
on:
push:
# branches:
# - main
pull_request:
# branches:
# - main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
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
- name: Get composer cache directory
id: composer-cache
if: false
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
if: false
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
if: false
run: |
composer -n config -g vendor-dir htdocs/includes
# composer self-update 2.4.4
composer -n require \
php-parallel-lint/php-parallel-lint ^1.2 \
php-parallel-lint/php-console-highlighter ^0 \
php-parallel-lint/php-var-dump-check ~0.4
# which phpunit phpcs php-parallel-lint
- run: |
where php
php -v
php -r 'phpinfo();'
echo ok
- name: "Windows: Cygwin download"
if: false && runner.os == 'Windows'
run: |
Invoke-WebRequest 'https://cygwin.com/setup-x86_64.exe' -OutFile 'setup-x86_64.exe'
- name: "Windows: Cygwin setup"
if: false && runner.os == 'Windows'
shell: cmd
#run: .\setup-x86_64.exe --quiet-mode --site http://cygwin.mirror.constant.com --symlink-type=sys --packages mingw64-i686-binutils=2.37-2,mingw64-x86_64-binutils=2.37-2,curl,diffutils,git,m4,make,mercurial,mingw64-i686-gcc-core,mingw64-i686-gcc-g++,mingw64-x86_64-gcc-core,mingw64-x86_64-gcc-g++,patch,perl,rsync,unzip
run: .\setup-x86_64.exe --quiet-mode --site http://cygwin.mirror.constant.com --symlink-type=sys --packages sed
- name: Setup MSYS (provides 'bash' and other unix-tools on windows)
uses: msys2/setup-msys2@v2
if: false
with:
path-type: inherit
cache: true
release: false
msystem: UCRT64
update: false
install: git mingw-w64-ucrt-x86_64-gcc
- name: Run Bash script
# shell: msys2 {0}
shell: bash
run: |
# Replace the following commands with your bash script commands
# Example:
# ./script.sh arg1 arg2
# would be
# bash script.sh arg1 arg2
# env
php -r 'phpinfo();'
${SHELL} -xv dev/setup/phpunit/setup_conf.sh
sed -i -e 's/stopOnFailure="[^"]*"/stopOnFailure="false"/' test/phpunit/phpunittest.xml
- name: Run PHPUnit tests
shell: cmd
run: |-
php --ini
REM TODO Uncomment next line to restrict directory access
REM SET PHP_INI_SCAN_DIR=C:\myphpini
SET INIFILE="C:\myphpini\dolibarr.ini"
mkdir c:\myphpini
echo [php] > %INIFILE%
echo open_basedir^="%CD%;%PHPROOT%" >> %INIFILE%
type %INIFILE%
php --ini
php "%PHPROOT%\phpunit" -d memory_limit=-1 -c "test\phpunit\phpunittest.xml" "test\phpunit\AllTests.php"

View File

@ -0,0 +1,6 @@
REM SAMPLE WINDOWS SCRIPT TO START TESTS
REM
REM CURRENTLY THIS SCRIPT MUST BE LOCATED AT THE ROOT OF THE PROJECT.
REM A copy of phpunit-9.5.phar is required
SET OPEN_BASEDIR=%~dp0
c:\wamp64\bin\php\php7.4.33\php -dopen_basedir=%OPEN_BASEDIR% .\phpunit-9.5.phar -d memory_limit=-1 -c test\phpunit\phpunittest.xml test\phpunit\AllTests.php

189
dev/setup/phpunit/setup_conf.sh Executable file
View File

@ -0,0 +1,189 @@
#!/usr/bin/bash -xv
# Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
# shellcheck disable=2050,2089,2090,2086
TRAVIS_BUILD_DIR=${TRAVIS_BUILD_DIR:=$(realpath "$(dirname "$0")/../../..")}
MYSQL=${MYSQL:=mysql}
DB=${DB:=mariadb}
DB_ROOT=${DB_ROOT:=root}
DB_PASS=${DB_PASS:=}
TRAVIS_DOC_ROOT_PHP="${TRAVIS_DOC_ROOT_PHP:=$TRAVIS_BUILD_DIR/htdocs}"
TRAVIS_DATA_ROOT_PHP="${TRAVIS_DATA_ROOT_PHP:=$TRAVIS_BUILD_DIR/documents}"
if [[ "$(uname -a)" =~ "MINGW"* ]] || [[ "$(uname -a)" =~ "CYGWIN"* ]] ; then
TRAVIS_BUILD_DIR=$(cygpath -w "${TRAVIS_BUILD_DIR}")
TRAVIS_BUILD_DIR=$(echo "$TRAVIS_BUILD_DIR" | sed 's/\\/\//g')
TRAVIS_DOC_ROOT_PHP=$(cygpath -w "${TRAVIS_DOC_ROOT_PHP}")
TRAVIS_DATA_ROOT_PHP=$(cygpath -w "${TRAVIS_DATA_ROOT_PHP}")
SUDO=""
else
SUDO="sudo"
fi
CONF_FILE=${CONF_FILE:=${TRAVIS_BUILD_DIR}/htdocs/conf/conf.php}
if [ -r "${CONF_FILE}" ] ; then
echo "'${CONF_FILE} exists, not overwriting!"
else
echo "Setting up Dolibarr '$CONF_FILE'"
{
echo '<?php'
echo 'error_reporting(E_ALL);'
echo '$'dolibarr_main_url_root=\'http://127.0.0.1\'';'
echo '$'dolibarr_main_document_root=\'${TRAVIS_DOC_ROOT_PHP}\'';'
echo '$'dolibarr_main_data_root=\'${TRAVIS_DATA_ROOT_PHP}\'';'
echo '$'dolibarr_main_db_host=\'127.0.0.1\'';'
echo '$'dolibarr_main_db_name=\'travis\'';'
echo '$'dolibarr_main_instance_unique_id=\'travis1234567890\'';'
if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ]; then
echo '$'dolibarr_main_db_type=\'mysqli\'';'
echo '$'dolibarr_main_db_port=3306';'
echo '$'dolibarr_main_db_user=\'travis\'';'
echo '$'dolibarr_main_db_pass=\'password\'';'
fi
if [ "$DB" = 'postgresql' ]; then
echo '$'dolibarr_main_db_type=\'pgsql\'';'
echo '$'dolibarr_main_db_port=5432';'
echo '$'dolibarr_main_db_user=\'postgres\'';'
echo '$'dolibarr_main_db_pass=\'postgres\'';'
fi
echo '$'dolibarr_main_authentication=\'dolibarr\'';'
} > "$CONF_FILE"
cat $CONF_FILE
echo
fi
echo "Setting up database '$DB'"
if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ] || [ "$DB" = 'postgresql' ]; then
echo "MySQL stop"
${SUDO} systemctl stop mariadb.service
echo "MySQL restart without pass"
#sudo mysqld_safe --skip-grant-tables --socket=/tmp/aaa
${SUDO} mysqld_safe --skip-grant-tables --socket=/tmp/aaa &
sleep 3
${SUDO} ps fauxww
if [ "${DB_PASS}" = "" ] ; then
PASS_OPT="-password="
PASS_OPT=""
else
PASS_OPT="'-password=${DB_PASS}'"
fi
echo "MySQL set root password"
if [ 1 = 1 ] ; then
CMDS=( \
""
"FLUSH PRIVILEGES; DROP DATABASE travis; CREATE DATABASE IF NOT EXISTS travis CHARACTER SET = 'utf8';"
"CREATE USER 'root'@'localhost' IDENTIFIED BY '$DB_PASS';"
"CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '$DB_PASS';"
"CREATE USER 'travis'@'localhost' IDENTIFIED BY 'password';"
"CREATE USER 'travis'@'127.0.0.1' IDENTIFIED BY 'password';"
"GRANT ALL PRIVILEGES ON travis.* TO root@localhost;"
"GRANT ALL PRIVILEGES ON travis.* TO root@127.0.0.1;"
"GRANT ALL PRIVILEGES ON travis.* TO travis@127.0.0.1;"
"GRANT ALL PRIVILEGES ON travis.* TO travis@localhost;"
"FLUSH PRIVILEGES;"
)
# Local, not changing root
for CMD in "${CMDS[@]}" ; do
${SUDO} "${MYSQL}" -u "$DB_ROOT" ${PASS_OPT} -h 127.0.0.1 -e "$CMD"
done
else
DB_ROOT='root'
DB_PASS='password'
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 -e "FLUSH PRIVILEGES; CREATE DATABASE IF NOT EXISTS travis CHARACTER SET = 'utf8'; ALTER USER 'root'@'localhost' IDENTIFIED BY '$DB_PASS'; CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '$DB_PASS'; CREATE USER 'travis'@'127.0.0.1' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON travis.* TO root@127.0.0.1; GRANT ALL PRIVILEGES ON travis.* TO travis@127.0.0.1; FLUSH PRIVILEGES;"
fi
echo "MySQL grant"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON travis.* TO travis@127.0.0.1; FLUSH PRIVILEGES;'
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON travis.* TO travis@localhost; FLUSH PRIVILEGES;'
echo "MySQL list current users"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'use mysql; select * from user;'
echo "List pid file"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e "show variables like '%pid%';"
#sudo kill `cat /var/lib/mysqld/mysqld.pid`
#sudo systemctl start mariadb
echo "MySQL grant"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'GRANT ALL PRIVILEGES ON travis.* TO travis@127.0.0.1;'
echo "MySQL flush"
${SUDO} "${MYSQL}" -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -e 'FLUSH PRIVILEGES;'
echo "MySQL load sql"
${SUDO} "${MYSQL}" --force -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -D travis < ${TRAVIS_BUILD_DIR}/dev/initdemo/mysqldump_dolibarr_3.5.0.sql | tee $TRAVIS_BUILD_DIR/initial_350.log
elif [ "$DB" = 'postgresql' ]; then
echo Install pgsql if run is for pgsql
echo "Check pgloader version"
pgloader --version
#ps fauxww | grep postgres
ls /etc/postgresql/13/main/
${SUDO} sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/13/main/pg_hba.conf
${SUDO} cat /etc/postgresql/13/main/pg_hba.conf
${SUDO} service postgresql restart
psql postgresql://postgres:postgres@127.0.0.1:5432 -l -A
psql postgresql://postgres:postgres@127.0.0.1:5432 -c 'create database travis;'
psql postgresql://postgres:postgres@127.0.0.1:5432 -c "CREATE USER travis WITH ENCRYPTED PASSWORD 'travis';"
psql postgresql://postgres:postgres@127.0.0.1:5432 -c 'GRANT ALL PRIVILEGES ON DATABASE travis TO travis;'
psql postgresql://postgres:postgres@127.0.0.1:5432 -l -A
fi
export INSTALL_FORCED_FILE="${TRAVIS_BUILD_DIR}/htdocs/install/install.forced.php"
echo "Setting up Dolibarr '$INSTALL_FORCED_FILE' to test installation"
# Ensure we catch errors
set +e
{
echo '<?php '
echo 'error_reporting(E_ALL);'
echo '$'force_install_noedit=2';'
if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ]; then
echo '$'force_install_type=\'mysqli\'';'
echo '$'force_install_port=3306';'
fi
if [ "$DB" = 'postgresql' ]; then
echo '$'force_install_type=\'pgsql\'';'
echo '$'force_install_port=5432';'
fi
echo '$'force_install_dbserver=\'127.0.0.1\'';'
echo '$'force_install_database=\'travis\'';'
echo '$'force_install_databaselogin=\'travis\'';'
echo '$'force_install_databasepass=\'\'';'
echo '$'force_install_prefix=\'llx_\'';'
} > "$INSTALL_FORCED_FILE"
(
cd "${TRAVIS_BUILD_DIR}/htdocs/install" || exit 1
VERSIONS=("3.5.0" "3.6.0" "3.7.0" "3.8.0" "3.9.0")
VERSIONS+=("4.0.0")
VERSIONS+=("5.0.0" "6.0.0" "7.0.0" "8.0.0" "9.0.0")
VERSIONS+=("10.0.0" "11.0.0" "12.0.0" "13.0.0" "14.0.0")
VERSIONS+=("15.0.0" "16.0.0" "18.0.0" "19.0.0" "20.0.0")
pVer=${VERSIONS[0]}
for v in "${VERSIONS[@]:1}" ; do
LOGNAME="${TRAVIS_BUILD_DIR}/upgrade${pVer//./}${v//./}"
php upgrade.php "$pVer" "$v" ignoredbversion > "${LOGNAME}.log"
php upgrade2.php "$pVer" "$v" ignoredbversion > "${LOGNAME}-2.log"
php step5.php "$pVer" "$v" ignoredbversion > "${LOGNAME}-3.log"
pVer="$v"
done
${SUDO} "${MYSQL}" --force -u "$DB_ROOT" -h 127.0.0.1 $PASS_OPT -D travis < "${TRAVIS_BUILD_DIR}/htdocs/install/mysql/migration/repair.sql"
{
php upgrade2.php 0.0.0 0.0.0 MAIN_MODULE_API,MAIN_MODULE_ProductBatch,MAIN_MODULE_SupplierProposal,MAIN_MODULE_STRIPE,MAIN_MODULE_ExpenseReport
php upgrade2.php 0.0.0 0.0.0 MAIN_MODULE_WEBSITE,MAIN_MODULE_TICKET,MAIN_MODULE_ACCOUNTING,MAIN_MODULE_MRP
php upgrade2.php 0.0.0 0.0.0 MAIN_MODULE_RECEPTION,MAIN_MODULE_RECRUITMENT
php upgrade2.php 0.0.0 0.0.0 MAIN_MODULE_KnowledgeManagement,MAIN_MODULE_EventOrganization,MAIN_MODULE_PARTNERSHIP
php upgrade2.php 0.0.0 0.0.0 MAIN_MODULE_EmailCollector
} > $TRAVIS_BUILD_DIR/enablemodule.log
)

View File

@ -124,7 +124,9 @@
$out .= "<b>".$langs->trans("Referer").":</b> ".(isset($_SERVER["HTTP_REFERER"]) ? dol_htmlentities($_SERVER["HTTP_REFERER"], ENT_COMPAT) : '')."<br>\n";
$reday = GETPOST('reday', 'int');
$reday = GETPOSTINT('reday');
$sql = "SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_modification, p.budget_amount";
$sql = "SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_update, p.budget_amount";
$sql = 'SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_modification, p.budget_amount';
$sql = 'SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_update, p.budget_amount';
$sql .= " (cs.periode IS NOT NULL AND cs.periode between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')";
$sql .= " OR (cs.periode IS NULL AND cs.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')";
@ -293,7 +295,9 @@ $permissiontoread = $user->hasRight('stock', 'mouvement', 'lire');
$sql .= " GROUP BY cs.rowid, cs.fk_type, cs.fk_user, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, cs.fk_account, c.libelle, c.accountancy_code, ba.label, ba.ref, ba.number, ba.account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.clos, pay.code";
$sql .= " cs.amount, cs.date_ech, cs.libelle as label, cs.paye, cs.periode, cs.fk_account,";
$sql .= " cs.rowid, cs.libelle as label_sc, cs.fk_type as type, cs.periode, cs.date_ech, cs.amount as total, cs.paye,";
$sql .= " p.datec as date_creation, p.dateo as date_start, p.datee as date_end, p.opp_amount, p.opp_percent, (p.opp_amount*p.opp_percent/100) as opp_weighted_amount, p.tms as date_modification, p.budget_amount,";
$sql .= " p.datec as date_creation, p.dateo as date_start, p.datee as date_end, p.opp_amount, p.opp_percent, (p.opp_amount*p.opp_percent/100) as opp_weighted_amount, p.tms as date_update, p.budget_amount,";
$sql .= " t.datec as date_creation, t.dateo as date_start, t.datee as date_end, t.tms as date_modification,";
$sql .= " t.datec as date_creation, t.dateo as date_start, t.datee as date_end, t.tms as date_update,";
$sql .= dolSqlDateFilter('p.datee', $search_eday, $search_emonth, $search_eyear);
$sql = "SELECT ".$distinct." p.rowid as projectid, p.ref as projectref, p.title as projecttitle, p.fk_statut as projectstatus, p.datee as projectdatee, p.fk_opp_status, p.public, p.fk_user_creat as projectusercreate, p.usage_bill_time,";

View File

@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
# `codespell` can be run as a standalone program from the CLI
# with the appropriate default options.
skip = "*/langs/*,*/build/exe/*,**.log,*.pdf,*dev/resources/*,*.phar,*.z,*.gz,*.sql,*.svg,*htdocs/includes/*,*/textiso.txt,*.js,*README-*,*build/rpm/*spec,*build/pad/*ml,*htdocs/includes/phpoffice/*,*htdocs/includes/tecnickcom/*,*dev/initdemo/removeconfdemo.sh,*dev/tools/codespell/*,*pyproject.toml,*build/exe/*,*fontawe*,*htdocs/theme/*/flags-sprite.inc.php,*dev/setup/codetemplates/codetemplates.xml,*/php.ini,*/html_cerfafr.*,*/lessc.class.php,*.asciidoc,*.xml,*opensurvey/css/style.css"
skip = "*/langs/*,*/build/exe/*,**.log,*.pdf,*dev/resources/*,*.phar,*.z,*.gz,*.sql,*.svg,*htdocs/includes/*,*/textiso.txt,*.js,*README-*,*build/rpm/*spec,*build/pad/*ml,*htdocs/includes/phpoffice/*,*htdocs/includes/tecnickcom/*,*dev/initdemo/removeconfdemo.sh,*dev/tools/codespell/*,*pyproject.toml,*build/exe/*,*fontawe*,*htdocs/theme/*/flags-sprite.inc.php,*dev/setup/codetemplates/codetemplates.xml,*/php.ini,*/html_cerfafr.*,*/lessc.class.php,*.asciidoc,*.xml,*opensurvey/css/style.css,*/documents"
quiet-level=2
ignore-regex = '\\[fnrstv]'