Skip to content

Commit

Permalink
run static analysis in CI
Browse files Browse the repository at this point in the history
Signed-off-by: Demin Yin <deminy@deminy.net>
  • Loading branch information
deminy committed Dec 13, 2023
1 parent 1f7483c commit 14b15b3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 9 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Static Analysis

on: [ push, pull_request, workflow_dispatch ]

jobs:
static-analysis:
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
tools: composer:v2
extensions: redis-stable, swoole-5.1.1, sysvmsg
ini-values: swoole.enable_library=off
coverage: none
env:
SWOOLE_CONFIGURE_OPTS: --enable-mysqlnd --enable-swoole-pgsql --enable-openssl --enable-sockets --enable-swoole-curl

- name: Install PHPStan
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: |
set -ex
composer global require phpstan/phpstan=^1.11.x-dev -n -q --no-progress
composer global require predis/predis=~2.2 -n -q --no-progress
composer global require swoole/library=~5.0 -n -q --no-progress
- name: Run Static Analysis
run: ~/.composer/vendor/bin/phpstan analyse --no-progress --memory-limit 2G
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
/composer.lock
/vendor/

# Ignore PHPStan files.
/phpstan.neon

# Some examples will download files from Internet. This is to ignore those downloaded files.
/examples/clients/*.png
4 changes: 1 addition & 3 deletions dockerfiles/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ RUN \
apt-get install -y apache2-utils netcat-traditional xxd --no-install-recommends && \
curl -sfL -o /usr/bin/websocat "https://github.com/vi/websocat/releases/download/v1.12.0/websocat.$(uname -m)-unknown-linux-musl" && \
chmod 755 /usr/bin/websocat && \
rm -rf /var/lib/apt/lists/* && \
composer require -d ${HOME} -n predis/predis:~2.2.0 && \
composer clearcache
rm -rf /var/lib/apt/lists/*
2 changes: 2 additions & 0 deletions dockerfiles/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ FROM phpswoole/swoole:5.1

COPY ./rootfilesystem /

# The System V messages support is to run some example in script "./examples/pool/process-pool/client.php".
RUN \
set -ex && \
docker-php-ext-install sysvmsg && \
apt-get update && \
apt-get install -y net-tools watch --no-install-recommends && \
rm -rf /var/lib/apt/lists/*
6 changes: 4 additions & 2 deletions examples/clients/redis/predis.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* This client-side script is to use predis to test the Redis server created in this repository. For details, please
* check comments in script https://github.com/deminy/swoole-by-examples/blob/master/examples/servers/redis.php.
*
* You can use following command to run this script:
* Before running this script, you need to install predis first using the following command:
* docker compose exec -t client bash -c "composer global require predis/predis=~2.2"
* Now you can use following command to run this script:
* docker compose exec -t client bash -c "./clients/redis/predis.php"
*/
require_once "{$_ENV['HOME']}/vendor/autoload.php";
require_once "{$_ENV['HOME']}/.composer/vendor/autoload.php";
$client = new Predis\Client(['scheme' => 'tcp', 'host' => 'server', 'port' => 6379]);
echo $client->set('foo', 'bar'), PHP_EOL;
echo $client->get('foo'), PHP_EOL;
21 changes: 17 additions & 4 deletions examples/pool/process-pool/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,29 @@

// This first example shows how to send messages (and deploy tasks) to a process pool through message queue.
// Swoole extension "async" (https://github.com/swoole/ext-async) is needed to run this example.
// If your PHP is compiled to support System V semaphore, you can also use message queue functions msg_get_queue()
// and msg_send() to do that. Check PHP manual https://www.php.net/sem for details.
if (class_exists(MsgQueue::class)) {
go(function () {
$mq = new MsgQueue(0x7000001);
$mq = new MsgQueue(0x7000001); // @phpstan-ignore class.notFound
for ($i = 0; $i < 3; $i++) {
// On the server side, you will see output messages like the following:
// Process #0 received message "s:35:"Message #0 via class Swoole\MsgQueue!";". (MSGQUEUE)
$mq->push(sprintf('Message #%d via class %s!', $i, MsgQueue::class)); // @phpstan-ignore class.notFound
}
});
}
// If your PHP is compiled to support System V messages, you can also use message queue functions msg_get_queue()
// and msg_send() to do that. Check PHP manual https://www.php.net/sem for details.
if (function_exists('msg_get_queue')) {
go(function () {
$mq = msg_get_queue(0x7000001);
for ($i = 0; $i < 3; $i++) {
$mq->push("Message #{$i}!");
// On the server side, you will see output messages like the following:
// Process #0 received message "s:35:"Message #0 via function msg_send()!";". (MSGQUEUE)
msg_send($mq, 1, sprintf('Message #%d via function msg_send()!', $i));
}
});
}
return;

// This second example shows how to send messages (and deploy tasks) to a process pool through TCP socket.
go(function () use ($settings) {
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 0
paths:
- ./examples

0 comments on commit 14b15b3

Please sign in to comment.