Skip to content

Commit

Permalink
Add GitHub Workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Mar 4, 2024
1 parent 0478076 commit fcde1e4
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github: yireo
custom: ["https://www.paypal.me/yireo"]

2 changes: 2 additions & 0 deletions .github/workflows/extdn-integration-tests-post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=redis --cache-backend-redis-db=0 -n
9 changes: 9 additions & 0 deletions .github/workflows/extdn-integration-tests-pre-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
composer config minimum-stability dev
composer config prefer-stable false

composer require yireo/magento2-integration-test-helper --no-update

composer require yireo/magento2-replace-bundled:^4.0 --no-update
composer require yireo/magento2-replace-inventory:^4.0 --no-update
composer require yireo/magento2-replace-pagebuilder:^4.0 --no-update
50 changes: 50 additions & 0 deletions .github/workflows/extdn-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: ExtDN Integration Tests
on: [push]

jobs:
integration-tests:
name: Magento 2 Integration Tests
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --tmpfs /tmp:rw --tmpfs /var/lib/mysql:rw --health-cmd="mysqladmin ping"
es:
image: docker.io/wardenenv/elasticsearch:7.8
ports:
- 9200:9200
env:
'discovery.type': single-node
'xpack.security.enabled': false
ES_JAVA_OPTS: "-Xms64m -Xmx512m"
options: --health-cmd="curl localhost:9200/_cluster/health?wait_for_status=yellow&timeout=60s" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
ports:
- 6379:6379
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
env:
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
MODULE_NAME: ${{ secrets.MODULE_NAME }}
COMPOSER_NAME: ${{ secrets.COMPOSER_NAME }}
steps:
- uses: actions/checkout@v2

- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- uses: extdn/github-actions-m2/magento-integration-tests/8.1@master
env:
MAGENTO_VERSION: '2.4.5-p1'
COMPOSER_VERSION: 2
with:
magento_pre_install_script: .github/workflows/extdn-integration-tests-pre-install.sh
magento_post_install_script: .github/workflows/extdn-integration-tests-post-install.sh
12 changes: 12 additions & 0 deletions .github/workflows/extdn-phpstan-tests-pre-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
composer config minimum-stability dev
composer config prefer-stable false
composer config --no-plugins allow-plugins true

composer require yireo/magento2-integration-test-helper --no-update

composer require yireo/magento2-integration-test-helper --no-update
composer require yireo/magento2-replace-bundled:^4.0 --no-update
composer require yireo/magento2-replace-inventory:^4.0 --no-update
composer require yireo/magento2-replace-pagebuilder:^4.0 --no-update

22 changes: 22 additions & 0 deletions .github/workflows/extdn-phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: ExtDN PHPStan
on: [push, pull_request]

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- uses: docker://extdn/magento-phpstan-action:7.4-latest
with:
composer_name: ${{ secrets.COMPOSER_NAME }}
composer_version: 2
phpstan_level: 2
magento_pre_install_script: .github/workflows/extdn-phpstan-tests-pre-install.sh
30 changes: 30 additions & 0 deletions .github/workflows/extdn-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ExtDN Unit Tests
on: [push]

jobs:
unit-tests:
name: Magento 2 Unit Tests
runs-on: ubuntu-latest
env:
MAGENTO_MARKETPLACE_USERNAME: ${{ secrets.MAGENTO_MARKETPLACE_USERNAME }}
MAGENTO_MARKETPLACE_PASSWORD: ${{ secrets.MAGENTO_MARKETPLACE_PASSWORD }}
MODULE_NAME: ${{ secrets.MODULE_NAME }}
COMPOSER_NAME: ${{ secrets.COMPOSER_NAME }}
steps:
- uses: actions/checkout@v2

- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- uses: extdn/github-actions-m2/magento-unit-tests/7.3@master
env:
MAGENTO_VERSION: '2.3.7-p3'
COMPOSER_VERSION: 1

- uses: extdn/github-actions-m2/magento-unit-tests/8.1@master
env:
MAGENTO_VERSION: '2.4.5-p1'
COMPOSER_VERSION: 2
16 changes: 7 additions & 9 deletions Link/LinkParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Yireo\LinkPreload\Link;

use DOMDocument;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\App\Response\Http as HttpResponse;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Asset\Repository;
Expand Down Expand Up @@ -86,7 +83,7 @@ private function processHeaders(HttpResponse $response)

$links = [];
foreach ($this->links as $link) {
$links[] = $link->getUrl();
$links[] = '<'.$link->getUrl().'>; rel="preload"';
}

$response->setHeader('Link', implode(', ', $links));
Expand All @@ -110,16 +107,16 @@ private function processBody(HttpResponse $response)
continue;
}

$createTag = '<link rel="preload" as="' . $link->getType() . '"';
$createTag = '<link rel="preload" as="'.$link->getType().'"';
if ($link->getType() === 'font') {
$createTag .= ' crossorigin="anonymous"';
}
$createTag .= ' href="' . $link->getUrl() . '" />';
$createTag .= ' href="'.$link->getUrl().'" />';

$newTags[] = $createTag;
}

$body = preg_replace('^</title>^',"</title>\n" . implode("\n", $newTags) , $body, 1);
$body = preg_replace('^</title>^', "</title>\n".implode("\n", $newTags), $body, 1);
$response->setBody($body);
}

Expand All @@ -145,6 +142,7 @@ private function addLinkHeadersFromResponse(HttpResponse $response)
if (!$this->config->isCriticalEnabled()) {
$this->addStylesheetsAsLinkHeader($crawler->filter('link[rel="stylesheet"]'));
}

$this->addScriptsAsLinkHeader($crawler->filter('script[type="text/javascript"][src]'));

if ($this->config->skipImages() === false) {
Expand Down Expand Up @@ -256,7 +254,7 @@ private function prepareLink(string $link): string

if (preg_match('/^(http|https):\/\//', $link) || preg_match('/^\/\//', $link)) {
if (strstr($link, $baseUrl)) {
$link = '/' . ltrim(substr($link, strlen($baseUrl)), '/');
$link = '/'.ltrim(substr($link, strlen($baseUrl)), '/');
}

return $link;
Expand All @@ -269,7 +267,7 @@ private function prepareLink(string $link): string

$baseUrl = $this->storeManager->getStore()->getBaseUrl();
if (strpos($link, $baseUrl) === 0) {
$link = '/' . ltrim(substr($link, strlen($baseUrl)), '/');
$link = '/'.ltrim(substr($link, strlen($baseUrl)), '/');
}

return $link;
Expand Down
4 changes: 2 additions & 2 deletions Test/Integration/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private function assertValidLink(string $link): void
foreach ($linkParams as $linkParam) {
$linkParam = explode('=', $linkParam);
$this->assertEquals(2, count($linkParam));
$this->assertEquals('rel', $linkParam[0]);
$this->assertEquals('preconnect', $linkParam[1]);
$this->assertEquals('rel', trim($linkParam[0]));
$this->assertEquals('preload', str_replace('"', '', trim($linkParam[1])));
}
}
}

0 comments on commit fcde1e4

Please sign in to comment.