Skip to content

Commit

Permalink
Merge pull request #432 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 4.13.0
  • Loading branch information
Progi1984 authored Oct 29, 2021
2 parents 257d9d4 + 3530ca0 commit 3f8c27a
Show file tree
Hide file tree
Showing 389 changed files with 25,509 additions and 227 deletions.
2 changes: 1 addition & 1 deletion .github/Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM prestashop/base:7.1-apache
FROM prestashop/base:7.2-apache
LABEL maintainer="PrestaShop Core Team <coreteam@prestashop.com>"

ARG VERSION
Expand Down
14 changes: 14 additions & 0 deletions .github/Dockerfile-7.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM prestashop/base:7.1-apache
LABEL maintainer="PrestaShop Core Team <coreteam@prestashop.com>"

ARG VERSION
ENV PS_VERSION $VERSION

# Get PrestaShop
ADD https://www.prestashop.com/download/old/prestashop_${PS_VERSION}.zip /tmp/prestashop.zip

# Extract
RUN mkdir -p /tmp/data-ps \
&& unzip -q /tmp/prestashop.zip -d /tmp/data-ps/ \
&& bash /tmp/ps-extractor.sh /tmp/data-ps \
&& rm /tmp/prestashop.zip
24 changes: 20 additions & 4 deletions .github/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,37 @@ runs:
steps:
- name: Build docker compose stack
env:
VERSION: ${{ matrix.ps-versions.from }}
VERSION: ${{ matrix.from }}
shell: bash
run: |
docker-compose -f docker-compose.yml up -d
bash -c '[[ "${VERSION}" == 1.6* ]] && docker-compose -f docker-compose-7.1.yml up -d || docker-compose -f docker-compose.yml up -d'
bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" != "200" ]]; do sleep 5; done'
- name: Copy autoupgrade module
shell: bash
run: docker exec -u www-data prestashop_autoupgrade cp modules/autoupgrade/ -R admin-dev
- name: Upgrade (major)
- name: Upgrade (intermediate)
env:
CHANNEL: 'archive'
ARCHIVE_URL: 'https://github.com/PrestaShop/PrestaShop/releases/download/1.7.7.8/prestashop_1.7.7.8.zip'
VERSION: '1.7.7.8'
FROM: ${{ matrix.from }}
SKIP: ${{ matrix.ps-versions.channel != 'archive' || !startsWith(matrix.from, '1.6') || startsWith(matrix.ps-versions.version, '1.7.7') }}
shell: bash
run: |
[[ "$SKIP" == true ]] || ${{ github.action_path }}action_upgrade.sh
[[ "$SKIP" == true ]] || docker exec prestashop_autoupgrade rm admin-dev/autoupgrade/modulesToUpgrade.list
[[ "$SKIP" == true ]] || docker stop prestashop_autoupgrade
[[ "$SKIP" == true ]] || docker rm prestashop_autoupgrade
[[ "$SKIP" == true ]] || docker run --name prestashop_autoupgrade -p 8001:80 -v autoupgrade_temp-ps:/var/www/html -v "$(pwd):/var/www/html/modules/autoupgrade" --network autoupgrade_default -d prestashop/base:7.2-apache
[[ "$SKIP" == true ]] || bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" == "000" ]]; do sleep 5; done'
- name: Upgrade
env:
CHANNEL: ${{ matrix.ps-versions.channel }}
ARCHIVE_URL: ${{ matrix.ps-versions.file }}
VERSION: ${{ matrix.ps-versions.version }}
FROM: ${{ matrix.from }}
shell: bash
run: ${{ github.action_path }}/action_upgrade.sh
run: ${{ github.action_path }}action_upgrade.sh
- name: Check endpoints response
shell: bash
run: |
Expand Down
27 changes: 24 additions & 3 deletions .github/action_upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
#!/bin/bash

if [[ $CHANNEL == "archive" ]]; then
if [[ "${FROM:0:1}" == 1 ]] && [[ "${VERSION:0:1}" == 1 ]]; then
if [[ "${FROM:2:1}" == "${VERSION:2:1}" ]]; then
UPDATE_THEME=0
else
UPDATE_THEME=1
fi
else
if [[ "${FROM:0:1}" == "${VERSION:0:1}" ]]; then
UPDATE_THEME=0
else
UPDATE_THEME=1
fi
fi

SKIP_BACKUP=$(docker exec -u www-data prestashop_autoupgrade ls admin-dev/autoupgrade/backup/ | wc -l)
if [[ "$SKIP_BACKUP" > 1 ]]; then
SKIP_BACKUP=1
else
SKIP_BACKUP=0
fi

docker exec -u www-data prestashop_autoupgrade mkdir admin-dev/autoupgrade/download
docker exec -u www-data prestashop_autoupgrade curl $ARCHIVE_URL -o admin-dev/autoupgrade/download/prestashop.zip
echo "{\"channel\":\"archive\",\"archive_prestashop\":\"prestashop.zip\",\"archive_num\":\"${VERSION}\"}" > config.json
docker exec -u www-data prestashop_autoupgrade curl -L $ARCHIVE_URL -o admin-dev/autoupgrade/download/prestashop.zip
echo "{\"channel\":\"archive\",\"archive_prestashop\":\"prestashop.zip\",\"archive_num\":\"${VERSION}\", \"PS_AUTOUP_CHANGE_DEFAULT_THEME\":${UPDATE_THEME}, \"skip_backup\": ${SKIP_BACKUP}}" > config.json
docker exec -u www-data prestashop_autoupgrade php admin-dev/autoupgrade/cli-updateconfig.php --from=modules/autoupgrade/config.json --dir=admin-dev
fi

docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev" --channel="$CHANNEL"
docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev"
8 changes: 7 additions & 1 deletion .github/get_matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@

$reports = json_decode(file_get_contents($nightlyEndpoint), true);
$currentDate = "";
$zipFiles = [];
foreach ($reports as $report) {
$date = strtotime($report['date']);
if ("" === $currentDate) {
$currentDate = $date;
}

if (null === $report['download'] || in_array($report['download'], $zipFiles)) {
continue;
}

if ($date === $currentDate) {
$zipFiles[] = $report['download'];
$matrix[] = [
"from" => "1.7.6.9",
"channel" => "archive",
"branch" => $report['version'],
"version" => getVersionFromFilename($report['download']),
Expand Down
206 changes: 164 additions & 42 deletions .github/get_results.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,97 @@
<?php

$result = getTestResultFromFile('result.txt');
$testPassed = $result['state'] === 'passed';
$branch = $result['branch'];
$psBranch = $argv[1] ?? null;
if (null === $psBranch) {
return;
}

$results = [];
$files = getResultFiles($psBranch);
foreach ($files as $file) {
$results[] = getTestResultFromFile($file);
}
$globalResults = getGlobalResults($results, $psBranch);
$totalDuration = getTotalDuration($globalResults);

$data = [
'stats' => [
'start' => $result['date_start']->format('Y-m-d H:i:s'),
'end' => $result['date_end']->format('Y-m-d H:i:s'),
'duration' => $result['duration'],
'start' => getDateStart($globalResults)->format('Y-m-d H:i:s'),
'end' => getDateEnd($globalResults)->format('Y-m-d H:i:s'),
'duration' => $totalDuration,
'skipped' => 0,
'pending' => 0,
'passes' => $testPassed ? 1 : 0,
'failures' => $testPassed ? 0 : 1,
'passes' => getPasses($globalResults),
'failures' => getFailures($globalResults),
'suites' => 1,
'tests' => 1,
'tests' => count($results),
],
'suites' => [
'uuid' => uniqid(),
'title' => $result['title'],
'title' => 'Upgrade to branch ' . $psBranch,
'file' => '',
'duration' => $result['duration'],
'duration' => $totalDuration,
'hasSkipped' => false,
'hasPending' => false,
'hasPasses' => $testPassed > 0,
'hasFailures' => $testPassed === 0,
'hasPasses' => getPasses($globalResults) > 0,
'hasFailures' => getFailures($globalResults) > 0,
'totalSkipped' => 0,
'totalPending' => 0,
'totalPasses' => $testPassed ? 1 : 0,
'totalFailures' => $testPassed ? 0 : 1,
'totalPasses' => getPasses($globalResults),
'totalFailures' => getFailures($globalResults),
'hasSuites' => true,
'hasTests' => false,
'tests' => [],
'suites' => [[
'uuid' => uniqid(),
'title' => $result['title'],
'file' => '',
'duration' => $result['duration'],
'hasSkipped' => false,
'hasPending' => false,
'hasPasses' => $testPassed > 0,
'hasFailures' => $testPassed === 0,
'totalSkipped' => 0,
'totalPending' => 0,
'totalPasses' => $testPassed ? 1 : 0,
'totalFailures' => $testPassed ? 0 : 1,
'hasSuites' => false,
'hasTests' => true,
'suites' => [],
'tests' => [$result],
]],
'suites' => [],
],
];

$filename = 'autoupgrade_' . date('Y-m-d') . '-' . $branch . '.json';
foreach ($globalResults as $globalResult) {
$data['suites']['suites'][] = [
'uuid' => uniqid(),
'title' => $globalResult['title'],
'file' => '',
'duration' => $globalResult['duration'],
'hasSkipped' => false,
'hasPending' => false,
'hasPasses' => $globalResult['passes'] > 0,
'hasFailures' => $globalResult['failures'] > 0,
'totalSkipped' => 0,
'totalPending' => 0,
'totalPasses' => $globalResult['passes'],
'totalFailures' => $globalResult['failures'],
'hasSuites' => false,
'hasTests' => true,
'suites' => [],
'tests' => $globalResult['tests'],
];
}

$filename = 'autoupgrade_' . date('Y-m-d') . '-' . $psBranch . '.json';
file_put_contents($filename, json_encode($data));

function getTestResultFromFile($file)
function getResultFiles(string $branch): array
{
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('./artifacts'));
$files = [];
foreach ($rii as $file) {
if ($file->isDir() || strpos($file->getPathname(), $branch . '.txt') === false) {
continue;
}

$files[] = $file->getPathname();
}

return $files;
}

function getTestResultFromFile(string $file): array
{
$data = explode('|', trim(file_get_contents($file)));
$dateStart = getDateTimeFromString($data[2]);
$dateEnd = getDateTimeFromString($data[3]);
$dateStart = getDateTimeFromString($data[4]);
$dateEnd = getDateTimeFromString($data[5]);
$duration = ($dateEnd->getTimestamp() - $dateStart->getTimestamp()) * 1000;
$state = $data[4] === 'success' ? 'passed' : 'failed';
$state = $data[6] === 'success' ? 'passed' : 'failed';
$branch = $data[0];
$error = null;
if ($state !== 'passed') {
$error = [
Expand All @@ -77,20 +106,113 @@ function getTestResultFromFile($file)

return [
'uuid' => uniqid(),
'title' => 'Upgrade to ' . $data[1],
'context' => '{"value": "Upgrade to ' . $data[1] . '"}',
'title' => '[' . $branch . '] Upgrade from ' . $data[1] . ' to ' . $data[2],
'context' => '{"value": "[' . $branch . '] Upgrade from ' . $data[1] . ' to ' . $data[2] . '"}',
'skipped' => [],
'pending' => [],
'duration' => $duration,
'state' => $state,
'err' => $error,
'date_start' => $dateStart,
'date_end' => $dateEnd,
'branch' => $data[0]
'branch' => $branch
];
}

function getDateTimeFromString($datetime)
function getDateTimeFromString(string $datetime): DateTime
{
return DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $datetime, new DateTimeZone('UTC'));
}

function getGlobalResults(array $results, string $psBranch): array
{
$globalResults = [];

foreach ($results as $result) {
if (!isset($globalResults[$result['branch']])) {
$globalResults[$result['branch']] = [
'title' => '[' . $result['branch'] . '] Upgrade to branch ' . $psBranch,
'date_start' => null,
'date_end' => null,
'duration' => 0,
'passes' => 0,
'failures' => 0,
];
}
if (null === $globalResults[$result['branch']]['date_start'] || $result['date_start'] < $globalResults[$result['branch']]['date_start']) {
$globalResults[$result['branch']]['date_start'] = $result['date_start'];
}
if (null === $globalResults[$result['branch']]['date_end'] || $result['date_end'] > $globalResults[$result['branch']]['date_end']) {
$globalResults[$result['branch']]['date_end'] = $result['date_end'];
}
$globalResults[$result['branch']]['passes'] += $result['state'] === 'passed' ? 1 : 0;
$globalResults[$result['branch']]['failures'] += $result['state'] !== 'passed' ? 1 : 0;
$globalResults[$result['branch']]['tests'][] = $result;
}

foreach ($globalResults as &$globalResult) {
$globalResult['duration'] = ($globalResult['date_end']->getTimestamp() - $globalResult['date_start']->getTimestamp()) * 1000;
}

return $globalResults;
}

function getDateStart(array $globalResults): DateTime {
$dateStart = null;

foreach ($globalResults as $globalResult) {
if (null === $dateStart || $globalResult['date_start'] < $dateStart) {
$dateStart = $globalResult['date_start'];
}
}

return $dateStart;
}

function getDateEnd(array $globalResults): DateTime {
$dateEnd = null;

foreach ($globalResults as $globalResult) {
if (null === $dateEnd || $globalResult['date_end'] < $dateEnd) {
$dateEnd = $globalResult['date_end'];
}
}

return $dateEnd;
}

function getPasses(array $globalResults): int {
$passes = 0;

foreach ($globalResults as $globalResult) {
$passes += $globalResult['passes'];
}

return $passes;
}

function getFailures(array $globalResults): int {
$failures = 0;

foreach ($globalResults as $globalResult) {
$failures += $globalResult['failures'];
}

return $failures;
}

function getTotalDuration(array $results): int {
$dateStart = null;
$dateEnd = null;

foreach ($results as $result) {
if (null === $dateStart || $result['date_start'] < $dateStart) {
$dateStart = $result['date_start'];
}
if (null === $dateEnd || $result['date_end'] > $dateEnd) {
$dateEnd = $result['date_end'];
}
}

return ($dateEnd->getTimestamp() - $dateStart->getTimestamp()) * 1000;
}
Loading

0 comments on commit 3f8c27a

Please sign in to comment.