From 9ec6636c297997564b5178d577c19e333f9100f8 Mon Sep 17 00:00:00 2001 From: Fabian General Date: Fri, 28 Nov 2025 10:20:13 +0000 Subject: [PATCH 1/5] feat: move to gh actions --- .github/workflows/test.yml | 121 +++++++++++++++++++++++++++++++++++++ .travis.yml | 104 ------------------------------- README.md | 2 +- 3 files changed, 122 insertions(+), 105 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..4ae817f7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,121 @@ +name: Test + +on: + push: + branches: + - master + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - php: '7.4' + env: + PHPCS: '1' + name: 'PHP 7.4 Lint' + - php: '8.2' + env: + PHPUNIT_VERSION: '9.6.7' + WP: 'latest' + name: 'PHP 8.2 / WP latest' + - php: '8.1' + env: + PHPUNIT_VERSION: '9.6.7' + WP: 'latest' + name: 'PHP 8.1 / WP latest' + - php: '8.0' + env: + PHPUNIT_VERSION: '9.6.7' + WP: 'latest' + name: 'PHP 8.0 / WP latest' + - php: '7.4' + env: + PHPUNIT_VERSION: '7.5.20' + WP: 'latest' + name: 'PHP 7.4 / WP latest' + - php: '7.3' + env: + PHPUNIT_VERSION: '7.5.20' + WP: 'latest' + name: 'PHP 7.3 / WP latest' + - php: '7.2' + env: + PHPUNIT_VERSION: '7.5.20' + WP: 'latest' + name: 'PHP 7.2 / WP latest' + - php: '7.1' + env: + PHPUNIT_VERSION: '7.5.20' + WP: '6.5.5' + name: 'PHP 7.1 / WP 6.5.5' + - php: '7.0' + env: + PHPUNIT_VERSION: '6.5.14' + WP: '6.5.5' + name: 'PHP 7.0 / WP 6.5.5' + - php: '5.6' + env: + PHPUNIT_VERSION: '5.7.27' + WP: '6.2.2' + name: 'PHP 5.6 / WP 6.2.2' + + name: ${{ matrix.name }} + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: root + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mysql, mysqli, pdo, pdo_mysql, zip, libonig5 + coverage: none + tools: composer:v2 + + - name: Install dependencies (PHPCS) + if: matrix.env.PHPCS == '1' + run: | + cd tests + composer install + + - name: Run PHPCS + if: matrix.env.PHPCS == '1' + run: tests/vendor/bin/phpcs + + - name: Setup Test Environment + if: matrix.env.PHPCS != '1' + env: + PHPUNIT_VERSION: ${{ matrix.env.PHPUNIT_VERSION }} + WP_VERSION: ${{ matrix.env.WP }} + run: | + # Install WP Tests + bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:$((3306)) $WP_VERSION + + # Install PHPUnit + wget -q https://phar.phpunit.de/phpunit-$PHPUNIT_VERSION.phar -O /tmp/phpunit + chmod +x /tmp/phpunit + + - name: Install Polyfills + if: matrix.env.PHPCS != '1' + run: composer require yoast/phpunit-polyfills + + - name: Run Tests + if: matrix.env.PHPCS != '1' + run: | + /tmp/phpunit + WP_MULTISITE=1 /tmp/phpunit diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 70274d3c..00000000 --- a/.travis.yml +++ /dev/null @@ -1,104 +0,0 @@ -os: linux -dist: bionic - -services: - - mysql - -language: php - -cache: - directories: - - $HOME/.composer/cache - -matrix: - fast_finish: true - include: - - php: 7.4 - env: PHPCS=1 - - php: 8.2 - env: - - PHPUNIT_VERSION=9.6.7 - - WP=latest - dist: jammy # Version 8.2 is not available in the "bionic", newer version is required. - addons: - apt: - packages: - - "libonig5" # This library is required, since Travis fails to properly install & run the PHP 8.2 - - php: 8.1 - env: - - PHPUNIT_VERSION=9.6.7 - - WP=latest - - php: 8.0 - env: - - PHPUNIT_VERSION=9.6.7 - - WP=latest - - php: 7.4 - env: - - PHPUNIT_VERSION=7.5.20 - - WP=latest - - php: 7.3 - env: - - PHPUNIT_VERSION=7.5.20 - - WP=latest - - php: 7.2 - env: - - PHPUNIT_VERSION=7.5.20 - - WP=latest - - php: 7.1 - env: - - PHPUNIT_VERSION=7.5.20 - - WP=6.5.5 - - php: 7.0 - env: - - PHPUNIT_VERSION=6.5.14 - - WP=6.5.5 - dist: xenial # Versions 7.0 and lower not available in "bionic", older version ("xenial") required to run - - php: 5.6 - env: - - PHPUNIT_VERSION=5.7.27 - - WP=6.2.2 - dist: xenial - -before_install: - - | - which composer - if ! composer --version; then - sudo apt-get update - sudo apt-get install -y php-cli unzip - curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php - sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer - PATH="/usr/local/bin:${PATH}" - which composer - fi - - composer --version - -before_script: - - | - if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then - phpenv config-rm xdebug.ini - else - echo \"xdebug.ini does not exist\" - fi - - | - if [ "$PHPCS" == "1" ]; then - (cd tests && composer install) - else - # (as of 2021-10-05, certifi still stubbornly bundles the expired root; - # see https://github.com/certifi/python-certifi/pull/162 - # and https://bugzilla.mozilla.org/show_bug.cgi?id=1733560 for updates) - sudo sed -re 's#^(mozilla/DST_Root_CA_X3.crt)$#!\1#' -i /etc/ca-certificates.conf; - sudo update-ca-certificates; - export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt; - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP; - wget https://phar.phpunit.de/phpunit-$PHPUNIT_VERSION.phar -O /tmp/phpunit && - chmod +x /tmp/phpunit - fi -script: - - | - if [ "$PHPCS" == "1" ]; then - tests/vendor/bin/phpcs - else - composer require yoast/phpunit-polyfills - /tmp/phpunit - WP_MULTISITE=1 /tmp/phpunit - fi diff --git a/README.md b/README.md index cfdd25da..9d0cec02 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ https://core.trac.wordpress.org/ticket/44043 # Travis CI Status -[![Build Status](https://travis-ci.com/CybotAS/CookiebotWP.svg?branch=master)](https://app.travis-ci.com/github/CybotAS/CookiebotWP) +[![Test](https://github.com/CybotAS/CookiebotWP/actions/workflows/test.yml/badge.svg)](https://github.com/CybotAS/CookiebotWP/actions/workflows/test.yml) # Sonarcloud status From 63eb65dbc1b89898d62fd192b4e422bbc5072507 Mon Sep 17 00:00:00 2001 From: Fabian General Date: Fri, 28 Nov 2025 10:38:38 +0000 Subject: [PATCH 2/5] fix: install svn --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4ae817f7..48c60b05 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,6 +87,11 @@ jobs: coverage: none tools: composer:v2 + - name: Install subversion + run: | + sudo apt-get update + sudo apt-get install -y subversion + - name: Install dependencies (PHPCS) if: matrix.env.PHPCS == '1' run: | From ceedee163401bad4351ee23a21fa42db31dfdd50 Mon Sep 17 00:00:00 2001 From: Fabian General Date: Fri, 28 Nov 2025 15:38:15 +0000 Subject: [PATCH 3/5] fix: point job dependency to hash --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48c60b05..f2b4837a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,10 +77,10 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Setup PHP - uses: shivammathur/setup-php@v2 + uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4 with: php-version: ${{ matrix.php }} extensions: mysql, mysqli, pdo, pdo_mysql, zip, libonig5 From ef2f620e64989523a8b2d202215fd779ce9ce4d8 Mon Sep 17 00:00:00 2001 From: Fabian General Date: Tue, 2 Dec 2025 09:30:26 +0000 Subject: [PATCH 4/5] fix: tests: --- .../controller/addons/Base_Cookiebot_Addon.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/addons/controller/addons/Base_Cookiebot_Addon.php b/src/addons/controller/addons/Base_Cookiebot_Addon.php index 40ae529b..b6285168 100644 --- a/src/addons/controller/addons/Base_Cookiebot_Addon.php +++ b/src/addons/controller/addons/Base_Cookiebot_Addon.php @@ -340,7 +340,17 @@ private static function get_svn_url( $path = '' ) { */ final public static function get_svn_file_content( $path = '' ) { $url = self::get_svn_url( $path ); - $response = wp_remote_get( $url ); - return wp_remote_retrieve_body( $response ); + $args = array( + 'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', + ); + $response = wp_remote_get( $url, $args ); + $body = wp_remote_retrieve_body( $response ); + + if ( ! $body || 200 !== wp_remote_retrieve_response_code( $response ) ) { + // Fallback to svn cat if wp_remote_get fails (e.g. 403 Forbidden) + $body = shell_exec( 'svn cat ' . escapeshellarg( $url ) ); + } + + return $body; } } From 744777968380b21c695a94f2942b1ca5106a488d Mon Sep 17 00:00:00 2001 From: Fabian General Date: Tue, 2 Dec 2025 09:42:11 +0000 Subject: [PATCH 5/5] fix: lint --- src/addons/controller/addons/Base_Cookiebot_Addon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addons/controller/addons/Base_Cookiebot_Addon.php b/src/addons/controller/addons/Base_Cookiebot_Addon.php index b6285168..14aac88d 100644 --- a/src/addons/controller/addons/Base_Cookiebot_Addon.php +++ b/src/addons/controller/addons/Base_Cookiebot_Addon.php @@ -348,7 +348,7 @@ final public static function get_svn_file_content( $path = '' ) { if ( ! $body || 200 !== wp_remote_retrieve_response_code( $response ) ) { // Fallback to svn cat if wp_remote_get fails (e.g. 403 Forbidden) - $body = shell_exec( 'svn cat ' . escapeshellarg( $url ) ); + $body = shell_exec( 'svn cat ' . escapeshellarg( $url ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec } return $body;