Skip to content

Commit

Permalink
Merge pull request #42 from TrueLayer/feature/2024-10-31-changelog
Browse files Browse the repository at this point in the history
V2.4.0
  • Loading branch information
artyom-jaksov-tl authored Nov 7, 2024
2 parents 1ed15d9 + 0d0b16e commit 005f461
Show file tree
Hide file tree
Showing 39 changed files with 1,205 additions and 39 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/check-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Check config.xml version
on:
pull_request:
types: [opened, reopened, synchronize]
branches: [main]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Set OLD_VERSION from etc/config.xml if merge would modify it
run: |
echo "OLD_VERSION=$(git log origin/main..HEAD --cherry -p -- etc/config.xml | grep '\-.\s*.<version>' | tail -1 | tr -d '\-[:blank:]\n' | sed -e 's/<version>\(.*\)<\/version>/\1/')" >> $GITHUB_ENV
- name: Set NEW_VERSION from etc/config.xml if merge would modify it
run: |
echo "NEW_VERSION=$(git log origin/main..HEAD --cherry -p -- etc/config.xml | grep '\+.\s*.<version>' | head -1 | tr -d '+[:blank:]\n' | sed -e 's/<version>\(.*\)<\/version>/\1/')" >> $GITHUB_ENV
- name: Test that versions are not empty
run: |
[[ ! -z $OLD_VERSION ]] && [[ ! -z $NEW_VERSION ]]
- name: Test that versions are different
run: |
[[ $OLD_VERSION != $NEW_VERSION ]]
- name: Test that version string mathches pattern
run: |
[[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]$ ]]
- name: Sort versions
run: |
if [[ $OLD_VERSION =~ ^[0-9]+(\.[0-9]+)+\.[0-9]$ ]]; then
echo "GREATER_VERSION=$(echo -e ${OLD_VERSION}\\n${NEW_VERSION} | sort --version-sort | tail -n1)" >> $GITHUB_ENV
else
echo "GREATER_VERSION=$NEW_VERSION" >> $GITHUB_ENV
fi
- name: Make sure new version is greater
run: |
[[ $GREATER_VERSION == $NEW_VERSION ]]
- name: Ensure changelog is not empty for the new version
run: |
CHANGELOG=$(sed -n "/^## \[v$NEW_VERSION\]/,/^## \[v/p" CHANGELOG.md | sed -e "s/^## \[v.*\$//" | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba')
[[ -n $CHANGELOG ]]
[[ $CHANGELOG == *"### Added"* || $CHANGELOG == *"### Changed"* || $CHANGELOG == *"### Fixed"* ]]
69 changes: 69 additions & 0 deletions .github/workflows/create-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Create Tag

on:
push:
branches:
- main
tags-ignore:
- '**'

jobs:
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'

- name: Generate Git Tag
id: generate_tag
run: |
NEW_TAG=v$(cat etc/config.xml | grep '<version>' | tr -d '\-[:blank:]\n' | sed -e 's/<version>\(.*\)<\/version>/\1/')
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_OUTPUT
- name: Test that version string mathches pattern
run: |
[[ $NEW_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]$ ]]
- name: Test for tag collision
run: |
TAG_EXISTS=0
for EXISTING_TAG in `git tag -l`; do
if [[ $EXISTING_TAG == $NEW_TAG || v$EXISTING_TAG == $NEW_TAG ]]; then
TAG_EXISTS=1
break
fi
done
[[ $TAG_EXISTS == 0 ]]
- name: Ensure changelog is not empty for the new tag
run: |
CHANGELOG=$(sed -n "/^## \[$NEW_TAG\]/,/^## \[v/p" CHANGELOG.md | sed -e "s/^## \[v.*\$//" | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba')
[[ -n $CHANGELOG ]]
[[ $CHANGELOG == *"### Added"* || $CHANGELOG == *"### Changed"* || $CHANGELOG == *"### Fixed"* ]]
- name: Push Git Tag
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git tag $NEW_TAG
git push origin $NEW_TAG
- name: Create changelog diff
run: |
sed -n "/^## \[$NEW_TAG\]/,/^## \[v/p" CHANGELOG.md | sed -e "s/^## \[v.*\$//" | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' > release_notes.md
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.generate_tag.outputs.NEW_TAG }}
release_name: ${{ steps.generate_tag.outputs.NEW_TAG }}
body_path: ./release_notes.md
draft: false
prerelease: false

- name: Delete release_notes file
run: rm release_notes.md
87 changes: 87 additions & 0 deletions .github/workflows/e2e-tests.yml

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ name: Lint PHP files
on: [push, pull_request]

jobs:
php-74:
runs-on: ubuntu-latest
steps:
- uses: prestashop/github-action-php-lint/[email protected]

php-81:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: Set minimum-stability for composer (temp)
run: docker exec magento-project-community-edition composer config minimum-stability dev

- name: Configure composer to mirror repository
run: docker exec magento-project-community-edition composer config repositories.truelayer \{\"type\":\"path\",\"url\":\"/data/extensions/$(basename $(pwd))\",\"options\":\{\"symlink\":false\}\}

- name: Install the extensions in Magento
run: docker exec magento-project-community-edition composer require truelayer/magento2:@dev --no-plugins --with-all-dependencies

Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/templates/wait-for-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
retries=10
count=0

while [ $count -lt $retries ]; do
mysql -uroot -e "SELECT 1" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "MySQL is available."
break
fi
count=$((count+1))
echo "MySQL is not available. Retrying..."
sleep 1
done

if [ $count -eq $retries ]; then
echo "Could not connect to MySQL after $retries retries."
exit 1;
fi

echo "Now connecting to Elasticsearch"
retries=20
count=0

while [ $count -lt $retries ]; do
if curl -s -f -o /dev/null "http://localhost:9200"; then
echo "Elasticsearch is available."
break
else
count=$((count+1))
echo "Attempt $count of $retries: Elasticsearch is not available. Retrying..."
sleep 1
fi
done

if [ $count -eq $retries ]; then
cat /var/log/elasticsearch/elasticsearch.log
echo "Could not connect to Elasticsearch after $retries retries."
fi
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
.DS_Store
docker
.vscode
.php-cs-fixer.cache
/node_modules
/test-results
/playwright-report
/results.xml
private-key.pem
56 changes: 56 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__)
->exclude(['.github', '.vscode', 'docker', 'vendor'])
->ignoreDotFiles(false);

$rules = [
'@PSR1' => true,
'@PSR2' => true,
'@PSR12' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => [
'class',
'function',
'const'
]
],
'single_line_empty_body' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'no_whitespace_in_blank_line' => true,
'whitespace_after_comma_in_array' => [
'ensure_single_space' => true
],
'no_multiline_whitespace_around_double_arrow' => true,
'no_trailing_comma_in_singleline_array' => true,
'normalize_index_brace' => true,
'trim_array_spaces' => true,
'single_class_element_per_statement' => [
'elements' => [
'const',
'property'
]
],
'visibility_required' => [
'elements' => [
'property',
'method',
'const'
]
],
'align_multiline_comment' => true
];

$config = new Config();
$config->setFinder($finder);
$config->setRules($rules);
$config->setIndent(' ');
$config->setLineEnding("\n");

return $config;
1 change: 1 addition & 0 deletions Api/Config/System/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface ConnectionInterface extends DebugInterface
public const XML_PATH_PRODUCTION_CLIENT_SECRET = 'payment/truelayer/production_client_secret';
public const XML_PATH_PRODUCTION_PRIVATE_KEY = 'payment/truelayer/production_private_key';
public const XML_PATH_PRODUCTION_KEY_ID = 'payment/truelayer/production_key_id';
public const XML_PATH_CACHE_ENCRYPTION_KEY = 'payment/truelayer/cache_encryption_key';

/**
* Get Merchant Account Name
Expand Down
65 changes: 57 additions & 8 deletions Block/Adminhtml/System/Config/Button/VersionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

namespace TrueLayer\Connect\Block\Adminhtml\System\Config\Button;

use TrueLayer\Connect\Api\Config\RepositoryInterface as ConfigRepository;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\HTTP\Client\Curl;
use TrueLayer\Connect\Api\Config\RepositoryInterface as ConfigRepository;
use TrueLayer\Connect\Api\Log\LogServiceInterface;

/**
* Version check class
Expand All @@ -22,10 +24,6 @@ class VersionCheck extends Field
* @var string
*/
protected $_template = 'TrueLayer_Connect::system/config/button/version.phtml';
/**
* @var ConfigRepository
*/
private $configRepository;

/**
* VersionCheck constructor.
Expand All @@ -35,10 +33,11 @@ class VersionCheck extends Field
*/
public function __construct(
Context $context,
ConfigRepository $configRepository,
private ConfigRepository $configRepository,
private Curl $curl,
private LogServiceInterface $logger,
array $data = []
) {
$this->configRepository = $configRepository;
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -66,6 +65,56 @@ public function _getElementHtml(AbstractElement $element): string
*/
public function getVersion(): string
{
return 'v' . $this->configRepository->getExtensionVersion();
return $this->configRepository->getExtensionVersion();
}

public function getLatestVersion()
{
$curlVersion = $this->getCurlVersion();
$this->curl->addHeader('Accept', 'application/vnd.github+json');
$this->curl->addHeader('User-Agent', 'curl/'.$curlVersion);
$this->curl->setOption(CURLOPT_RETURNTRANSFER, true);
$this->curl->get('https://api.github.com/repos/TrueLayer/magento2/releases');
$responseStatus = $this->curl->getStatus();
if ($responseStatus !== 200) {
$this->logger->error('Plugin version check failed, could not retrieve releases from github api', [
'response_status' => $responseStatus,
'response_body' => $this->curl->getBody()
]);
return false;
}
$response = $this->curl->getBody();
try {
$releases = json_decode($response, true, JSON_THROW_ON_ERROR);
} catch (\Exception $e) {
$this->logger->error('Plugin version check failed, json_decode error', [
'response_body' => $response,
'json_exception' => $e->getMessage()
]);
return false;
}
foreach ($releases as $release) {
if (!$release['draft'] && !$release['prerelease']) {
$latestRelease = $release;
break;
}
}
if (!isset($latestRelease)) {
$this->logger->error('Plugin version check failed, no valid release in github api response');
return false;
}
$latestVersion = ltrim($latestRelease['name'], 'v');
return $latestVersion;
}

private function getCurlVersion()
{
$curlVersion = curl_version();
if (is_array($curlVersion) && array_key_exists('version', $curlVersion)) {
$curlVersion = $curlVersion['version'];
} else {
$curlVersion = 'unknown';
}
return $curlVersion;
}
}
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v2.4.0] - 2024-11-06

### Added

- A notice will appear on the settings page of the plugin if a newer version of the plugin is available.
- Added "Magento Order Increment ID" to payment metadata when creating the payment in Truelayer.
- PSR-16 cache adapter
- Automatically generate cache encryption key

### Changed

- Using constant filename new uploaded private keys
- Increased PHP dependency version
- Increased TrueLayer PHP Client dependency version

### Fixed

- Potential security issue when deleting a private key

## [v2.3.0] - 2024-09-27

### Added
Expand Down
3 changes: 2 additions & 1 deletion Controller/Adminhtml/Credentials/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ private function getCredentials(): array
'client_id' => $clientId,
'client_secret' => $clientSecret,
'private_key' => $this->getPrivateKeyPath($configCredentials),
'key_id' => $keyId
'key_id' => $keyId,
'cache_encryption_key' => $configCredentials['cache_encryption_key']
]
];
}
Expand Down
Loading

0 comments on commit 005f461

Please sign in to comment.