Skip to content

Commit

Permalink
[ACCOUNT-2732] refactor: replace module-lib-service-container (#447)
Browse files Browse the repository at this point in the history
* refactor: get rid of module-lib-service-container

* refactor: remove useless deps

* refactor: create provider files

* chore: empty services files

* chore: cleanup composer.json

* fix: static closures

* refactor: early logger injection

* refactor: switch to the lightweight-container lib

* feat: scoping lightweight-container
  • Loading branch information
hschoenenberger authored Nov 29, 2024
1 parent ad29492 commit 189f098
Show file tree
Hide file tree
Showing 44 changed files with 1,183 additions and 1,550 deletions.
11 changes: 2 additions & 9 deletions .dir-scoped
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
symfony/cache
symfony/config
symfony/dependency-injection
symfony/expression-language
symfony/filesystem
symfony/yaml
psr
monolog
guzzlehttp
league
prestashopcorp/oauth2-prestashop
prestashopcorp/lightweight-container
lcobucci
prestashop/module-lib-service-container
prestashop/module-lib-cache-directory-provider
monolog
ramsey/uuid
ralouphie/getallheaders
phpseclib/phpseclib/phpseclib
2 changes: 1 addition & 1 deletion .docker/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.7"
services:
prestashop:
container_name: phpunit
# image: 'prestashop/prestashop-flashlight:1.7.6.9-7.2'
# image: 'prestashop/prestashop-flashlight:1.7.6'
image: ${PLATFORM_IMAGE}
healthcheck:
test: curl --fail http://localhost:80 || exit 1
Expand Down
68 changes: 19 additions & 49 deletions .github/workflows/accounts-qc-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master
with:
folder-to-exclude: "! -path \"./tests/*\" ! -path \"./vendor/symfony/polyfill-*\" ! -path \"./vendor/symfony/config/*\""
folder-to-exclude: "! -path \"./tests/*\" ! -path \"./vendor/symfony/polyfill-*\""

- name: PHP syntax checker 8.3
uses: prestashop/github-action-php-lint/8.3@master
with:
folder-to-exclude: "! -path \"./tests/*\" ! -path \"./vendor/symfony/polyfill-*\" ! -path \"./vendor/symfony/config/*\" ! path \"./vendor/segmentio/analytics-php/*\""
folder-to-exclude: "! -path \"./tests/*\" ! -path \"./vendor/symfony/polyfill-*\" ! path \"./vendor/segmentio/analytics-php/*\""

php-cs-fixer:
name: PHP-CS-FIXER
Expand All @@ -50,27 +50,8 @@ jobs:
- name: Run PHP-CS-Fixer
uses: prestashopcorp/github-action-php-cs-fixer@master

phpstan:
name: PHPStan for Prestashop ${{ matrix.presta-versions }}
runs-on: ubuntu-latest
strategy:
matrix:
presta-versions:
- "1.7.7.8-7.1"
- "1.6.1.24-7.1"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Scoped dependencies
run: make php-scoper

- name: PHPStan
run: |
make phpstan-${{ matrix.presta-versions }}
phpunit:
name: PHPUNIT for Prestashop ${{ matrix.presta-versions }}
name: Testsuite for Prestashop ${{ matrix.presta-versions }}
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -104,35 +85,24 @@ jobs:
run: |
make phpunit-display-logs
# - name: PHPStan
# run: |
# make phpstan

header-stamp:
name: Check license headers
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- run: make header-stamp-test
- name: PHPStan
if: matrix.presta-versions == '1.6.1.24-7.1' || matrix.presta-versions == '8.1.5-7.4'
run: |
make phpstan
# - name: Cache vendor folder
# uses: actions/cache@v3
# with:
# path: vendor
# key: php-${{ hashFiles('composer.lock') }}
#
# - name: Cache composer folder
# uses: actions/cache@v3
# with:
# path: ~/.composer/cache
# key: php-composer-cache
#
# - run: composer install
- name: header-stamp
if: matrix.presta-versions == '1.6.1.24-5.6-fpm-stretch'
run: |
make header-stamp-test
# header-stamp:
# name: Check license headers
# runs-on: ubuntu-20.04
# steps:
# - name: Checkout
# uses: actions/checkout@v3
#
# - name: Run Header Stamp in Dry Run mode
# run: php vendor/bin/header-stamp --license=vendor/prestashop/header-stamp/assets/afl.txt --exclude=.github,node_modules,vendor,vendor,tests,_dev --dry-run
# - run: make header-stamp-test

notify-earth:
if: ${{ github.event.action == 'labeled' && github.event.label.name == 'ready to review' }}
Expand Down
20 changes: 2 additions & 18 deletions .github/workflows/build-release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,10 @@ jobs:
service_account_key: ${{ secrets.G_CREDENTIAL_PRODUCTION }}
export_default_credentials: true

- name: Copy env files
run: |
gcloud components install beta
gcloud beta secrets versions access latest --secret="accounts-module-config" > ${{ github.workspace }}/config/config.yml
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.G_CREDENTIAL_PRODUCTION }}

- name: Prepare the production zip
run: |
cd ${{ github.workspace }}
sh ./scripts/bundle-module.sh ${{ env.zip_file }}
env:
ENV_FILE: ${{ secrets.PS_ACCOUNTS_ENV_PROD }}
sh ./scripts/bundle-module.sh ${{ env.zip_file }} 'prod'
- name: Publish the production zip
uses: actions/[email protected]
Expand Down Expand Up @@ -148,17 +139,10 @@ jobs:
service_account_key: ${{ secrets.G_CREDENTIAL_PREPROD }}
export_default_credentials: true

- name: Copy env files
run: |
gcloud components install beta
gcloud beta secrets versions access latest --secret="accounts-module-config" > ${{ github.workspace }}/config/config.yml
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.G_CREDENTIAL_PREPROD }}

- name: Prepare the preprod zip
run: |
cd ${{ github.workspace }}
sh ./scripts/bundle-module.sh ${{ env.zip_file }}
sh ./scripts/bundle-module.sh ${{ env.zip_file }} 'preprod'
- name: Publish the preprod zip
uses: actions/[email protected]
Expand Down
7 changes: 5 additions & 2 deletions .zip-contents
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
config
controllers
sql
src
translations
upgrade
vendor
views
CHANGELOG.md
config
config.php
config.local.php
config.prod.php
config.preprod.php
config.xml
LICENSE
logo.png
Expand Down
1 change: 1 addition & 0 deletions .zip-excludes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.idea/*
*tests/*
*config/config.yml.*
*config.*.php
*.bak/*
*.md/*
*composer.*
Expand Down
71 changes: 48 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ MODULE ?= $(shell basename ${PWD})
CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)
WORKDIR ?= .
PS_VERSION ?= base-8.2-fpm-alpine
TESTING_IMAGE ?= prestashop/prestashop-flashlight:${PS_VERSION}
TESTING_IMAGE_TAG ?= base-8.2-fpm-alpine
TESTING_IMAGE ?= prestashop/prestashop-flashlight:${TESTING_IMAGE_TAG}

default: bundle

Expand All @@ -32,8 +32,8 @@ version:
# PLATFORM

PLATFORM_REPO ?= prestashop/prestashop-flashlight
PLATFORM_REPO_TAG ?= 8.1.5-7.4
PLATFORM_IMAGE ?= ${PLATFORM_REPO}:${PHPUNIT_TAG}
PLATFORM_TAG ?= 8.1.5-7.4
PLATFORM_IMAGE ?= ${PLATFORM_REPO}:${PLATFORM_TAG}
PLATFORM_COMPOSE_FILE ?= docker-compose.flashlight.yml

COMPOSER_FILE ?= composer.json
Expand All @@ -57,9 +57,10 @@ platform-stop:

platform-restart: platform-stop platform-start

platform-module-config:
.PHONY: config.php
config.php:
@docker exec -w ${CONTAINER_INSTALL_DIR} phpunit \
sh -c "if [ ! -f ./config/config.yml ]; then cp ./config/config.yml.dist ./config/config.yml; fi"
sh -c "if [ ! -f ./config.php ]; then cp ./config.dist.php ./config.php; fi"

platform-module-version:
@docker exec -w ${CONTAINER_INSTALL_DIR} phpunit \
Expand All @@ -70,15 +71,18 @@ platform-phpstan-config:
@docker exec -w ${CONTAINER_INSTALL_DIR}/tests phpunit \
sh -c "if [ -f ./phpstan/${NEON_FILE} ]; then cp ./phpstan/${NEON_FILE} ./phpstan/phpstan.neon; fi"

platform-module-install: tests/vendor platform-phpstan-config platform-module-config platform-module-version
-@docker exec phpunit sh -c "if [ -f ./bin/console ]; then php -d memory_limit=-1 ./bin/console prestashop:module install ps_accounts; fi"
-@docker exec phpunit sh -c "if [ ! -f ./bin/console ]; then php -d memory_limit=-1 ./modules/ps_accounts/tests/install-module.php; fi"
platform-module-install: tests/vendor platform-phpstan-config config.php platform-module-version
@docker exec phpunit sh -c "if [ -f ./bin/console ]; then php -d memory_limit=-1 ./bin/console prestashop:module install ps_accounts; fi"
@docker exec phpunit sh -c "if [ ! -f ./bin/console ]; then php -d memory_limit=-1 ./modules/ps_accounts/tests/install-module.php; fi"

platform-fix-permissions:
@docker exec phpunit sh -c "if [ -d ./var ]; then chown -R www-data:www-data ./var; fi"
@docker exec phpunit sh -c "if [ -d ./cache ]; then chown -R www-data:www-data ./cache; fi" # PS1.6
@docker exec phpunit sh -c "if [ -d ./log ]; then chown -R www-data:www-data ./log; fi" # PS1.6

#platform-status:
# COMPOSER=composer71.json ./composer.phar outdated --locked -m --working-dir=./tests/

#phpunit-xdebug:
# -@docker exec phpunit sh -c "docker-php-ext-enable xdebug"

Expand All @@ -96,7 +100,7 @@ define build-platform
$(eval neonfile = $(if $(neonfile:-=),$(neonfile),${NEON_FILE}))

PLATFORM_REPO=$(repo) \
PHPUNIT_TAG=$(tag) \
PLATFORM_TAG=$(tag) \
PLATFORM_COMPOSE_FILE=.docker/$(shell echo 'docker-compose.'$(repo)'.yml' | sed 's/\//@/') \
COMPOSER_FILE=${composer} \
NEON_FILE=${neonfile} \
Expand Down Expand Up @@ -135,6 +139,9 @@ platform-1.7.8.5-7.4:
platform-8.1.5-7.4:
$(call build-platform,$@)

platform-8.2.0-8.1:
$(call build-platform,$@)

platform-nightly:
$(call build-platform,$@)

Expand Down Expand Up @@ -181,6 +188,24 @@ phpstan:
--memory-limit=-1 \
--configuration=./phpstan/phpstan.neon

##############
# HEADER-STAMP

header-stamp-test:
@docker exec -w ${CONTAINER_INSTALL_DIR} \
phpunit ./tests/vendor/bin/header-stamp \
--target="${WORKDIR}" \
--license=./tests/vendor/prestashop/header-stamp/assets/afl.txt \
--exclude=.github,node_modules,vendor,dist,tests,_dev \
--dry-run

header-stamp:
@docker exec -w ${CONTAINER_INSTALL_DIR} \
phpunit ./tests/vendor/bin/header-stamp \
--target="${WORKDIR}" \
--license=./tests/vendor/prestashop/header-stamp/assets/afl.txt \
--exclude=.github,node_modules,vendor,dist,tests,_dev

#phpstan16: NEON_FILE := phpstan-PS-1.6.neon
#phpstan16: phpstan

Expand All @@ -205,7 +230,7 @@ phpunit-nightly: platform-nightly phpunit

#"latest", "1.7.6.5", "1.6.1.21"
phpstan-1.6.1.24-7.1: platform-1.6.1.24-7.1 phpstan
phpstan-1.7.7.8-7.1: platform-1.7.7.8-7.1 phpstan
phpstan-8.1.5-7.4: platform-8.1.5-7.4 phpstan

php-cs-fixer-test-1.6.1.24-5.6-fpm-stretch: platform-1.6.1.24-5.6-fpm-stretch platform-php-cs-fixer-test
php-cs-fixer-1.6.1.24-5.6-fpm-stretch: platform-1.6.1.24-5.6-fpm-stretch platform-php-cs-fixer
Expand Down Expand Up @@ -255,13 +280,13 @@ BUNDLE_ZIP ?= # ex: ps_accounts_flavor.zip
BUNDLE_VERSION ?= $(shell grep "<version>" config.xml | sed 's/^.*\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/')
BUNDLE_JS ?= views/js/app.${BUNDLE_VERSION}.js

bundle: php-scoper config/config.yml build-front
bundle: php-scoper build-front
@./scripts/bundle-module.sh "${BUNDLE_ZIP}" "${BUNDLE_ENV}"

bundle-prod: php-scoper config/config.yml.prod build-front
bundle-prod: php-scoper config.php.prod build-front
@./scripts/bundle-module.sh "ps_accounts.zip" "prod"

bundle-preprod: php-scoper config/config.yml.preprod build-front
bundle-preprod: php-scoper config.php.preprod build-front
@./scripts/bundle-module.sh "ps_accounts_preprod.zip" "preprod"

define build_front
Expand Down Expand Up @@ -294,15 +319,15 @@ autoindex: COMPOSER_FILE := composer56.json
autoindex: tests/vendor
${PHP} ./tests/vendor/bin/autoindex prestashop:add:index "${WORKDIR}"

HEADER_STAMP_DRY_RUN ?= ''
header-stamp: COMPOSER_FILE := composer56.json
header-stamp: tests/vendor
${PHP} -d error_reporting=1 ./tests/vendor/bin/header-stamp --target="${WORKDIR}" ${HEADER_STAMP_DRY_RUN} \
--license="assets/afl.txt" --exclude=".github,node_modules,vendor,vendor,tests,_dev"

header-stamp-test: COMPOSER_FILE := composer56.json
header-stamp-test: HEADER_STAMP_DRY_RUN := '--dry-run'
header-stamp-test: tests/vendor header-stamp
#HEADER_STAMP_DRY_RUN ?= ''
#header-stamp: COMPOSER_FILE := composer56.json
#header-stamp: tests/vendor
# ${PHP} -d error_reporting=1 ./tests/vendor/bin/header-stamp --target="${WORKDIR}" ${HEADER_STAMP_DRY_RUN} \
# --license="assets/afl.txt" --exclude=".github,node_modules,vendor,vendor,tests,_dev"
#
#header-stamp-test: COMPOSER_FILE := composer56.json
#header-stamp-test: HEADER_STAMP_DRY_RUN := '--dry-run'
#header-stamp-test: tests/vendor header-stamp

##########################################################
COMPOSER_OPTIONS ?= --prefer-dist -o --no-dev --quiet
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![Source Code](https://img.shields.io/badge/source-PrestaShopCorp/ps_accounts-blue.svg?style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts)
[![Latest Version](https://img.shields.io/github/release/PrestaShopCorp/ps_accounts.svg?style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts/releases)
[![Software License](https://img.shields.io/badge/license-OSL-brightgreen.svg?style=flat-square)](https://github.com/PrestaShopCorp/oauth2-prestashop/blob/main/LICENSE)
[![Software License](https://img.shields.io/badge/license-OSL-brightgreen.svg?style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts/blob/main/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/PrestaShopCorp/ps_accounts/.github/workflows/php.yml?label=CI&logo=github&style=flat-square)](https://github.com/PrestaShopCorp/ps_accounts/actions?query=workflow%3ACI)

The module **ps_accounts** is the interface between your module and PrestaShop's services. It manages:
Expand Down
Loading

0 comments on commit 189f098

Please sign in to comment.