Skip to content

Commit

Permalink
Merge pull request #47 from openfoodfacts/0.3.x-dev
Browse files Browse the repository at this point in the history
feat: 0.3.x dev - Update dependencies and PHP to 8.1
  • Loading branch information
epalmans authored May 1, 2024
2 parents 595a6b4 + 34bab53 commit 6c6702d
Show file tree
Hide file tree
Showing 25 changed files with 292 additions and 203 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Docker
USER_ID=1000
GROUP_ID=1000
# For Composer (installing packages - optional)
#GITHUB_TOKEN="${GITHUB_TOKEN}"
2 changes: 1 addition & 1 deletion .github/workflows/auto-assign-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
assign-author:
runs-on: ubuntu-latest
steps:
- uses: toshimaru/auto-author-assign@v1.4.0
- uses: toshimaru/auto-author-assign@v1.6.2
22 changes: 13 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ jobs:
tests:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
name: Tests - PHP ${{ matrix.php }}
php: ['8.1', '8.2']
name: Tests - PHP ${{ matrix.php }}
concurrency:
group: ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}-${{ matrix.php }}
cancel-in-progress: true
steps:
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
uses: actions/checkout@v3
- uses: actions/cache@v3
id: cache-db
with:
path: ~/.symfony/cache
Expand All @@ -23,23 +25,25 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
- name: Report PHP version
run: php -v
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ matrix.php }}-composer-
- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress --no-suggest
- name: check dependancy
uses: symfonycorp/security-checker-action@v2
- name: check dependency
uses: symfonycorp/security-checker-action@v5
- name: Check quality code
env:
PHP_CS_FIXER_IGNORE_ENV: 1
run: vendor/bin/php-cs-fixer fix --ansi --dry-run --using-cache=no --verbose
- name: Execute phpstan
run: vendor/bin/phpstan
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
### Example user template template
### Example user template
/build/
/bin/

# IntelliJ project files
.idea
Expand All @@ -12,6 +13,8 @@ composer.phar
/vendor/
/log/
/tests/tmp/*
.env
/xdebug_profile/

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file https://getcomposer.org/doc/02-libraries.md#lock-file
Expand Down
19 changes: 13 additions & 6 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(['src', 'tests'])
$config = new PhpCsFixer\Config();
$finder = $config->getFinder();
$finder
->in(['src','tests'])
;

$config = new PhpCsFixer\Config();
return $config->setRules([
return $config
->setRules([
'@PSR12' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'single_quote' => true,
'blank_line_before_statement' => true,
'no_spaces_around_offset' => true,
'no_unused_imports' => true,
'ternary_operator_spaces' => true,
])
->setFinder($finder)
;
->setUsingCache(false)
;
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
5. Create a new Pull Request
6. Help this Project move forward :)
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

php-setup:
test -e .env || cp .env.example .env
docker compose down
docker compose rm
docker compose build
docker compose up -d --force-recreate
make composer install

install:
docker compose exec php-fpm bash -c 'XDEBUG_MODE=off composer install'

fix:
docker compose exec php-fpm bash -c 'XDEBUG_MODE=off ./vendor/bin/php-cs-fixer fix'

test:
docker compose exec php-fpm bash -c 'XDEBUG_MODE=off ./vendor/bin/phpunit'

composer:
docker compose exec php-fpm bash -c "XDEBUG_MODE=off composer $(filter-out $@,$(MAKECMDGOALS))"
28 changes: 16 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@
{
"name": "Roberto Moreno",
"email": "[email protected]",
"homepage": "http://www.rampmaster.org",
"homepage": "https://rampmaster.org/",
"role": "Wrapper Developer"
},
{
"name": "Colin Benoit",
"homepage": "https://github.com/Benoit382",
"role": "PHP Developer"
}
],
"require": {
"php": "^7.2|^8.0",
"php": "^8.1",
"ext-json": "*",
"ext-curl": "*",
"guzzlehttp/guzzle": "^6.3|^7.0",
"psr/log": "^1.0",
"psr/simple-cache": "^1.0"
"ext-gd": "*",
"guzzlehttp/guzzle": "^7.4",
"psr/log": "^3.0",
"psr/simple-cache": "^3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -35,12 +41,10 @@
}
},
"require-dev": {
"ext-gd": "*",
"monolog/monolog": "^1.23",
"symfony/cache": "^4.3",
"phpunit/phpunit": "^8.5|^9.5",
"phpstan/phpstan": "^0.12.99",
"phpstan/phpstan-phpunit": "^0.12.22",
"friendsofphp/php-cs-fixer": "^3.1"
"symfony/cache": "^6.1.3",
"phpunit/phpunit": "^9.5.21",
"phpstan/phpstan": "^1.8.2",
"phpstan/phpstan-phpunit": "^1.1.1",
"friendsofphp/php-cs-fixer": "^3.9.5"
}
}
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.7'

services:
php-fpm:
container_name: openfoodfacts-php
build:
context: .
dockerfile: ./docker/php/Dockerfile
args:
GITHUB_TOKEN: $GITHUB_TOKEN
GROUP_ID: $GROUP_ID
USER_ID: $USER_ID
environment:
XDEBUG_CONFIG: client_host=host.docker.internal
image: somecoding/crawler-php-fpm
volumes:
- .:/var/www/html:delegated
- ./docker/php/php.ini:/usr/local/etc/php/conf.d/php.ini
- ./docker/php/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./docker/php/fpm_additional.conf:/usr/local/etc/php-fpm.d/zzzz-fpm_additional.conf # zzzz- to be loaded last: overwrites all before
- ./xdebug_profile:/tmp/profile:delegated
networks:
- default
extra_hosts:
- "host.docker.internal:host-gateway"
50 changes: 50 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# syntax=docker/dockerfile:experimental
FROM composer:2 AS COMPOSER
ENV COMPOSER_HOME=/usr/config/composer
ENV GITHUB_TOKEN=""
RUN if [[ -z "$GITHUB_TOKEN" ]] ; then echo Github Token not provided ; else composer config -g github-oauth.github.com $GITHUB_TOKEN; fi

FROM php:8.1-fpm

ENV COMPOSER_HOME=/usr/config/composer
ARG USER_ID
ARG GROUP_ID
RUN usermod -u $USER_ID www-data && groupmod -g $GROUP_ID www-data

# Install php-src extensions
RUN apt-get -qq update && apt-get -qq --no-install-recommends install \
libzip-dev \
unzip \
libpng-dev \
libjpeg-dev \
mariadb-client \
git > /dev/null && \
pecl install xdebug-3.1.6 > /dev/null && \
docker-php-ext-enable xdebug > /dev/null && \
pecl install -o -f redis-5.3.4 > /dev/null && \
docker-php-ext-install \
-j$(nproc) \
zip \
gd \
bcmath \
pdo_mysql > /dev/null && \
rm -rf /tmp/pear > /dev/null && \
rm -rf /var/lib/apt/lists/*
RUN mkdir /tmp/profile; chmod 755 /tmp/profile

# Install composer and dependencies
COPY --chown=root:root --from=COMPOSER --chmod=755 /usr/bin/composer /usr/bin/composer


ENV GITHUB_TOKEN=""
###COPY --chown=www-data:www-data --from=COMPOSER /usr/config/composer /usr/config/composer
#Re-enable aboce COPY when Token is set

# Make sure composer can checkout github
RUN mkdir -p /var/www/.ssh/ && \
touch /var/www/.ssh/known_hosts && \
ssh-keyscan github.com >> /var/www/.ssh/known_hosts

WORKDIR /var/www/html

USER www-data
6 changes: 6 additions & 0 deletions docker/php/docker-php-ext-xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zend_extension=xdebug

xdebug.mode=debug,profile
xdebug.client_port= 9000
xdebug.start_with_request=yes
xdebug.output_dir = /tmp/profile
7 changes: 7 additions & 0 deletions docker/php/fpm_additional.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[www]
pm = dynamic
pm.max_children = 20
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 250
4 changes: 4 additions & 0 deletions docker/php/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
max_execution_time=600
memory_limit=-1
session.cookie_httponly = 1; // Make sonarcloud happy - docker is for local dev only
session.cookie_secure = 1;
2 changes: 1 addition & 1 deletion examples/01-basic_api_usage/cached_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Symfony\Component\Cache\Psr16Cache;

include '../../vendor/autoload.php';
$logger = new \Monolog\Logger('test');
$logger = new \Psr\Log\NullLogger;
$httpClient = new \GuzzleHttp\Client();
// the PSR-6 cache object that you want to use (you might also use a PSR-16 Interface Object directly)
$psr6Cache = new FilesystemAdapter();
Expand Down
8 changes: 5 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ includes:
- vendor/phpstan/phpstan-phpunit/rules.neon

parameters:
level: max
level: 8
checkMissingIterableValueType: false
ignoreErrors:
- '/.*is not subtype of Throwable/'
paths:
- src
- tests
ignoreErrors:
-
message: "#^Unreachable statement - code above always terminates.$#"
path: tests/ApiFoodTest.php
Loading

0 comments on commit 6c6702d

Please sign in to comment.