Skip to content

Commit ba54e9d

Browse files
authored
Merge pull request #2 from mbissonho/release/1.0.0
Release 1.0.0
2 parents a1af092 + 3aad862 commit ba54e9d

19 files changed

+690
-6
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: E2E Tests
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- 'main'
9+
jobs:
10+
run:
11+
strategy:
12+
matrix:
13+
php-version: ["8.3"]
14+
magento-version: [ "2.4.7-p4"]
15+
runs-on: ubuntu-latest
16+
env:
17+
PHP_VERSION: ${{ matrix.php-version }}
18+
MAGENTO_VERSION: ${{ matrix.magento-version }}
19+
MAGENTO_ADMIN_USERNAME: admin
20+
MAGENTO_ADMIN_PASSWORD: admin123
21+
MAGENTO_HOST: magento2.test.com
22+
MAGENTO_BASE_URL: http://magento2.test.com
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Install Magento
26+
run: |
27+
docker compose -f .github/workflows/e2e-tests/docker-compose.yml run --rm web bash -c "sed '/exec /d' /tmp/install_magento.sh | bash"
28+
- name: Start web server in background
29+
run: docker compose -f .github/workflows/e2e-tests/docker-compose.yml up -d web
30+
- name: Setup permissions
31+
run: |
32+
docker exec e2e-magento2 bash -c "find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + &&
33+
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + &&
34+
chmod 777 -R var &&
35+
chown -R www-data:www-data . &&
36+
chmod u+x bin/magento &&
37+
echo 'memory_limit = -1' > /usr/local/etc/php/conf.d/memory.ini"
38+
- name: Install Extension
39+
run: |
40+
docker exec -u www-data e2e-magento2 bash -c "/tmp/install_extension.sh"
41+
- name: Run E2E Tests
42+
run: |
43+
docker compose -f .github/workflows/e2e-tests/docker-compose.playwright.yml run playwright \
44+
bash -c "chmod +x /tmp/module/.github/workflows/e2e-tests/run-e2e.sh && /tmp/module/.github/workflows/e2e-tests/run-e2e.sh"
45+
env:
46+
CI: TRUE
47+
- name: Archive test result artifacts
48+
if: always()
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: html-report
52+
path: test-report
53+
54+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
ARG PHP_VERSION
2+
FROM php:${PHP_VERSION}-apache
3+
4+
ENV MAGENTO_HOST="<will be defined>" \
5+
DB_SERVER="<will be defined>" \
6+
DB_PORT=3306 \
7+
DB_NAME=magento \
8+
DB_USER=magento \
9+
DB_PASSWORD=magento \
10+
DB_PREFIX=m2_ \
11+
OPENSEARCH_SERVER="<will be defined>" \
12+
OPENSEARCH_PORT=9200 \
13+
OPENSEARCH_INDEX_PREFIX=magento2 \
14+
OPENSEARCH_TIMEOUT=15 \
15+
ADMIN_NAME=admin \
16+
ADMIN_LASTNAME=admin \
17+
ADMIN_EMAIL=admin@example.com \
18+
ADMIN_USERNAME=admin \
19+
ADMIN_PASSWORD=admin123 \
20+
ADMIN_URLEXT=admin \
21+
MAGENTO_LANGUAGE=pt_BR \
22+
MAGENTO_CURRENCY=BRL \
23+
MAGENTO_TZ=America/Sao_Paulo \
24+
DEPLOY_SAMPLEDATA=0 \
25+
USE_SSL=0
26+
27+
RUN apt-get update \
28+
&& apt-get install -y libjpeg62-turbo-dev \
29+
libpng-dev \
30+
libfreetype6-dev \
31+
libxml2-dev \
32+
libzip-dev \
33+
libssl-dev \
34+
libxslt-dev \
35+
default-mysql-client \
36+
wget \
37+
cron \
38+
unzip
39+
40+
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
41+
RUN docker-php-ext-install -j$(nproc) bcmath gd intl pdo_mysql simplexml soap sockets xsl zip
42+
RUN a2enmod rewrite
43+
44+
RUN rm -f /etc/apache2/sites-enabled/default-ssl.conf
45+
46+
WORKDIR /var/www/html
47+
COPY php.ini /usr/local/etc/php/
48+
COPY install_magento.sh /tmp/install_magento.sh
49+
COPY install_extension.sh /tmp/install_extension.sh
50+
51+
ARG MAGENTO_VERSION
52+
ADD "https://github.com/magento/magento2/archive/refs/tags/${MAGENTO_VERSION}.tar.gz" /tmp/magento.tar.gz
53+
54+
RUN chmod +x /tmp/install_magento.sh
55+
RUN chmod +x /tmp/install_extension.sh
56+
57+
CMD ["bash", "/tmp/install_magento.sh"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '3'
2+
services:
3+
playwright:
4+
image: mcr.microsoft.com/playwright:v1.50.1
5+
shm_size: 1gb
6+
ipc: host
7+
cap_add:
8+
- SYS_ADMIN
9+
networks:
10+
- backend
11+
environment:
12+
- MAGENTO_BASE_URL
13+
- MAGENTO_ADMIN_USERNAME
14+
- MAGENTO_ADMIN_PASSWORD
15+
- CI
16+
volumes:
17+
- ../../../:/tmp/module
18+
networks:
19+
backend:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
version: '3'
2+
3+
services:
4+
db:
5+
image: mariadb:10.4
6+
container_name: e2e-mariadb
7+
networks:
8+
- backend
9+
environment:
10+
MARIADB_ROOT_PASSWORD: root_password
11+
MARIADB_DATABASE: magento
12+
MARIADB_USER: magento
13+
MARIADB_PASSWORD: magento
14+
opensearch:
15+
image: bitnami/opensearch:2
16+
container_name: e2e-opensearch
17+
networks:
18+
- backend
19+
ports:
20+
- 9200:9200
21+
- 9300:9300
22+
environment:
23+
- "discovery.type=single-node"
24+
- "ES_JAVA_OPTS=-Xms750m -Xmx750m"
25+
web:
26+
build:
27+
context: .
28+
args:
29+
- PHP_VERSION=${PHP_VERSION}
30+
- MAGENTO_VERSION=${MAGENTO_VERSION}
31+
container_name: e2e-magento2
32+
extra_hosts:
33+
- ${MAGENTO_HOST}:127.0.0.1
34+
# ports:
35+
# - 80:80
36+
networks:
37+
backend:
38+
aliases:
39+
- ${MAGENTO_HOST}
40+
environment:
41+
DB_SERVER: e2e-mariadb
42+
OPENSEARCH_SERVER: e2e-opensearch
43+
MAGENTO_HOST: ${MAGENTO_HOST}
44+
VIRTUAL_HOST: ${MAGENTO_HOST}
45+
COMPOSER_MEMORY_LIMIT: -1
46+
ADMIN_URLEXT: admin
47+
depends_on:
48+
- db
49+
- opensearch
50+
volumes:
51+
- ../../../:/data/extensions/workdir
52+
- composer:/usr/local/bin
53+
- magento:/var/www/html
54+
networks:
55+
backend:
56+
volumes:
57+
magento:
58+
composer:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
composer config --json repositories.local '{"type": "path", "url": "/data/extensions/workdir", "options": { "symlink": false } }'
4+
composer require "mbissonho/module-remember-admin-last-page:*"
5+
bin/magento module:disable Magento_TwoFactorAuth
6+
bin/magento module:disable Magento_AdminAnalytics
7+
bin/magento module:enable Mbissonho_RememberAdminLastPage
8+
bin/magento config:set admin/usage/enabled 0
9+
bin/magento config:set admin/mbissonho_remember_admin_last_page/active 1
10+
# Ensure short admin session lifetime
11+
bin/magento config:set admin/security/session_lifetime 60
12+
bin/magento setup:upgrade
13+
bin/magento setup:di:compile
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/bin/bash
2+
3+
MAGENTO_INSTALL_ARGS="";
4+
5+
if [ "$DB_SERVER" != "<will be defined>" ]; then
6+
RET=1
7+
while [ $RET -ne 0 ]; do
8+
echo "Checking if $DB_SERVER is available."
9+
mysql -h "$DB_SERVER" -P "$DB_PORT" -u "$DB_USER" -p"$DB_PASSWORD" -e "status" >/dev/null 2>&1
10+
RET=$?
11+
12+
if [ $RET -ne 0 ]; then
13+
echo "Connection to MySQL/MariaDB is pending."
14+
sleep 5
15+
fi
16+
done
17+
echo "DB server $DB_SERVER is available."
18+
else
19+
echo "MySQL/MariaDB server is not defined!"
20+
exit 1
21+
fi
22+
23+
if [ "$OPENSEARCH_SERVER" != "<will be defined>" ]; then
24+
MAGENTO_INSTALL_ARGS=$(echo \
25+
--search-engine="opensearch" \
26+
--opensearch-host="$OPENSEARCH_SERVER" \
27+
--opensearch-port="$OPENSEARCH_PORT" \
28+
--opensearch-index-prefix="$OPENSEARCH_INDEX_PREFIX" \
29+
--opensearch-timeout="$OPENSEARCH_TIMEOUT")
30+
RET=1
31+
while [ $RET -ne 0 ]; do
32+
echo "Checking if $OPENSEARCH_SERVER is available."
33+
curl -XGET "$OPENSEARCH_SERVER:$OPENSEARCH_PORT/_cat/health?v&pretty" >/dev/null 2>&1
34+
RET=$?
35+
36+
if [ $RET -ne 0 ]; then
37+
echo "Connection to OpenSearch is pending."
38+
sleep 5
39+
fi
40+
done
41+
echo "OpenSearch server $OPENSEARCH_SERVER is available."
42+
fi
43+
44+
echo "Current directory: $(pwd)"
45+
46+
if [[ -e /tmp/magento.tar.gz ]]; then
47+
mv /tmp/magento.tar.gz /var/www/html
48+
else
49+
echo "Magento 2 tar is already moved to /var/www/html"
50+
fi
51+
52+
if [[ -e /var/www/html/pub/index.php ]]; then
53+
echo "Already extracted Magento"
54+
else
55+
tar -xf magento.tar.gz --strip-components 1
56+
rm magento.tar.gz
57+
fi
58+
59+
if [[ -e /usr/local/bin/composer ]]; then
60+
echo "Composer already exists"
61+
else
62+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
63+
php composer-setup.php --quiet
64+
rm composer-setup.php
65+
mv composer.phar /usr/local/bin/composer
66+
fi
67+
68+
if [[ -d /var/www/html/vendor/magento ]]; then
69+
echo "Magento is already installed."
70+
else
71+
composer install -n
72+
73+
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
74+
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
75+
chown -R www-data:www-data .
76+
chmod u+x bin/magento
77+
78+
bin/magento setup:install \
79+
--base-url="http://$MAGENTO_HOST" \
80+
--db-host="$DB_SERVER:$DB_PORT" \
81+
--db-name="$DB_NAME" \
82+
--db-user="$DB_USER" \
83+
--db-password="$DB_PASSWORD" \
84+
--db-prefix="$DB_PREFIX" \
85+
--admin-firstname="$ADMIN_NAME" \
86+
--admin-lastname="$ADMIN_LASTNAME" \
87+
--admin-email="$ADMIN_EMAIL" \
88+
--admin-user="$ADMIN_USERNAME" \
89+
--admin-password="$ADMIN_PASSWORD" \
90+
--backend-frontname="$ADMIN_URLEXT" \
91+
--language="$MAGENTO_LANGUAGE" \
92+
--currency="$MAGENTO_CURRENCY" \
93+
--timezone="$MAGENTO_TZ" \
94+
--use-rewrites=1 \
95+
--cleanup-database \
96+
$MAGENTO_INSTALL_ARGS;
97+
98+
bin/magento setup:di:compile
99+
bin/magento setup:static-content:deploy -f
100+
bin/magento indexer:reindex
101+
bin/magento deploy:mode:set developer
102+
bin/magento maintenance:disable
103+
104+
echo "Installation completed"
105+
fi
106+
107+
ISSET_USE_SSL=$(bin/magento config:show web/secure/use_in_frontend)
108+
109+
if [ "$USE_SSL" -eq 1 ]; then
110+
if [ "${ISSET_USE_SSL:-0}" -eq 1 ]; then
111+
echo "Use SSL is set, but SSL is already enabled."
112+
else
113+
bin/magento setup:store-config:set \
114+
--base-url-secure="https://$MAGENTO_HOST" \
115+
--use-secure=1 \
116+
--use-secure-admin=1
117+
echo "SSL for Magento is configured."
118+
fi
119+
else
120+
echo "Use SSL is not set, skipping."
121+
fi
122+
123+
grep "ServerName" /etc/apache2/apache2.conf >/dev/null 2>&1
124+
SERVERNAME_EXISTS=$?
125+
126+
if [ $SERVERNAME_EXISTS -eq 0 ]; then
127+
echo "ServerName is already added in Apache config."
128+
else
129+
echo "ServerName $MAGENTO_HOST" >>/etc/apache2/apache2.conf
130+
echo "ServerName is added to Apache config."
131+
fi
132+
133+
echo "Magento configuration"
134+
bin/magento config:show
135+
136+
exec apache2-foreground

.github/workflows/e2e-tests/php.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
memory_limit = 2G
2+
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
3+
display_errors = Off
4+
display_startup_errors = On
5+
post_max_size = 20M
6+
upload_max_filesize = 20M
7+
date.timezone = America/Sao_Paulo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
cd /tmp/module/e2e
3+
rm -rf package-lock.json
4+
npm i
5+
npx playwright install --with-deps
6+
npx playwright test -c playwright-ci.config.js

.github/workflows/integration-tests.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ on:
88
- 'main'
99

1010
jobs:
11-
integration-tests:
12-
name: Integration Tests
11+
run:
12+
strategy:
13+
matrix:
14+
php-version: [ "8.3" ]
15+
magento-version: [ "2.4.7-p4" ]
1316
runs-on: ubuntu-latest
1417
services:
1518
mysql:
@@ -30,8 +33,9 @@ jobs:
3033
options: --health-cmd="curl localhost:9200/_cluster/health?wait_for_status=yellow&timeout=60s" --health-interval=10s --health-timeout=5s --health-retries=3
3134
steps:
3235
- uses: actions/checkout@v3
33-
- name: Magento 2.4.6 Integration Tests (Php8.2)
34-
uses: extdn/github-actions-m2/magento-integration-tests/8.2@master
36+
- name: Magento ${{ matrix.magento-version }} Integration Tests (Php${{ matrix.php-version }})
37+
uses: extdn/github-actions-m2/magento-integration-tests/8.3@master
3538
with:
3639
module_name: Mbissonho_RememberAdminLastPage
3740
composer_name: mbissonho/module-remember-admin-last-page
41+
magento_version: ${{ matrix.magento-version }}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.0] - 2025-02-04
9+
10+
### Added
11+
- Automated Tests
12+
13+
### Fixed
14+
- Improve code quality
15+
816
## [0.1.0] - 2024-02-01
917

1018
### Added

0 commit comments

Comments
 (0)