Skip to content

Commit

Permalink
OXDEV-7760 Switch to Universal light workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
snehasreeramini committed May 28, 2024
1 parent ebbd1ba commit c57d054
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 36 deletions.
37 changes: 37 additions & 0 deletions .github/oxid-esales/twig-component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This plan should be used before ~/defaults/component.yml. That template uses
# the variables below to fill all the settings for the installation into
# /var/www directly without installing a shop.

global:
# The organisation part of the composer package name <org>/<name>
org: 'oxid-esales'
# The name part of the composer package, also used in other places
name: 'twig-component'
# The repository organisation/name to check out
repo: 'OXID-eSales/twig-component'

# These tests are run for all PHP/MySQL combinations specified when calling
# the workflow
runscript:
matrix:
# A string containing a valid json array of scripts to execute
# The scripts follow the pattern "<prefix>:<composer_alias>" for scripts
# defined in composer.json and "<prefix>:~/<shell_script>" for shell
# scripts located in tests/Scripts
# If you want to see the tests output, make sure to generate it in tests/Output
script: '["component:~/unit.sh","component:~/integration.sh"]'

sonarcloud:
# Remove the next two lines if you want to feed the results of your tests
# to sonarcloud. You need to make sure that your scripts generate an xml
# coverage file in tests/Reports, e.g. by adding
# --coverage-clover=tests/Reports/coverage_phpunit_integration.xml to them.
matrix:
testplan: 'skip'
# If you want to enable sonarcloud, you need to fill out the
# settings for project_key and project_name. You can get them from
# https://sonarcloud.io/organizations/oxid-esales/projects. The defaults for
# organization and parameters should be OK for most cases, so you don't need
# to overwrite them here.
project_key: '???'
project_name: '???'
54 changes: 30 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,49 @@ jobs:
run_tests:
strategy:
matrix:
php: [ '8.1' ]
mysql: [ '8.0' ]
php: ['8.1']
mysql: ['8.0']
fail-fast: false
runs-on: ubuntu-latest
runs-on: "ubuntu-latest"
env:
ESHOP_DOCKER_SDK_REPOSITORY: https://github.com/OXID-eSales/docker-eshop-sdk.git
SHOP_CE_REPOSITORY: https://github.com/OXID-eSales/oxideshop_ce.git
SHOP_CE_DEFAULT_BRANCH: b-7.0.x
SHOP_INSTALL_DIR: eshop_ce
DOCKER_SETUP_DIR: source
steps:

- name: Add environment variables
run: |
SHOP_ROOT_DIR="/var/www/$SHOP_INSTALL_DIR"
RUN_PHP="docker-compose run -T -w $SHOP_ROOT_DIR php"
TWIG_ROOT="/var/www/$SHOP_INSTALL_DIR/vendor/oxid-esales/twig-component"
echo "SHOP_ROOT_DIR=$SHOP_ROOT_DIR" >> $GITHUB_ENV
echo "RUN_PHP=$RUN_PHP" >> $GITHUB_ENV
echo "TWIG_ROOT=$TWIG_ROOT" >> $GITHUB_ENV
cat >>"${GITHUB_OUTPUT}" <<EOF
"TWIG_ROOT=${TWIG_ROOT}"
"SHOP_ROOT_DIR=${SHOP_ROOT_DIR}"
"RUN_PHP=${RUN_PHP}"
EOF
- name: Clone Docker Eshop SDK
run: |
git clone --depth 1 $ESHOP_DOCKER_SDK_REPOSITORY --branch master --single-branch .
git clone --depth 1 \
"${ESHOP_DOCKER_SDK_REPOSITORY}" --branch master \
--single-branch .
- name: Define eShop-CE branch for cloning
run: |
if [[ $(git ls-remote --heads $SHOP_CE_REPOSITORY ${{ github.ref_name }}) ]]; then
if [[ $(git ls-remote --heads "${SHOP_CE_REPOSITORY}" "${{ github.ref_name }}") ]]; then
SHOP_CE_BRANCH=${{ github.ref_name }};
else
SHOP_CE_BRANCH=$SHOP_CE_DEFAULT_BRANCH;
SHOP_CE_BRANCH="${SHOP_CE_DEFAULT_BRANCH}";
fi
echo "SHOP_CE_BRANCH=$SHOP_CE_BRANCH" >> $GITHUB_ENV
echo "SHOP_CE_BRANCH=${SHOP_CE_BRANCH}" >> "${GITHUB_ENV}"
- name: Clone the shop
run: |
git clone --depth 1 $SHOP_CE_REPOSITORY --branch $SHOP_CE_BRANCH --single-branch $DOCKER_SETUP_DIR/$SHOP_INSTALL_DIR
git clone --depth 1 \
"{$SHOP_CE_REPOSITORY}" --branch "{$SHOP_CE_BRANCH}" \
--single-branch "{$DOCKER_SETUP_DIR}"/"{$SHOP_INSTALL_DIR}"
- name: Prepare container configuration
run: |
Expand Down Expand Up @@ -87,46 +94,45 @@ jobs:
run: |
$RUN_PHP \
composer require squizlabs/php_codesniffer
$RUN_PHP \
composer install --no-interaction
- name: Prepare for PHP_CS check
run: |
cd source/eshop_ce/vendor/oxid-esales/twig-component
git diff --name-only origin/${{ github.ref_name }} HEAD~1 | grep '\.php$' >changed-files.txt || true
git diff --name-only origin/${{ github.ref_name }} HEAD~1 | grep '\.php$' >changed-files.txt || true
if [[ -f "changed-files.txt" && -s "changed-files.txt" ]]; then
perl -pi -e "s#^#$TWIG_ROOT/#" changed-files.txt
perl -pi -e "s#^#${TWIG_ROOT}/#" changed-files.txt
if [[ -f "changed-files.txt" && -s "changed-files.txt" ]]; then
cd ../../../../../
$RUN_PHP php vendor/bin/phpcs --standard=psr12 --file-list=$TWIG_ROOT/changed-files.txt 2>&1 \
cd ../../../../../
${RUN_PHP} php vendor/bin/phpcs --standard=psr12 --file-list="${TWIG_ROOT}/changed-files.txt" 2>&1 \
| tee php_codesniff_log.txt || true
rm source/eshop_ce/vendor/oxid-esales/twig-component/changed-files.txt
if grep -q -Ei 'fail|\\.\\=\\=|Warning|Notice|Deprecated|Fatal|Error' php_codesniff_log.txt;
then exit 1;
if grep -q -Ei 'fail|\\.\\=\\=|Warning|Notice|Deprecated|Fatal|Error' php_codesniff_log.txt;
then exit 1;
fi
fi
fi
- name: Run Install Shop
run: |
$RUN_PHP \
cp source/config.inc.php.dist source/config.inc.php
$RUN_PHP \
${RUN_PHP} \
cp source/config.inc.php.dist source/config.inc.php
${RUN_PHP} \
bin/oe-console oe:setup:shop \
--db-host mysql \
--db-port 3306 \
--db-name example \
--db-user root \
--db-password root \
--shop-url localhost.localhost \
--shop-directory $SHOP_ROOT_DIR/source/ \
--compile-directory $SHOP_ROOT_DIR/source/tmp/
--shop-directory "${SHOP_ROOT_DIR}/source/" \
--compile-directory "${SHOP_ROOT_DIR}/source/tmp/"
- name: Run component tests
# Put PHPUnit logs to the eShop log folder
run: |
$RUN_PHP \
${RUN_PHP} \
php vendor/bin/phpunit \
--configuration phpunit.xml \
--bootstrap source/bootstrap.php \
Expand Down
113 changes: 102 additions & 11 deletions .github/workflows/dispatch_dev_component.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,117 @@
name: Manual trigger for testing github actions development
name: Manual run
# Matrix workflow using re-usable github actions

on:
workflow_dispatch:
inputs:
testplan:
scenario:
type: choice
options:
- 7.0.x
- 7.1.x
- 7.2.x
- 8.0.x
- use custom testplan
default: '8.0.x'
description: 'Choose test scenario'
limit:
type: choice
options:
- 'no'
- 'PHP8.0/MySQL5.7'
- 'PHP8.0/MySQL8.0'
- 'PHP8.1/MySQL5.7'
- 'PHP8.1/MySQL8.0'
- 'PHP8.2/MySQL5.7'
- 'PHP8.2/MySQL8.0'
- 'PHP8.3/MySQL5.7'
- 'PHP8.3/MySQL8.0'
description:
default: 'PHP8.1/MySQL5.7'
custom_testplan:
type: string
required: true
description: 'URL/PATH of the testplan to run'
default: 'tests/github_actions/defaults/defaults.yml,tests/github_actions/twig-component.yml'
description: 'Custom testplan'
default: '~/defaults/php8.2_mysql5.7_only.yaml,~/twig-component.yaml,~/defaults/component.yaml'
runs_on:
type: string
description: 'JSON string/array describing the runner'
required: true
default: '["self-hosted", "x64"]'
default: '"ubuntu-latest"'
use_dev_version:
type: choice
options: ['no', 'v0']
description: 'Use the dev version of github actions'
default: 'no'

jobs:
call_matrix:
uses: oxid-eSales/github-actions/.github/workflows/call-universal_test_workflow.yml@v0
build_testplan:
runs-on: ${{ fromJson(inputs.runs_on) }}
outputs:
testplan: '${{ steps.build.outputs.testplan }}'
steps:
- name: 'Build testplan'
id: build
run: |
# Build testplan
# shellcheck disable=SC2088
PLAN="~/twig-component.yaml,~/defaults/component.yaml"
# shellcheck disable=SC2088
case "${{ inputs.limit }}" in
"no") LIMIT='';;
"PHP8.0/MySQL5.7") LIMIT='~/defaults/php8.0_mysql5.7_only.yaml,' ;;
"PHP8.0/MySQL8.0") LIMIT='~/defaults/php8.0_mysql8.0_only.yaml,' ;;
"PHP8.1/MySQL5.7") LIMIT='~/defaults/php8.1_mysql5.7_only.yaml,' ;;
"PHP8.1/MySQL8.0") LIMIT='~/defaults/php8.1_mysql8.0_only.yaml,' ;;
"PHP8.2/MySQL5.7") LIMIT='~/defaults/php8.2_mysql5.7_only.yaml,' ;;
"PHP8.2/MySQL8.0") LIMIT='~/defaults/php8.2_mysql8.0_only.yaml,' ;;
"PHP8.3/MySQL5.7") LIMIT='~/defaults/php8.3_mysql5.7_only.yaml,' ;;
"PHP8.3/MySQL8.0") LIMIT='~/defaults/php8.3_mysql8.0_only.yaml,' ;;
*) echo "Illegal choice, fix the workflow"
exit 1
;;
esac
# shellcheck disable=SC2088
case '${{ inputs.scenario}}' in
"7.0.x") TESTPLAN="~/defaults/7.0.x.yaml,${LIMIT}${PLAN}" ;;
"7.1.x") TESTPLAN="~/defaults/7.1.x.yaml,${LIMIT}${PLAN}" ;;
"7.2.x") TESTPLAN="~/defaults/7.2.x.yaml,${LIMIT}${PLAN}" ;;
"8.0.x") TESTPLAN="${LIMIT}${PLAN}" ;;
"smarty 7.0.x") TESTPLAN="~/defaults/7.0.x.yaml,${LIMIT}~/smarty_7.0.x.yaml" ;;
"use custom testplan") TESTPLAN="${{ inputs.custom_testplan }}" ;;
*)
echo "Illegal choice, fix the workflow"
exit 1
;;
esac
echo "testplan=${TESTPLAN}" | tee -a "${GITHUB_OUTPUT}"
dispatch_stable:
if: ${{ inputs.use_dev_version == 'no' }}
needs: build_testplan
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4
with:
testplan: ${{ needs.build_testplan.outputs.testplan }}
runs_on: ${{ inputs.runs_on }}
defaults: 'v0'
plan_folder: '.github/oxid-esales'
secrets:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
CACHE_ENDPOINT: ${{ secrets.CACHE_ENDPOINT }}
CACHE_ACCESS_KEY: ${{ secrets.CACHE_ACCESS_KEY }}
CACHE_SECRET_KEY: ${{ secrets.CACHE_SECRET_KEY }}
enterprise_github_token: ${{ secrets.enterprise_github_token }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

dispatch_v0:
if: ${{ inputs.use_dev_version == 'v0' }}
needs: build_testplan
uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v0
with:
testplan: ${{ inputs.testplan }}
testplan: ${{ needs.build_testplan.outputs.testplan }}
runs_on: ${{ inputs.runs_on }}
defaults: 'v3'
defaults: 'v0'
plan_folder: '.github/oxid-esales'
secrets:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/composer.lock
/vendor
.idea
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"OxidEsales\\Twig\\Tests\\": "tests"
}
}
}
}
29 changes: 29 additions & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="true"
backupStaticAttributes="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
beStrictAboutTestsThatDoNotTestAnything="false"
verbose="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true" processUncoveredFiles="false">
<include>
<directory suffix=".php">../src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="UnitTests">
<directory>Unit/</directory>
<directory>Integration/</directory>
</testsuite>
</testsuites>
</phpunit>
7 changes: 7 additions & 0 deletions tests/scripts/integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
vendor/bin/phpunit \
-c phpunit.xml \
--coverage-clover=tests/Reports/coverage_phpunit_integration.xml \
tests/Integration 2>&1 \
| tee tests/Output/integration_tests.txt
7 changes: 7 additions & 0 deletions tests/scripts/unit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
vendor/bin/phpunit \
-c phpunit.xml \
--coverage-clover=tests/Reports/coverage_phpunit_unit.xml \
tests/Unit 2>&1 \
| tee tests/Output/unit_tests.txt

0 comments on commit c57d054

Please sign in to comment.