Skip to content

Phalcon CI

Phalcon CI #942

# This file is part of Phalcon.
#
# (c) Phalcon Team <[email protected]>
#
# For the full copyright and license information, please view
# the LICENSE file that was distributed with this source code.
name: "Phalcon CI"
on:
schedule:
- cron: '0 2 * * *' # Daily at 02:00 runs only on default branch
push:
paths-ignore:
- '**.md'
- '**.txt'
pull_request:
workflow_dispatch:
env:
# All versions should be declared here
PHALCON_VERSION: 6.0.0
# For tests
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
LC_ALL: en_US.UTF-8
# PHP extensions required by Composer
EXTENSIONS: apcu, gettext, gd, igbinary, imagick, intl, json, mbstring, msgpack, memcached, sqlite3, yaml, redis, phalcon-niden/phalcon-module@master
permissions: { }
jobs:
# PHP CodeSniffer inspection
phpcs:
name: "Validate code style"
permissions:
contents: read
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
php:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- uses: actions/checkout@v5
- name: "Setup PHP"
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.EXTENSIONS }}
ini-values: apc.enable_cli=on, session.save_path=/tmp
tools: pecl
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PHALCON_PATH: ext
- name: "Install development dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--prefer-dist"
- name: "PHPCS"
run: composer cs
- name: "PHPStan"
run: composer analyze
unit-tests:
name: Unit tests
permissions:
contents: read # to fetch code (actions/checkout)
runs-on: ubuntu-24.04
services:
redis:
image: redis:8-alpine
ports:
- "6379:6379"
memcached:
image: memcached:1.6-alpine
ports:
- "11211:11211"
strategy:
matrix:
php:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- uses: actions/checkout@v5
- name: "Setup platform specific environment"
shell: pwsh
run: |
git config --global core.autocrlf false
$SessionSavePath = if ("${{ runner.os }}" -eq "Windows") { 'C:\temp' } else { '/tmp' }
Write-Output "SESSION_SAVE_PATH=$SessionSavePath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Redis Cluster
uses: vishnudxb/[email protected]
with:
master1-port: 5000
master2-port: 5001
master3-port: 5002
slave1-port: 5003
slave2-port: 5004
slave3-port: 5005
sleep-duration: 5 # Define the sleep duration for docker to start and ready for accepting connections (Here we set default to 5seconds)
# Running Test
- name: Test Redis Cluster
run: |
sudo apt-get update
sudo apt-get install -y redis-tools
docker ps -a
redis-cli -h 127.0.0.1 -p 5000 ping
redis-cli -h 127.0.0.1 -p 5000 cluster nodes
- name: "Setup PHP"
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.EXTENSIONS }}
ini-values: apc.enable_cli=on, session.save_path=${{ env.SESSION_SAVE_PATH }}
tools: pecl, phpize, php-config, composer:v2
coverage: xdebug
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PHALCON_PATH: ext
- name: "Validate composer"
run: composer validate --no-check-all --no-check-publish
- name: "Install development dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--prefer-dist"
- name: "Setup Tests"
shell: bash
run: |
if [ "${{ runner.os }}" = "Linux" ]; then
./config/ci/linux-setup-locales.sh
fi
cp tests/_config/.env.default .env
- name: "Run Unit Tests"
run: composer test-unit-coverage
- name: "Upload coverage file artifact"
uses: "actions/upload-artifact@v4"
with:
name: "unit-${{ matrix.php }}.coverage"
path: "tests/_output/coverage.xml"
db-mysql-tests:
name: MySQL tests
permissions:
contents: read # to fetch code (actions/checkout)
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
php:
- '8.1'
services:
mysql:
image: mysql:5.7
ports:
- "3306:3306"
env:
MYSQL_ROOT_PASSWORD: secret
MYSQL_USER: phalcon
MYSQL_DATABASE: phalcon
MYSQL_PASSWORD: secret
postgres:
image: postgres:18-alpine
ports:
- "5432:5432"
env:
POSTGRES_USER: phalcon
POSTGRES_PASSWORD: secret
POSTGRES_DB: phalcon
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:8-alpine
ports:
- "6379:6379"
memcached:
image: memcached:1.6-alpine
ports:
- "11211:11211"
steps:
- uses: actions/checkout@v5
- name: "Setup platform specific environment"
shell: pwsh
run: git config --global core.autocrlf false
- name: "Setup PHP"
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.EXTENSIONS }}
ini-values: apc.enable_cli=on, session.save_path=${{ env.SESSION_SAVE_PATH }}
tools: pecl, phpize, php-config, composer:v2
coverage: xdebug
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PHALCON_PATH: ext
- name: "Validate composer"
run: composer validate --no-check-all --no-check-publish
- name: "Install development dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--prefer-dist"
- name: "Setup Tests"
shell: bash
run: |
if [ "${{ runner.os }}" = "Linux" ]; then
./config/ci/linux-setup-locales.sh
fi
cp tests/_config/.env.default .env
- name: "Run Database Tests (MySQL)"
env:
DATA_MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}
DATA_MYSQL_USER: root
DATA_REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
DATA_MEMCACHED_PORT: ${{ job.services.memcached.ports['11211'] }}
run: composer test-db-mysql-coverage
- name: "Upload coverage file artifact"
uses: "actions/upload-artifact@v4"
with:
name: "db-mysql-${{ matrix.php }}.coverage"
path: "tests/_output/coverage.xml"
# db-postgres-tests:
# name: PostgreSQL tests
#
# permissions:
# contents: read # to fetch code (actions/checkout)
#
# runs-on: ubuntu-24.04
#
# strategy:
# fail-fast: true
# matrix:
# php:
# - '8.1'
#
# services:
# postgres:
# image: postgres:18-alpine
# ports:
# - "5432:5432"
# env:
# POSTGRES_USER: phalcon
# POSTGRES_PASSWORD: secret
# POSTGRES_DB: phalcon
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# redis:
# image: redis:8-alpine
# ports:
# - "6379:6379"
# memcached:
# image: memcached:1.6-alpine
# ports:
# - "11211:11211"
#
# steps:
# - uses: actions/checkout@v5
#
# - name: "Setup platform specific environment"
# shell: pwsh
# run: git config --global core.autocrlf false
#
# - name: "Setup PHP"
# uses: shivammathur/[email protected]
# with:
# php-version: ${{ matrix.php }}
# extensions: ${{ env.EXTENSIONS }}
# ini-values: apc.enable_cli=on, session.save_path=${{ env.SESSION_SAVE_PATH }}
# tools: pecl, phpize, php-config, composer:v2
# coverage: xdebug
# env:
# COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# PHALCON_PATH: ext
#
# - name: "Validate composer"
# run: composer validate --no-check-all --no-check-publish
#
# - name: "Install development dependencies with Composer"
# uses: "ramsey/composer-install@v2"
# with:
# composer-options: "--prefer-dist"
#
# - name: "Setup Tests"
# shell: bash
# run: |
# if [ "${{ runner.os }}" = "Linux" ]; then
# ./config/ci/linux-setup-locales.sh
# fi
#
# cp tests/_config/.env.default .env
# vendor/bin/codecept build
#
# - name: "Run Database Tests (PostgreSQL)"
# env:
# DATA_POSTGRES_USER: phalcon
# DATA_POSTGRES_PASS: secret
# DATA_POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }}
# DATA_REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
# DATA_MEMCACHED_PORT: ${{ job.services.memcached.ports['11211'] }}
# run: vendor/bin/codecept run --coverage-xml=coverage.xml --ext DotReporter database --env pgsql -g pgsql
#
# - name: "Upload coverage file artifact"
# uses: "actions/upload-artifact@v4"
# with:
# name: "db-postgres-${{ matrix.php }}.coverage"
# path: "tests/_output/coverage.xml"
db-sqlite-tests:
name: SQLite tests
permissions:
contents: read # to fetch code (actions/checkout)
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
php:
- '8.1'
steps:
- uses: actions/checkout@v5
- name: "Setup platform specific environment"
shell: pwsh
run: git config --global core.autocrlf false
- name: "Setup PHP"
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.EXTENSIONS }}
ini-values: apc.enable_cli=on, session.save_path=${{ env.SESSION_SAVE_PATH }}
tools: pecl, phpize, php-config, composer:v2
coverage: xdebug
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PHALCON_PATH: ext
- name: "Validate composer"
run: composer validate --no-check-all --no-check-publish
- name: "Install development dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--prefer-dist"
- name: "Setup Tests"
shell: bash
run: |
if [ "${{ runner.os }}" = "Linux" ]; then
./config/ci/linux-setup-locales.sh
fi
cp tests/_config/.env.default .env
- name: "Run Database Tests (SQLite)"
run: composer test-db-sqlite-coverage
- name: "Upload coverage file artifact"
uses: "actions/upload-artifact@v4"
with:
name: "db-sqlite-${{ matrix.php }}.coverage"
path: "tests/_output/coverage.xml"
upload-coverage:
name: "Upload coverage"
permissions:
contents: read
runs-on: ubuntu-24.04
needs:
- "phpcs"
- "unit-tests"
- "db-mysql-tests"
# - "db-postgres-tests"
- "db-sqlite-tests"
steps:
- name: "Checkout"
uses: "actions/checkout@v5"
with:
fetch-depth: 0
- name: "Display structure of downloaded files"
run: mkdir -p cv
- name: "Download coverage files"
uses: "actions/download-artifact@v4"
with:
path: "cv"
- name: "Display structure of downloaded files"
run: |
mv cv/db-mysql-8.1.coverage/coverage.xml cv/01.xml
mv cv/db-sqlite-8.1.coverage/coverage.xml cv/02.xml
mv cv/unit-8.1.coverage/coverage.xml cv/03.xml
mv cv/unit-8.2.coverage/coverage.xml cv/04.xml
mv cv/unit-8.3.coverage/coverage.xml cv/05.xml
mv cv/unit-8.4.coverage/coverage.xml cv/06.xml
ls -la cv/
- name: SonarCloud Scan
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: ./
args: >
-Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }}
-Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }}
-Dsonar.sources=src/
-Dsonar.exclusions=vendor/**,cv/**,tests/**
-Dsonar.sourceEncoding=UTF-8
-Dsonar.language=php
-Dsonar.tests=tests/
-Dsonar.php.coverage.reportPaths=cv/01.xml,cv/02.xml,cv/03.xml,cv/04.xml,cv/05.xml,cv/06.xml