Skip to content

Commit

Permalink
Merge pull request #621 from mollie/release/2.23.0
Browse files Browse the repository at this point in the history
Release/2.23.0
  • Loading branch information
Marvin-Magmodules authored Mar 10, 2023
2 parents 6fd1e63 + 9c34b08 commit 7553c8a
Show file tree
Hide file tree
Showing 28 changed files with 6,863 additions and 1,315 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ on:

jobs:
analyze:
if: github.repository_owner == 'mollie'

name: Analyze
runs-on: ubuntu-latest
permissions:
Expand All @@ -48,11 +50,11 @@ jobs:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
Expand All @@ -61,7 +63,7 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
Expand Down
64 changes: 49 additions & 15 deletions .github/workflows/end-2-end-test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
name: End-2-end
on: [push, pull_request]
on:
pull_request:
types:
- opened
- labeled

jobs:
secrets-gate:
# Only run tests if the pull request is opened or labeled with run_e2e_tests
if: ${{ github.event.label.name == 'run_e2e_tests' || github.event.action != 'labeled' }}
runs-on: ubuntu-latest
outputs:
is-secret-set: ${{ steps.is-secret-set.outputs.is_mollie_api_key_test_set }}
Expand All @@ -13,23 +19,44 @@ jobs:
if: "${{ env.MOLLIE_API_KEY_TEST != '' }}"
run: echo "is_mollie_api_key_test_set=true" >> $GITHUB_OUTPUT

build:
# Remove flag used to trigger the e2e tests
remove_flag:
if: ${{ contains(github.event.*.labels.*.name, 'run_e2e_tests') }}
runs-on: ubuntu-latest
steps:
- name: Remove run E2E tests label
uses: actions/github-script@v5
with:
script: |
github.rest.issues.removeLabel({
issue_number: ${{ github.event.issue.number || github.event.number }},
owner: context.repo.owner,
repo: context.repo.repo,
name: "run_e2e_tests"
})
e2e-tests:
concurrency: e2e-tests

needs:
- secrets-gate
# Only run this job if the secret is set
if: needs.secrets-gate.outputs.is-secret-set == 'true'
strategy:
fail-fast: false
max-parallel: 1
matrix:
include:
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.3.7-p3
- PHP_VERSION: php81-fpm
MAGENTO_VERSION: 2.4.4
MAGENTO_VERSION: 2.4.5-p1
runs-on: ubuntu-latest
env:
PHP_VERSION: ${{ matrix.PHP_VERSION }}
MAGENTO_VERSION: ${{ matrix.MAGENTO_VERSION }}
MOLLIE_API_KEY_TEST: ${{ secrets.MOLLIE_API_KEY_TEST }}
NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
CYPRESS_TESTRAIL_DOMAIN: ${{ secrets.TESTRAIL_DOMAIN }}
CYPRESS_TESTRAIL_USERNAME: ${{ secrets.TESTRAIL_USERNAME }}
Expand All @@ -44,49 +71,56 @@ jobs:
- name: Start the Magento container
run: |
openssl req -x509 -newkey rsa:4096 -keyout .github/workflows/templates/nginx-proxy/magento.test.key -out .github/workflows/templates/nginx-proxy/magento.test.crt -days 365 -nodes -subj "/CN=magento.test" && \
docker-compose -f .github/workflows/templates/docker-compose.yml up -d magento
docker-compose -f .github/workflows/templates/docker-compose.yml up -d
# Get the URL from ngrok
docker-compose -f .github/workflows/templates/docker-compose.yml logs ngrok
MAGENTO_URL=$(docker exec magento-project-community-edition /bin/bash -c "curl -s ngrok:4040/api/tunnels |jq -r \".tunnels[0].public_url\"")
echo "magento_url=$MAGENTO_URL" >> $GITHUB_ENV
- name: Upload the code into the docker container
run: |
sed -i '/version/d' ./composer.json && \
docker cp $(pwd) magento-project-community-edition:/data/extensions/ && \
docker exec magento-project-community-edition composer require mollie/magento2:@dev
docker exec magento-project-community-edition composer require mollie/magento2:@dev --no-plugins
- name: Activate the extension
run: |
docker exec magento-project-community-edition ./retry "php bin/magento module:enable Mollie_Payment" && \
docker exec magento-project-community-edition ./retry "php bin/magento setup:upgrade" && \
docker exec magento-project-community-edition ./retry "php bin/magento module:enable Mollie_Payment"
docker exec magento-project-community-edition ./retry "php bin/magento setup:upgrade"
docker exec magento-project-community-edition /bin/bash /data/configure-mollie.sh
docker exec magento-project-community-edition ./retry "bin/magento config:set payment/mollie_general/use_webhooks custom_url"
docker exec magento-project-community-edition ./retry "bin/magento config:set payment/mollie_general/custom_webhook_url ${{ env.magento_url }}/mollie/checkout/webhook"
- name: Prepare Magento
run: |
docker exec magento-project-community-edition /bin/bash ./change-base-url https://magento.test/ && \
docker exec magento-project-community-edition ./retry "php bin/magento setup:di:compile" && \
docker exec magento-project-community-edition ./retry "php bin/magento setup:static-content:deploy -f" && \
docker exec magento-project-community-edition /bin/bash ./change-base-url https://magento.test/
docker exec magento-project-community-edition ./retry "php bin/magento setup:di:compile"
docker exec magento-project-community-edition ./retry "php bin/magento setup:static-content:deploy -f"
docker exec magento-project-community-edition ./retry "php bin/magento indexer:reindex"
- name: Start all containers and check if we can reach Magento (and warmup cache)
run: |
docker-compose -f .github/workflows/templates/docker-compose.yml up -d && \
docker exec e2e curl -k -s -o /dev/null -w "%{http_code}" https://magento.test/
docker exec e2e curl -k -s -o /dev/null -w "%{http_code}" ${{ env.magento_url }}
- name: Run Cypress
run: |
docker cp .git e2e:/e2e/.git && \
docker exec e2e cypress run --browser chrome --record --key $CYPRESS_RECORD_KEY --config defaultCommandTimeout=20000
# Copy the .git folder for Cypress
docker cp .git e2e:/e2e/.git
docker exec e2e cypress run --browser chrome --config defaultCommandTimeout=20000
- name: Dump docker-compose logs
if: always()
run: |
docker-compose -f .github/workflows/templates/docker-compose.yml logs magento > magento.log && \
docker-compose -f .github/workflows/templates/docker-compose.yml logs nginx-proxy > nginx-proxy.log && \
docker-compose -f .github/workflows/templates/docker-compose.yml logs ngrok > ngrok.log && \
docker-compose -f .github/workflows/templates/docker-compose.yml logs e2e > e2e.log
- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: E2E logs
name: E2E logs - ${{ matrix.PHP_VERSION }} - ${{ matrix.MAGENTO_VERSION }}
path: |
Test/End-2-end/cypress/videos
magento-logs
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
- name: Start Docker
run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }}

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json
- name: Remove version from composer.json
run: sed -i '/version/d' ./composer.json

- name: Upload the code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require mollie/magento2:dev-continuous-integration-test-branch
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require mollie/magento2:@dev --no-plugins

- name: Activate the extension
run: docker exec magento-project-community-edition ./retry "php bin/magento module:enable Mollie_Payment && php bin/magento setup:upgrade"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
- name: Start Docker
run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }}

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json
- name: Remove version from composer.json
run: sed -i '/version/d' ./composer.json

- name: Upload our code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/

- name: Install the extensions in Magento
run: docker exec magento-project-community-edition composer require mollie/magento2:dev-continuous-integration-test-branch
run: docker exec magento-project-community-edition composer require mollie/magento2:@dev --no-plugins

- name: Activate the extension
run: docker exec magento-project-community-edition ./retry "php bin/magento module:enable Mollie_Payment && php bin/magento setup:upgrade && php bin/magento setup:di:compile"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/setup-di-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
- name: Start Docker
run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }}

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json
- name: Remove version from composer.json
run: sed -i '/version/d' ./composer.json

- name: Upload our code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/

- name: Install the extension in Magento
run: docker exec magento-project-community-edition composer require mollie/magento2:dev-continuous-integration-test-branch
run: docker exec magento-project-community-edition composer require mollie/magento2:@dev --no-plugins

- name: Run setup:di:compile
run: docker exec magento-project-community-edition ./retry "php bin/magento setup:di:compile"
9 changes: 8 additions & 1 deletion .github/workflows/templates/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ services:
container_name: magento-project-community-edition
environment:
- VIRTUAL_HOST=magento.test
- URL=https://magento.test/
- MOLLIE_API_KEY_TEST
volumes:
- ../../../magento-logs:/data/var/log
- ./magento/configure-mollie.sh:/data/configure-mollie.sh
depends_on:
- ngrok

nginx-proxy:
image: jwilder/nginx-proxy
Expand All @@ -20,6 +21,12 @@ services:
- ./nginx-proxy/magento.test.key:/etc/nginx/certs/magento.test.key
- /var/run/docker.sock:/tmp/docker.sock:ro

ngrok:
image: ngrok/ngrok:latest
command: http http://magento
environment:
- NGROK_AUTHTOKEN

e2e:
build: ./e2e
container_name: e2e
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
- name: Start Docker
run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }}

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json
- name: Remove version from composer.json
run: sed -i '/version/d' ./composer.json

- name: Upload the code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require mollie/magento2:dev-continuous-integration-test-branch
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require mollie/magento2:@dev --no-plugins

- name: Activate the extension
run: docker exec magento-project-community-edition ./retry "php bin/magento module:enable Mollie_Payment && php bin/magento setup:upgrade && php bin/magento setup:di:compile"
Expand Down
30 changes: 30 additions & 0 deletions GraphQL/Resolver/General/MollieStoreConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Mollie\Payment\GraphQL\Resolver\General;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Mollie\Payment\Config;

class MollieStoreConfig implements ResolverInterface
{
/**
* @var Config
*/
private $config;

public function __construct(
Config $config
) {
$this->config = $config;
}

public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
return [
'profile_id' => $this->config->getProfileId(),
'live_mode' => $this->config->isProductionMode(),
];
}
}
39 changes: 39 additions & 0 deletions Plugin/Sales/Api/OrderManagementPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Mollie\Payment\Plugin\Sales\Api;

use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\OrderManagementInterface;
use Mollie\Payment\Service\LockService;

class OrderManagementPlugin
{
/**
* @var LockService
*/
private $lockService;

public function __construct(
LockService $lockService
) {
$this->lockService = $lockService;
}

public function aroundCancel(
OrderManagementInterface $subject,
callable $proceed,
$orderId
) {
// Lock the order, so we are sure that there are no other operations running on the order at the same time.
$key = 'mollie.order.' . $orderId;
if (!$this->lockService->lock($key)) {
throw new LocalizedException(__('Unable to get lock for %1', $key));
}

$result = $proceed($orderId);

$this->lockService->unlock($key);

return $result;
}
}
24 changes: 22 additions & 2 deletions Service/LockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class LockService
*/
private $resourceConnection;

/**
* @var bool
*/
private $alreadyLocked = false;

public function __construct(
Config $config,
ResourceConnection $resourceConnection
Expand All @@ -60,16 +65,25 @@ public function __construct(
*/
public function lock(string $name, int $timeout = -1): bool
{
// Make sure we only lock once per request.
if ($this->alreadyLocked) {
return true;
}

$this->config->addToLog('info', 'Locking: ' . $name);
if ($this->isLockManagerAvailable()) {
return $this->lockManager->lock($name, $timeout);
return $this->alreadyLocked = $this->lockManager->lock($name, $timeout);
}

$result = (bool)$this->getConnection()->query(
"SELECT GET_LOCK(?, ?);",
[$name, $timeout < 0 ? 60 * 60 * 24 * 7 : $timeout]
)->fetchColumn();

if ($result) {
$this->alreadyLocked = true;
}

return $result;
}

Expand All @@ -83,14 +97,20 @@ public function unlock(string $name): bool
{
$this->config->addToLog('info', 'Unlocking: ' . $name);
if ($this->isLockManagerAvailable()) {
return $this->lockManager->unlock($name);
$result = $this->lockManager->unlock($name);
$this->alreadyLocked = !$result;
return $result;
}

$result = (bool)$this->getConnection()->query(
"SELECT RELEASE_LOCK(?);",
[(string)$name]
)->fetchColumn();

if ($result) {
$this->alreadyLocked = false;
}

return $result;
}

Expand Down
Loading

0 comments on commit 7553c8a

Please sign in to comment.