Skip to content

Commit

Permalink
Merge pull request #381 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 4.12.0
  • Loading branch information
Progi1984 authored Feb 11, 2021
2 parents 4a63ab4 + b72f76d commit 257d9d4
Show file tree
Hide file tree
Showing 29 changed files with 548 additions and 150 deletions.
14 changes: 14 additions & 0 deletions .github/Dockerfile
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
37 changes: 37 additions & 0 deletions .github/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Upgrade
description: Test PrestaShop upgrade process
runs:
using: composite
steps:
- name: Build docker compose stack
env:
VERSION: ${{ matrix.ps-versions.from }}
shell: bash
run: |
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)
env:
CHANNEL: ${{ matrix.ps-versions.channel }}
ARCHIVE_URL: ${{ matrix.ps-versions.file }}
VERSION: ${{ matrix.ps-versions.version }}
shell: bash
run: ${{ github.action_path }}/action_upgrade.sh
- name: Check endpoints response
shell: bash
run: |
bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" == "200" ]'
bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]'
- name: Rollback
shell: bash
run: docker exec -u www-data prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php \
admin-dev/autoupgrade/cli-rollback.php --dir="admin-dev" \
--backup=`docker exec prestashop_autoupgrade bash -c "ls -td -- /var/www/html/admin-dev/autoupgrade/backup/*/ | head -n 1 | cut -d'/' -f8 | tr -d '\n'"`;
- name: Check endpoints response
shell: bash
run: |
bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" == "200" ]'
bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]'
10 changes: 10 additions & 0 deletions .github/action_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [[ $CHANNEL == "archive" ]]; then
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 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"
32 changes: 32 additions & 0 deletions .github/get_matrix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

$matrix = [];

$nightlyEndpoint = "https://api-nightly.prestashop.com/reports";

$reports = json_decode(file_get_contents($nightlyEndpoint), true);
$currentDate = "";
foreach ($reports as $report) {
$date = strtotime($report['date']);
if ("" === $currentDate) {
$currentDate = $date;
}
if ($date === $currentDate) {
$matrix[] = [
"from" => "1.7.6.9",
"channel" => "archive",
"branch" => $report['version'],
"version" => getVersionFromFilename($report['download']),
"file" => $report['download']
];
}
}

function getVersionFromFilename($filename) {
$matches = [];
preg_match('/^.*prestashop_(.*)\.zip$/', $filename, $matches);

return $matches[1];
}

echo json_encode($matrix);
96 changes: 96 additions & 0 deletions .github/get_results.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

$result = getTestResultFromFile('result.txt');
$testPassed = $result['state'] === 'passed';
$branch = $result['branch'];

$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'],
'skipped' => 0,
'pending' => 0,
'passes' => $testPassed ? 1 : 0,
'failures' => $testPassed ? 0 : 1,
'suites' => 1,
'tests' => 1,
],
'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' => 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],
]],
],
];

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

function getTestResultFromFile($file)
{
$data = explode('|', trim(file_get_contents($file)));
$dateStart = getDateTimeFromString($data[2]);
$dateEnd = getDateTimeFromString($data[3]);
$duration = ($dateEnd->getTimestamp() - $dateStart->getTimestamp()) * 1000;
$state = $data[4] === 'success' ? 'passed' : 'failed';
$error = null;
if ($state !== 'passed') {
$error = [
'message' => sprintf(
'%s/%s/actions/runs/%s',
getenv('GITHUB_SERVER_URL'),
getenv('GITHUB_REPOSITORY'),
getenv('GITHUB_RUN_ID')
)
];
}

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

function getDateTimeFromString($datetime)
{
return DateTime::createFromFormat('Y-m-d\TH:i:s\Z', $datetime, new DateTimeZone('UTC'));
}
57 changes: 57 additions & 0 deletions .github/workflows/nigthly_upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Nightly Upgrades
on:
schedule:
- cron: '0 0 * * *'
jobs:
get_matrix:
name: Set up matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
- id: set-matrix
run: echo "::set-output name=matrix::$(php ./.github/get_matrix.php)"
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
upgrade:
continue-on-error: true
needs: get_matrix
strategy:
fail-fast: false
matrix:
ps-versions: ${{ fromJson(needs.get_matrix.outputs.matrix) }}
runs-on: ubuntu-latest
name: Upgrade
outputs:
result: ${{ steps.export-result.outputs.result }}
steps:
- uses: actions/checkout@v2
- name: Composer Install
run: |
composer install
echo "START_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`" >> $GITHUB_ENV
- name: Upgrade & Rollback
id: upgrade-rollback
uses: ./.github/
- name: Format result
if: ${{ always() }}
run: |
export END_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
echo "${{matrix.ps-versions.branch}}|${{matrix.ps-versions.version}}|$START_DATE|$END_DATE|${{steps.upgrade-rollback.outcome}}" > result.txt
php ./.github/get_results.php
- name: Set up Cloud SDK
if: ${{ always() }}
uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GC_PROJECT_ID }}
service_account_key: ${{ secrets.GC_SERVICE_KEY }}
export_default_credentials: true
- name: Push results to the nightly board
if: ${{ always() }}
run: |
export TODAY=`date -u +"%Y-%m-%d"`
export FILENAME=autoupgrade_$TODAY-${{matrix.ps-versions.branch}}.json
gsutil cp $FILENAME gs://prestashop-core-nightly/reports
curl -X GET "https://api-nightly.prestashop.com/hook/add?filename=$FILENAME&platform=cli&campaign=autoupgrade&token=${{ secrets.QANB_TOKEN }}"
46 changes: 43 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PHP tests
on: [push, pull_request]
jobs:
build:
php-unit:
strategy:
matrix:
php-versions: ['5.6', '7.1', '7.2','7.4']
Expand All @@ -13,9 +13,49 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv, ext-zip
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 0

- run: composer install --prefer-dist
- run: ./vendor/phpunit/phpunit/phpunit tests
- run: ./vendor/phpunit/phpunit/phpunit tests

phpstan:
name: PHPStan
runs-on: ubuntu-latest
strategy:
matrix:
presta-versions: [ '1.6.1.18', '1.7.6.9', 'latest' ]
steps:
- name: Checkout
uses: actions/checkout@v2.0.0

- name: Cache vendor folder
uses: actions/cache@v1
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

- name: Cache composer folder
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: php-composer-cache

- run: composer install

- name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }})
env:
PS_VERSION: ${{ matrix.presta-versions }}
IS_16: ${{ startsWith(matrix.presta-versions, '1.6') }}
run: |
PHPSTAN_FILE="phpstan.neon" && [[ $IS_16 == true ]] && PHPSTAN_FILE="phpstan-PS-16.neon"
echo $PHPSTAN_FILE
docker rm -f temp-ps || true
docker volume rm -f ps-volume || true
docker run -d --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION
docker exec -t temp-ps rm -rf /var/www/html/modules/autoupgrade
docker build -t phpstan:php-7.4 ./tests/phpstan/
docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/autoupgrade \
-e _PS_ROOT_DIR_=/var/www/html --workdir=/var/www/html/modules/autoupgrade phpstan:php-7.4 \
analyse --configuration=/var/www/html/modules/autoupgrade/tests/phpstan/$PHPSTAN_FILE
26 changes: 26 additions & 0 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Upgrades
on: [push, pull_request]
jobs:
upgrade:
strategy:
matrix:
ps-versions:
- from: 1.6.1.11
channel: minor
# Failing for now
#- from: 1.6.1.24
# channel: major
- from: 1.7.6.9
channel: major
- from: 1.7.6.1
channel: minor
- from: 1.7.7.0
channel: minor
runs-on: ubuntu-latest
name: Upgrade
steps:
- uses: actions/checkout@v2
- name: Composer Install
run: composer install
- name: Upgrade & Rollback
uses: ./.github/
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

Loading

0 comments on commit 257d9d4

Please sign in to comment.