From 02b8a9f1eebffd8d647444c968cfdd09c92a2d0a Mon Sep 17 00:00:00 2001 From: RahatHameed Date: Wed, 15 May 2024 17:30:15 +0200 Subject: [PATCH] OXDEV-8234 Switched GitHub light workflow --- .github/oxid-esales/geo-blocking.yaml | 50 ++++ .github/workflows/dispatch_module.yaml | 397 +++---------------------- .github/workflows/schedule.yaml | 27 +- .github/workflows/trigger.yaml | 34 ++- 4 files changed, 135 insertions(+), 373 deletions(-) create mode 100644 .github/oxid-esales/geo-blocking.yaml diff --git a/.github/oxid-esales/geo-blocking.yaml b/.github/oxid-esales/geo-blocking.yaml new file mode 100644 index 0000000..8e1774c --- /dev/null +++ b/.github/oxid-esales/geo-blocking.yaml @@ -0,0 +1,50 @@ +install_shop_with_modules: + cache: + prepared_shop: false + composer: + transform: | + { + "require": { + "oxid-esales/oxideshop-ce": "{{ .Data.global.composer.dev_ref }}", + "oxid-esales/twig-component": "{{ .Data.global.composer.dev_ref }}", + "oxid-esales/twig-admin-theme": "{{ .Data.global.composer.dev_ref }}", + "oxid-esales/apex-theme": "{{ .Data.global.composer.dev_ref }}", + "oxid-esales/geo-blocking-module": "{{ .Data.global.composer.ref_name }}" + }, + "repositories": { + "oxid-esales/geo-blocking-module": { + "type": "git", + "url": "https://github.com/OXID-eSales/geo-blocking-module.git" + } + } + } + custom_script_container: | + vendor/bin/oe-console oe:theme:activate apex + vendor/bin/oe-console oe:module:activate oegeoblocking + +runscript: &runscript + matrix: + script: | + [ + "geo_blocking:tests-integration", + "geo_blocking:tests-codeception" + ] + geo_blocking: + path: 'vendor/oxid-esales/geo-blocking-module' + +sonarcloud: + matrix: + testplan: '["-"]' + strip_path: '/var/www/vendor/oxid-esales/geo-blocking-module/' + project_key: 'OXID-eSales_geo-blocking-module' + project_name: 'oxid-esales/geo-blocking-module' + organization: 'oxid-esales' + parameters: | + -Dsonar.language=php + -Dsonar.scm.provider=git + -Dsonar.sources=src + -Dsonar.tests=tests + -Donar.php.phpstan.reportPaths=coverage-reports/phpstan.report.json + +finish: + slack_title: 'Geo Blocking ({{ .Data.global.git.shop_ref }}) by {{ .Github.Actor }}' \ No newline at end of file diff --git a/.github/workflows/dispatch_module.yaml b/.github/workflows/dispatch_module.yaml index 34e948d..41d0f1d 100644 --- a/.github/workflows/dispatch_module.yaml +++ b/.github/workflows/dispatch_module.yaml @@ -1,360 +1,59 @@ name: Manual trigger +# Matrix workflow using re-usable github actions on: - workflow_call: - inputs: - php: - required: true - type: string - mysql: - required: true - type: string - template_engine: - type: string - default: 'both' - report_slack: - type: boolean - default: true - workflow_dispatch: inputs: - php: - description: 'PHP version' - required: true - default: '8.0' - type: choice - options: - - '8.0' - - '8.1' - mysql: - description: 'MySQL version' - required: true - default: '5.7.37' + limit: type: choice options: - - '5.7.37' - - '8.0' - template_engine: - description: 'Template engine - smarty with flow theme, twig with twig or apex theme' - required: true - default: 'twig-apex' - type: choice - options: - - 'both' - - 'twig-apex' - - 'smarty' - -env: - PACKAGE_NAME: 'oxid-esales/geo-blocking-module' - MODULE_IDS: 'oegeoblocking' - SONARCLOUD_ORGANIZATION: 'oxid-esales' - SONARCLOUD_PROJECT_KEY: 'OXID-eSales_geo-blocking-module' + - 'no' + - 'PHP8.1/MySQL5.7' + - 'PHP8.1/MySQL8.0' + - 'PHP8.2/MySQL5.7' + - 'PHP8.2/MySQL8.0' + default: 'PHP8.2/MySQL8.0' + description: 'Limit to one PHP/MySQL combination' jobs: - install_shop_with_module: - runs-on: ubuntu-latest - steps: - - name: Print run parameters - run: | - echo "Running job with:\ - PHP version: ${{ inputs.php }}\ - MySQL version: ${{ inputs.mysql }}\ - Template engine: ${{ inputs.template_engine }}\ - Trigger event: ${{ github.event_name }}" - - name: Clone testing environment - run: git clone https://github.com/OXID-eSales/docker-eshop-sdk.git . - - - name: Clone the shop - run: git clone --depth 1 https://github.com/OXID-eSales/oxideshop_ce.git --branch b-7.0.x --single-branch source - - - name: Cache current installation - uses: actions/cache@v3 - with: - path: | - ./* - key: installation-${{ join(inputs, '-') }}-${{ github.run_number }}-${{ github.run_attempt }} - - - name: Prepare container configuration - run: | - make setup - make addbasicservices - make file=services/selenium-chrome.yml addservice - perl -pi\ - -e 's#PHP_VERSION=.*#PHP_VERSION=${{ inputs.php }}#g;'\ - -e "s#MYSQL_VERSION=.*#MYSQL_VERSION=${{ inputs.mysql }}#g;"\ - .env - perl -pi\ - -e 's#display_errors =.*#display_errors = false#g;'\ - -e 's#error_reporting = .*#error_reporting = E_ALL ^ E_WARNING ^ E_DEPRECATED#g;'\ - -e 'print "xdebug.max_nesting_level=1000\nxdebug.mode=coverage\n\n"'\ - containers/php/custom.ini - perl -pi\ - -e 's#/var/www/#/var/www/source/#g;'\ - containers/httpd/project.conf - - - name: Prepare shop configuration - run: | - cp source/source/config.inc.php.dist source/source/config.inc.php - sed -i "1s+^+SetEnvIf Authorization "\(.*\)" HTTP_AUTHORIZATION=\$1\n\n+" source/source/.htaccess - sed -i -e 's//mysql/'\ - -e 's//root/'\ - -e 's//example/'\ - -e 's//root/'\ - -e 's//3306/'\ - -e 's//http:\/\/localhost.local\//'\ - -e 's//\/var\/www\/source\//'\ - -e 's//\/var\/www\/source\/tmp\//'\ - source/source/config.inc.php - - - name: Checkout current module - uses: actions/checkout@v3 - with: - path: source/test-module - - - name: Start containers - run: | - make up - sleep 2 - - - name: Install module - run: | - docker-compose exec -T \ - php composer config repositories.${{ env.PACKAGE_NAME }} \ - --json '{"type":"path", "url":"./test-module", "options": {"symlink": true}}' - docker-compose exec -T \ - php composer require ${{ env.PACKAGE_NAME }}:* --no-interaction --no-update - - - name: Install dependencies and reset shop - run: | - docker-compose exec -T php composer update --no-interaction - docker-compose exec -T php bin/oe-console oe:database:reset \ - --db-host=mysql --db-port=3306 --db-name=example --db-user=root --db-password=root --force - docker-compose exec -T php bin/oe-console oe:module:activate oegeoblocking - - - name: Stop containers - run: | - docker-compose down - sleep 2 - - - name: Show docker log - if: always() - run: | - docker-compose logs - - - name: Upload configuration artifacts - if: always() - uses: actions/upload-artifact@v3 - with: - name: Configs-${{ inputs.php }}-${{ inputs.mysql }}-${{ inputs.template_engine }} - path: | - docker-compose.yml - source/composer.json - source/composer.lock - source/source/config.inc.php - - integration_tests: - needs: [ install_shop_with_module ] - runs-on: ubuntu-latest - steps: - - name: Load current installation from cache - uses: actions/cache@v3 - with: - path: | - ./* - key: installation-${{ join(inputs, '-') }}-${{ github.run_number }}-${{ github.run_attempt }} - restore-keys: | - installation-${{ join(inputs, '-') }}-${{ github.run_number }}-${{ github.run_attempt }} - - name: Start containers - run: | - make up - sleep 2 - - name: Run tests - run: | - docker-compose exec -T \ - -e XDEBUG_MODE=coverage \ - php php vendor/bin/phpunit \ - -c /var/www/vendor/${{ env.PACKAGE_NAME }}/tests/phpunit.xml \ - --testsuite=Integration \ - --bootstrap=/var/www/source/bootstrap.php \ - --coverage-text \ - --coverage-php=/var/www/integration.cov - - name: Upload log artifact - if: always() - uses: actions/upload-artifact@v3 - with: - name: ModuleIntegrationTestsLog-${{ inputs.php }}-${{ inputs.mysql }}-${{ inputs.template_engine }} - path: | - source/integration.cov - source/source/log/oxideshop.log - data/php/logs/error_log.txt - - name: Stop containers - if: always() - run: | - docker-compose down - sleep 2 - - codeception_twig: - needs: [ install_shop_with_module ] - if: ${{ inputs.template_engine == 'both' || inputs.template_engine == 'twig-apex' }} - runs-on: ubuntu-latest - steps: - - name: Load current installation from cache - uses: actions/cache@v3 - with: - path: | - ./* - key: installation-${{ join(inputs, '-') }}-${{ github.run_number }}-${{ github.run_attempt }} - restore-keys: | - installation-${{ join(inputs, '-') }}-${{ github.run_number }}-${{ github.run_attempt }} - - - name: Start containers - run: | - make up - sleep 2 - - - name: Set Github dependencies - run: | - docker-compose run -T --rm php composer config github-protocols https - docker-compose run -T --rm php composer config -g github-oauth.github.com ${{ secrets.GH_CI_JENKINS_TOKEN }} - - - name: Install twig template engine with twig and apex theme - run: | - docker-compose exec -T php composer require oxid-esales/twig-component:dev-b-7.0.x --no-update - docker-compose exec -T php composer require oxid-esales/twig-admin-theme:dev-b-7.0.x --no-update - docker-compose exec -T php composer require oxid-esales/twig-theme:dev-b-7.0.x --no-update - docker-compose exec -T \ - php composer config repositories.oxid-esales/apex-theme \ - --json '{"type":"git", "url":"https://github.com/OXID-eSales/apex-theme.git"}' - docker-compose exec -T php composer require oxid-esales/apex-theme:dev-main --no-update - docker-compose exec -T php composer update --no-interaction - - - name: Run tests with apex theme - if: ${{ inputs.template_engine == 'both' || inputs.template_engine == 'twig-apex' }} - run: | - perl -pi \ - -e 's#views/twig#views/apex#g;' \ - source/test-module/tests/Codeception/acceptance.suite.yml - docker-compose exec -T \ - -e SELENIUM_SERVER_HOST=selenium \ - -e BROWSER_NAME=chrome \ - -e THEME_ID=apex \ - -e MODULE_IDS=${{ env.MODULE_IDS }} \ - php vendor/bin/codecept run acceptance \ - -c /var/www/vendor/${{ env.PACKAGE_NAME }}/tests/codeception.yml - - - name: Upload log artifact - if: always() - uses: actions/upload-artifact@v3 - with: - name: ModuleCodeceptionTestsLog-${{ inputs.php }}-${{ inputs.mysql }}-${{ inputs.template_engine }} - path: | - docker-compose.yml - source/composer.json - source/composer.lock - source/source/config.inc.php - source/source/log/oxideshop.log - data/php/logs/error_log.txt - source/tests/Codeception/_output - - - name: Stop containers - if: always() - run: | - make down - sleep 2 - - codeception_smarty: - needs: [ install_shop_with_module ] - if: ${{ inputs.template_engine == 'both' || inputs.template_engine == 'smarty' }} - runs-on: ubuntu-latest - steps: - - name: Load current installation from cache - uses: actions/cache@v3 - with: - path: | - ./* - key: installation-${{ join(inputs, '-') }}-${{ github.run_number }}-${{ github.run_attempt }} - restore-keys: | - installation-${{ join(inputs, '-') }}-${{ github.run_number }}-${{ github.run_attempt }} - - - name: Reconfigure codeception for smarty themes - run: | - perl -pi \ - -e 's#admin_twig#admin_smarty#g;' \ - source/test-module/tests/Codeception/acceptance.suite.yml - perl -pi \ - -e 's#views/twig#views/flow/translations#g;' \ - source/test-module/tests/Codeception/acceptance.suite.yml - - - name: Start containers - run: | - make up - sleep 2 - - - name: Install smarty template engine and flow theme - run: | - docker-compose exec -T php composer require oxid-esales/codeception-page-objects:dev-b-7.0.x-SMARTY --no-update - docker-compose exec -T php composer require oxid-esales/smarty-component:dev-b-7.0.x --no-update - docker-compose exec -T php composer require oxid-esales/smarty-admin-theme:dev-b-7.0.x --no-update - docker-compose exec -T php composer require oxid-esales/flow-theme:dev-b-7.0.x --no-update - docker-compose exec -T php composer update --no-interaction - - - name: Run tests - run: | - docker-compose exec -T \ - -e SELENIUM_SERVER_HOST=selenium \ - -e BROWSER_NAME=chrome \ - -e THEME_ID=flow \ - -e MODULE_IDS=${{ env.MODULE_IDS }} \ - php vendor/bin/codecept run acceptance \ - -c /var/www/vendor/${{ env.PACKAGE_NAME }}/tests/codeception.yml - - - name: Upload log artifact - if: always() - uses: actions/upload-artifact@v3 - with: - name: sModuleCodeceptionTestsLog-${{ inputs.php }}-${{ inputs.mysql }}-${{ inputs.template_engine }} - path: | - docker-compose.yml - source/composer.json - source/composer.lock - source/source/config.inc.php - source/source/log/oxideshop.log - data/php/logs/error_log.txt - source/tests/Codeception/_output - - - name: Stop containers - if: always() - run: | - make down - sleep 2 - - notify_slack: + build_testplan: runs-on: ubuntu-latest - needs: [ integration_tests, codeception_twig, codeception_smarty ] - if: ${{ always() && inputs.report_slack }} + outputs: + testplan: '${{ steps.build.outputs.testplan }}' steps: - - name: Send custom JSON data to Slack workflow - uses: slackapi/slack-github-action@v1.23.0 - with: - # "needs" context used to access the state of related jobs - # "github" context used to access workflow its trigger information - # Warning: Payload is JSON format given through Yaml. Be careful with new lines and do not make it NICE looking, it will not work here ;) - # Help: New lines can be easily added for texts bellow. Check how it's currently implemented in this example! - payload: > - {"text": " - ${{ github.event_name == 'workflow_dispatch' && 'Manual' || 'Scheduled' }} ${{ github.workflow }} workflow on ${{ github.repository }} by ${{ github.actor }} - ${{ (needs.integration_tests.result=='success' && needs.codeception_twig.result=='success' && needs.codeception_smarty.result=='success') && 'Successful' || 'Failed' }} - ", "blocks": [{"type": "header","text": {"type": "plain_text", "emoji": true, "text": " - ${{ github.event_name == 'workflow_dispatch' && 'Manual' || 'Scheduled' }} ${{ github.workflow }} workflow on ${{ github.repository }} by ${{ github.actor }} - "}},{"type": "section","fields": [{"type": "mrkdwn","text": " - *Status:* ${{ (needs.integration_tests.result=='success' && needs.codeception_twig.result=='success' && needs.codeception_smarty.result=='success') && ':heavy_check_mark:' || ':x:' }} - "},{"type": "mrkdwn","text": " - Repository: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.repository }}/actions/runs/${{ github.run_id }}> - "}]},{"type": "section", "text": {"type": "mrkdwn", "text": " - \n* Integration tests job ${{ (needs.integration_tests.result=='success') && ':white_check_mark:' || ':x:' }} - \n* Codeception tests with twig job ${{ (needs.codeception_twig.result=='success') && ':white_check_mark:' || ':x:' }} - \n* Codeception tests with smarty job ${{ (needs.codeception_smarty.result=='success') && ':white_check_mark:' || ':x:' }} - "}}, {"type": "divider"}]} - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + - name: 'Build testplan' + id: build + run: | + # Build testplan + # shellcheck disable=SC2088 + case "${{ inputs.limit }}" in + "no") LIMIT='';; + "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,' ;; + *) echo "Illegal choice, fix the workflow" + exit 1 + ;; + esac + # shellcheck disable=SC2088 + TESTPLAN="~/defaults/7.1.x.yaml,${LIMIT}~/geo-blocking.yaml" + echo "testplan=${TESTPLAN}" | tee -a "${GITHUB_OUTPUT}" + + dispatch_stable: + needs: build_testplan + uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4 + with: + testplan: ${{ needs.build_testplan.outputs.testplan }} + runs_on: '"ubuntu-latest"' + defaults: 'v4' + 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 }} \ No newline at end of file diff --git a/.github/workflows/schedule.yaml b/.github/workflows/schedule.yaml index 48f2bc8..76ae428 100644 --- a/.github/workflows/schedule.yaml +++ b/.github/workflows/schedule.yaml @@ -1,14 +1,25 @@ -name: Scheduled weekly runs +name: Scheduled weekly run +# Matrix workflow using re-usable github actions on: schedule: - - cron: '0 0 */7 * *' + - cron: '16 1 */7 * *' jobs: - p80m57both: - name: 'Php-8.0-Mysql-5.7' - uses: ./.github/workflows/dispatch_module.yaml - secrets: inherit + jeo_blocking_php82_mysql80: + if: always() + uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4 with: - php: '8.0' - mysql: '5.7.37' + testplan: '~/defaults/7.1.x.yaml,~/defaults/scheduled.yaml,~/geo-blocking.yaml' + runs_on: '"ubuntu-latest"' + defaults: 'v4' + 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 }} \ No newline at end of file diff --git a/.github/workflows/trigger.yaml b/.github/workflows/trigger.yaml index 971154c..04f4586 100644 --- a/.github/workflows/trigger.yaml +++ b/.github/workflows/trigger.yaml @@ -1,22 +1,24 @@ name: Auto trigger on push or pull requests +# Matrix workflow using re-usable github actions on: - pull_request: - push: + pull_request: {} + push: {} jobs: - p80m57both: - name: 'Php-8.0-Mysql-5.7' - uses: ./.github/workflows/dispatch_module.yaml - secrets: inherit + jeo_blocking_php82_mysql80: + uses: oxid-eSales/github-actions/.github/workflows/universal_workflow_light.yaml@v4 with: - php: '8.0' - mysql: '5.7.37' - - p81m80both: - name: 'Php-8.1-Mysql-8.0' - uses: ./.github/workflows/dispatch_module.yaml - secrets: inherit - with: - php: '8.1' - mysql: '8.0' \ No newline at end of file + testplan: '~/defaults/7.1.x.yaml,~/defaults/php8.2_mysql8.0_only.yaml,~/geo-blocking.yaml' + runs_on: '"ubuntu-latest"' + defaults: 'v4' + 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 }} \ No newline at end of file