Skip to content

Phalcon CI

Phalcon CI #139

# 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:
fail-fast: true
# All versions should be declared here
PHALCON_VERSION: 6.0.0
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
# For tests
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
LC_ALL: en_US.UTF-8
# Windows specific
TOOLS_DIR: 'C:\tools'
# 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 Tests code style"
if: "!contains(github.event.head_commit.message, 'ci skip')"
permissions:
contents: read
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
php:
- '8.1'
- '8.2'
- '8.3'
# - '8.4'
steps:
- uses: actions/checkout@v4
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
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:
needs: phpcs
permissions:
contents: read # to fetch code (actions/checkout)
services:
redis:
image: redis:5-alpine
ports:
- "6379:6379"
memcached:
image: memcached:1.5-alpine
ports:
- "11211:11211"
name: Unit tests / PHP-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
php:
- '8.1'
- '8.2'
- '8.3'
ts:
# - 'nts'
- 'ts'
name:
- ubuntu-gcc
# - macos-clang
# matrix names should be in next format:
# {php}-{ts}-{os.name}-{compiler}-{arch}
include:
# Linux
- { name: ubuntu-gcc, os: ubuntu-22.04, compiler: gcc }
# # macOS
# - { name: macos-clang, os: macos-12, compiler: clang }
# # Windows
# - { php: '8.1', ts: 'ts', arch: 'x64', name: 'windows2019-vs16', os: 'windows-2019', compiler: 'vs16' }
# - { php: '8.1', ts: 'nts', arch: 'x64', name: 'windows2019-vs16', os: 'windows-2019', compiler: 'vs16' }
steps:
- uses: actions/checkout@v4
- 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:
redis-node-0-port: 5000
redis-node-1-port: 5001
redis-node-2-port: 5002
redis-node-3-port: 5003
redis-node-4-port: 5004
redis-node-5-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 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/setup-php@v2
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:
PHPTS: ${{ matrix.ts }}
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"
if: always()
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: Database MySQL tests / PHP-${{ matrix.php }}
needs: phpcs
permissions:
contents: read # to fetch code (actions/checkout)
runs-on: ubuntu-22.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:12-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:5-alpine
ports:
- "6379:6379"
memcached:
image: memcached:1.5-alpine
ports:
- "11211:11211"
steps:
- uses: actions/checkout@v4
- name: "Setup platform specific environment"
shell: pwsh
run: |
git config --global core.autocrlf false
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
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: Database PostgreSql tests / PHP-${{ matrix.php }}
# needs: phpcs
#
# permissions:
# contents: read # to fetch code (actions/checkout)
#
# runs-on: ubuntu-22.04
#
# strategy:
# fail-fast: true
# matrix:
# php:
# - '8.1'
#
# services:
# postgres:
# image: postgres:12-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:5-alpine
# ports:
# - "6379:6379"
# memcached:
# image: memcached:1.5-alpine
# ports:
# - "11211:11211"
#
# steps:
# - uses: actions/checkout@v4
# - name: "Setup platform specific environment"
# shell: pwsh
# run: |
# git config --global core.autocrlf false
#
# - name: "Setup PHP"
# uses: shivammathur/setup-php@v2
# 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 }}-${{ matrix.ts }}-${{ matrix.name }}.coverage"
# path: "tests/_output/coverage.xml"
db-sqlite-tests:
name: Database Sqlite tests / PHP-${{ matrix.php }}
needs: phpcs
permissions:
contents: read # to fetch code (actions/checkout)
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
php:
- '8.1'
# - '8.2'
# - '8.3'
steps:
- uses: actions/checkout@v4
- name: "Setup platform specific environment"
shell: pwsh
run: |
git config --global core.autocrlf false
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
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:
permissions:
contents: read
name: "Upload coverage"
runs-on: "ubuntu-22.04"
needs:
- "unit-tests"
- "db-mysql-tests"
# - "db-postgres-tests"
# - "db-sqlite-tests"
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
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
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