diff --git a/.github/workflows/actions/checkout-prestashop/action.yml b/.github/workflows/actions/checkout-prestashop/action.yml new file mode 100644 index 00000000..82d972b1 --- /dev/null +++ b/.github/workflows/actions/checkout-prestashop/action.yml @@ -0,0 +1,65 @@ +name: Checkout PrestaShop and prepare config +description: Checkout PrestaShop and prepare config +inputs: + pr_number: + description: Pull request Id + required: true + base_branch: + description: Base branch to rebase the PR + required: true + rebase_or_merge: + required: true + description: Rebase or merge the pull request + backoffice_layout: + description: Backoffice layout + required: true + ps_dir: + description: Directory target + required: true + +runs: + using: "composite" + steps: + # Checkout PrestaShop + - uses: actions/checkout@v3 + name: Checkout PrestaShop repository + with: + fetch-depth: 0 + repository: PrestaShop/PrestaShop + path: ${{ inputs.ps_dir }} + + - name: Config git + run: | + git config --local user.email "$(git log --format='%ae' HEAD^!)" + git config --local user.name "$(git log --format='%an' HEAD^!)" + working-directory: ${{ inputs.ps_dir }} + shell: bash + + # Get the PR + - name: Get pull request + working-directory: ${{ inputs.ps_dir }} + run: | + git fetch origin pull/${{ inputs.pr_number }}/head:pr${{ inputs.pr_number }} + git checkout pr${{ inputs.pr_number }} + shell: bash + + - name: Rebase + working-directory: ${{ inputs.ps_dir }} + if: ${{ inputs.rebase_or_merge == 'rebase' }} + run: | + git fetch origin ${{ inputs.base_branch }}:${{ inputs.base_branch }} + git rebase origin/${{ inputs.base_branch }} + shell: bash + + # Workaround until https://github.com/PrestaShop/PrestaShop/issues/29813 is fixed + - name: PrestaShop Configuration (Copy of Config API) + if: (inputs.base_branch == '8.1.x') || (inputs.base_branch == 'develop') + run: cp ./${{ inputs.ps_dir }}/app/config/security_test.yml ./${{ inputs.ps_dir }}/app/config/security_prod.yml + shell: bash + + - name: Adapt Back Office layout + if: inputs.backoffice_layout == 'symfony' + working-directory: ${{ inputs.ps_dir }} + run: | + echo PS_FF_SYMFONY_LAYOUT=true >> .env + shell: bash diff --git a/.github/workflows/actions/run-tests/action.yml b/.github/workflows/actions/run-tests/action.yml new file mode 100644 index 00000000..0b3b97b8 --- /dev/null +++ b/.github/workflows/actions/run-tests/action.yml @@ -0,0 +1,94 @@ +name: Run UI tests +description: Run UI tests +inputs: + base_branch: + description: Base branch to rebase the PR + required: true + ps_mode_dev: + description: Enable/Disable the developer mode + required: true + php_version: + description: PHP version + required: true + node_version: + description: Node version + required: true + test_command: + description: Test command to run + required: true + fast_fail: + description: Fast fail on first error + required: true + ps_dir: + description: Directory target + required: true + +runs: + using: "composite" + steps: + - name: Run tests + run: | + export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem" + npm run test:${{ inputs.test_command }} + working-directory: '${{ inputs.ps_dir }}/tests/UI' + env: + # Input values + PS_MODE_DEV: ${{ fromJson(inputs.ps_mode_dev) && '1' || '0' }} + PS_DEV_MODE: ${{ fromJson(inputs.ps_mode_dev) && '1' || '0' }} + PHP_VERSION: ${{ inputs.php_version }} + NODE_VERSION: ${{ inputs.node_version }} + VERSION: ${{ inputs.php_version }}-apache + PS_DOMAIN: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'localhost:8001' || 'localhost:8002' }} + PS_ENABLE_SSL: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && '0' || '1' }} + ADMIN_PASSWD: ${{ (inputs.base_branch == '1.7.8.x') && 'prestashop_demo' || 'Correct Horse Battery Staple' }} + # Fixed values + DB_USER: root + DB_PASSWD: prestashop + DB_NAME: prestashop + DB_PREFIX: tst_ + DB_SERVER: mysql + PS_DIR: 'my_prestashop' + PS_FOLDER_INSTALL: install-dev + PS_FOLDER_ADMIN: admin-dev + PS_COUNTRY: fr + PS_LANGUAGE: en + ADMIN_MAIL: 'demo@prestashop.com' + # Test variables + URL_FO: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }} + HEADLESS: true + ENABLE_SSL: true + TAKE_SCREENSHOT_AFTER_FAIL: true + SMTP_SERVER: '172.17.0.1' + EXTRA_TEST_PARAMS: ${{ fromJson(inputs.fast_fail) && '--bail' || '' }} + shell: bash + + # UI Tests : Upload screenshots + - name: Prepare screenshot name + id: screenshot-campaign + run: echo "screenshot-campaign=$( echo -e '${{ inputs.test_command }}' | tr ':' '-' )" >> $GITHUB_OUTPUT + if: failure() + shell: bash + + - name: Export docker logs + run: | + mkdir -p ${{ inputs.ps_dir }}/var/docker-logs + docker logs my_prestashop_mysql_1 > ${{ inputs.ps_dir }}/var/docker-logs/mysql.log + docker logs my_prestashop_prestashop-git_1 > ${{ inputs.ps_dir }}/var/docker-logs/prestashop.log + if: failure() + shell: bash + + - name: Export docker keycloak logs + run: | + docker logs my_prestashop_keycloak_1 > ${{ inputs.ps_dir }}/var/docker-logs/keycloak.log + if: failure() && inputs.test_command == 'functional:API' + shell: bash + + - name: Export logs and screenshots as artifacts + uses: actions/upload-artifact@v3 + if: failure() + with: + name: campaign-${{ steps.screenshot-campaign.outputs.screenshot-campaign }} + path: | + ${{ inputs.ps_dir }}/tests/UI/screenshots/ + ${{ inputs.ps_dir }}/var/logs + ${{ inputs.ps_dir }}/var/docker-logs diff --git a/.github/workflows/build-shop.yml b/.github/workflows/build-shop.yml new file mode 100644 index 00000000..0e1ff6c4 --- /dev/null +++ b/.github/workflows/build-shop.yml @@ -0,0 +1,227 @@ +name: Build PrestaShop and export sources and SQL dump as artifacts +on: + workflow_call: + inputs: + pr_number: + type: string + description: Pull request Id + required: true + base_branch: + type: string + description: Base branch to rebase the PR + required: true + ps_mode_dev: + type: boolean + description: Enable/Disable the developer mode + required: true + rebase_or_merge: + type: string + required: true + description: Rebase or merge the pull request + php_version: + type: string + description: PHP version + required: true + node_version: + type: string + description: Node version + required: true + backoffice_layout: + type: string + description: Backoffice layout + required: true + +jobs: + build-shop-artifacts: + runs-on: ubuntu-latest + name: Build shop artifacts + env: + # Input values + PS_MODE_DEV: ${{ inputs.ps_mode_dev && '1' || '0' }} + PS_DEV_MODE: ${{ inputs.ps_mode_dev && '1' || '0' }} + PHP_VERSION: ${{ inputs.php_version }} + NODE_VERSION: ${{ inputs.node_version }} + VERSION: ${{ inputs.php_version }}-apache + PS_DOMAIN: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'localhost:8001' || 'localhost:8002' }} + PS_ENABLE_SSL: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && '0' || '1' }} + ADMIN_PASSWD: ${{ (inputs.base_branch == '1.7.8.x') && 'prestashop_demo' || 'Correct Horse Battery Staple' }} + URL_FO: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }} + # Fixed values + DB_USER: root + DB_PASSWD: prestashop + DB_NAME: prestashop + DB_PREFIX: tst_ + PS_DIR: 'my_prestashop' + PS_FOLDER_INSTALL: install-dev + PS_FOLDER_ADMIN: admin-dev + PS_COUNTRY: fr + PS_LANGUAGE: en + ADMIN_MAIL: 'demo@prestashop.com' + # Build assets and install shop + PS_INSTALL_AUTO: 1 + DISABLE_MAKE: 0 + + steps: + - name: Print Inputs values + shell: bash + run: echo "${{ toJSON(inputs) }}" + + # Checkout repository to use custom actions + - uses: actions/checkout@v3 + with: + path: custom_actions + + - name: Checkout PrestaShop + uses: ./custom_actions/.github/workflows/actions/checkout-prestashop + with: + pr_number: ${{ inputs.pr_number }} + base_branch: ${{ inputs.base_branch }} + rebase_or_merge: ${{ inputs.rebase_or_merge }} + backoffice_layout: ${{ inputs.backoffice_layout }} + ps_dir: ${{ env.PS_DIR }} + + # Pre pull/build images + # For some reason keycloak must be started before the PrestaShop build or it fails + - name: Pull images in background + working-directory: ${{ env.PS_DIR }} + run: | + # Pull mysql image + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml pull -q mysql >& /dev/null & + - name: Build PrestaShop image in background + working-directory: ${{ env.PS_DIR }} + run: | + # Build prestashop image in background + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build >& /dev/null & + + # Run composer install before building the assets since the themes come from composer + - name: Get Composer Cache Directory + id: composer-cache-dir + run: | + echo "composer-cache-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + working-directory: ${{ env.PS_DIR }} + shell: bash + - name: Restore composer cache dir + uses: actions/cache/restore@v3 + id: composer-cache + with: + path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + # Run composer install + - name: Install Composer dependencies + run: composer install --prefer-dist --optimize-autoloader + working-directory: ${{ env.PS_DIR }} + shell: bash + # Save composer cache when it didn't exist + - name: Save composer cache dir + uses: actions/cache/save@v3 + if: steps.composer-cache.outputs.cache-hit != 'true' + with: + path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }} + key: ${{ steps.composer-cache.outputs.cache-primary-key }} + + # Install node dependencies and build assets + - name: Setup Node ${{ inputs.node_version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node_version }} + - name: Build assets in parallel and in background + run: | + (pushd ${{ env.PS_DIR }}/admin-dev/themes/new-theme; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + (pushd ${{ env.PS_DIR }}/admin-dev/themes/default; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + (pushd ${{ env.PS_DIR }}/themes/classic/_dev; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + (pushd ${{ env.PS_DIR }}/themes/; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + shell: bash + + # Certificate + - name: Generate a certificate + if: (inputs.base_branch == '8.1.x') || (inputs.base_branch == 'develop') + run: | + ## Install MkCert + sudo apt install libnss3-tools + curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64" + chmod +x mkcert-v*-linux-amd64 + sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert + ## Generate certificate + mkcert -key-file ./${{ env.PS_DIR }}/.docker/ssl.key -cert-file ./${{ env.PS_DIR }}/.docker/ssl.crt localhost + ## Link certificate to Chrome Trust Store + mkdir -p $HOME/.pki/nssdb + certutil -d $HOME/.pki/nssdb -N + certutil -d sql:$HOME/.pki/nssdb -n localhost -A -t "TCu,Cu,Tu" -i ./${{ env.PS_DIR }}/.docker/ssl.crt + ## Add self-signed certificate to Chrome Trust Store + mkcert -install + + # Wait for all builds to be finished (the check is required because we encountered cases where the action exited before + # everything was built, probably because of the parallelization and background processes) + - name: Check that all builds are finished + run: | + buildLocks="admin-dev/themes/new-theme/buildLock admin-dev/themes/default/buildLock themes/classic/_dev/buildLock themes/buildLock" + echo Checking for all these lock files $buildLocks + for lockFile in $buildLocks; do + lockFile="${{ env.PS_DIR }}/$lockFile" + if [ -f $lockFile ]; then + echo Wait for $lockFile to be removed + sleep 1 + while [ -f $lockFile ]; do + echo $lockFile still present wait a bit more + sleep 1 + done + fi + echo $lockFile is no longer present + done + shell: bash + + # Create shop with Docker build assets, and initialize database and shop content + - name: Start PrestaShop docker + working-directory: ${{ env.PS_DIR }} + timeout-minutes: 5 + env: + URL_FO: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }} + VERSION: ${{ (inputs.base_branch == '1.7.8.x') && inputs.php_version || env.VERSION }} + # Initial build, install shop data but assets are already built + DISABLE_MAKE: 1 + PS_INSTALL_AUTO: 1 + run: | + # First wait for all images to be ready + echo Check that all images are ready + until docker images | grep mysql; do echo Waiting for mysql image; sleep 1; done + until docker images | grep prestashop-git; do echo Waiting for prestashop-git image; sleep 1; done + # Then build and start the docker + echo Build docker via docker composer + USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build prestashop-git + echo Waiting for response from the FO + bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} ${{ env.URL_FO }}en/)" != "200" ]]; do sleep 1; done' + + # Prepare archive contents to share with following jobs + - name: Archive shop content + if: always() + run: | + mkdir -p /tmp/shop-artifacts + zip -q -r /tmp/shop-artifacts/sources.zip ${{ env.PS_DIR }} -x \ + "*/admin-dev/themes/new-theme/node_modules/**/*" \ + "*/admin-dev/themes/default/node_modules/**/*" \ + "*/themes/classic/_dev/**/*" \ + "*/themes/_core/**/*" \ + "*/themes/node_modules/**/*" \ + "*/install-dev/**/*" \ + "*/translations/*.zip" \ + "*/var/cache/**/*" \ + "*/tests/Integration/**/*" \ + "*/tests/Resources/**/*" \ + "*/tests/Unit/**/*" \ + "*/.git/**/*" + docker exec my_prestashop_mysql_1 /usr/bin/mysqldump -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} ${{ env.DB_NAME }} > /tmp/shop-artifacts/db_dump.sql + + - name: Upload shop artifacts + if: always() + uses: actions/upload-artifact@v3 + with: + name: shop-artifacts + path: /tmp/shop-artifacts + + - name: Save logs in case of error + uses: actions/upload-artifact@v3 + if: failure() + with: + name: Build error export logs + path: | + ${{ env.PS_DIR }}/var/logs diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 6a03cd7f..3beb34af 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -15,14 +15,23 @@ on: - '8.0.x' - '1.7.8.x' default: 'develop' + fast_fail: + type: boolean + description: Fast fail on first error + required: true + default: false ps_mode_dev: + type: boolean + description: Use developer mode? + required: true + backoffice_layout: type: choice - description: Enable/Disable the developer mode + description: Backoffice layout required: true options: - - 'true' - - 'false' - default: 'false' + - 'legacy' + - 'symfony' + default: 'legacy' rebase_or_merge: type: choice required: true @@ -50,19 +59,85 @@ on: - '14.21.3' - '16.20.1' default: '14.21.3' - backoffice_layout: - type: choice - description: Backoffice layout - required: true - options: - - 'legacy' - - 'symfony' - default: 'legacy' jobs: - testing-pr: - runs-on: ubuntu-latest - name: test + # Sanity tests are run independently because it's the only campaign that handles the installation itself, since it tests it + sanity-test: + name: Sanity campaign + uses: ./.github/workflows/test-sanity.yml + with: + pr_number: ${{ inputs.pr_number }} + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + rebase_or_merge: ${{ inputs.rebase_or_merge }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + backoffice_layout: ${{ inputs.backoffice_layout }} + fast_fail: ${{ inputs.fast_fail }} + + # We perform a unique build that is stored as an artifact, only then do we start the campaign that will rely on this build + build-shop: + name: Prebuild shop and export artifacts + uses: ./.github/workflows/build-shop.yml + with: + pr_number: ${{ inputs.pr_number }} + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + rebase_or_merge: ${{ inputs.rebase_or_merge }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + backoffice_layout: ${{ inputs.backoffice_layout }} + + # These campaigns are run first because they are longer, so we try to optimize the total run However this list must not + # be too long or too many runners will be blocked by these campaigns and the split would be counter-productive, it's a + # delicate balance to maintain The criteria so far was campaign longer than 15min + test-long-campaigns: + name: Run long campaign ${{ matrix.TEST_COMMAND }} + needs: build-shop + uses: ./.github/workflows/test-with-prebuilt-shop.yml + with: + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + test_command: ${{ matrix.TEST_COMMAND }} + fast_fail: ${{ inputs.fast_fail }} + strategy: + fail-fast: false + matrix: + TEST_COMMAND: + - 'functional:BO:advanced-parameters:07-10' + - 'functional:BO:catalog:03-04' + - 'functional:BO:catalog:07-08' + - 'functional:BO:design' + - 'functional:BO:orders:01-create-orders' + - 'functional:BO:orders:01-view-and-edit-order' + - 'functional:BO:orders:03-05' + - 'functional:BO:shop-parameters:03-04' + - 'functional:BO:shop-parameters:05-07' + - 'functional:BO:shop-parameters:01-02' + - 'functional:FO:classic:08-12' + BASE_BRANCH: + - ${{ inputs.base_branch }} + exclude: + ## 1.7.8.x + - BASE_BRANCH: 1.7.8.x + TEST_COMMAND: 'functional:FO:classic:08-12' + ## 8.0.x + - BASE_BRANCH: 8.0.x + TEST_COMMAND: 'functional:FO:classic:08-12' + + test-short-campaigns: + name: Run short campaign ${{ matrix.TEST_COMMAND }} + needs: build-shop + uses: ./.github/workflows/test-with-prebuilt-shop.yml + with: + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + test_command: ${{ matrix.TEST_COMMAND }} + fast_fail: ${{ inputs.fast_fail }} strategy: fail-fast: false matrix: @@ -71,47 +146,35 @@ jobs: - 'functional:API' - 'functional:BO:login' - 'functional:BO:dashboard' - - 'functional:BO:orders:01:0-1' - - 'functional:BO:orders:01-create-orders' - - 'functional:BO:orders:01-view-and-edit-order' - - 'functional:BO:orders:02' - - 'functional:BO:orders:03-05' + - 'functional:BO:advanced-parameters:01-06' + - 'functional:BO:advanced-parameters:11-12' - 'functional:BO:catalog:01-02' - - 'functional:BO:catalog:03-04' - 'functional:BO:catalog:05-06' - - 'functional:BO:catalog:07-08' - 'functional:BO:customer:01' - 'functional:BO:customer:02-03' - 'functional:BO:customer-service' - - 'functional:BO:modules' - - 'functional:BO:design' - - 'functional:BO:shipping' - - 'functional:BO:payment' + - 'functional:BO:header' - 'functional:BO:international:01' - 'functional:BO:international:02' - 'functional:BO:international:03-04' - - 'functional:BO:shop-parameters:01-02' - - 'functional:BO:shop-parameters:03-04' - - 'functional:BO:shop-parameters:05-07' - - 'functional:BO:advanced-parameters:01-06' - - 'functional:BO:advanced-parameters:07-10' - - 'functional:BO:advanced-parameters:11-12' - - 'functional:BO:header' + - 'functional:BO:modules' + - 'functional:BO:orders:01:0-1' + - 'functional:BO:orders:02' + - 'functional:BO:payment' + - 'functional:BO:shipping' - 'functional:FO:01-03' - 'functional:FO:04-07' - 'functional:FO:08-12' - 'functional:FO:classic:01-03' - 'functional:FO:classic:04-07' - - 'functional:FO:classic:08-12' - 'functional:FO:hummingbird:01-03' - 'functional:productV2' - 'functional:WS' - 'modules' - 'regression' - - 'sanity' - 'sanity:productV2' BASE_BRANCH: - - ${{ github.event.inputs.base_branch }} + - ${{ inputs.base_branch }} exclude: ## 1.7.8.x - BASE_BRANCH: 1.7.8.x @@ -128,8 +191,6 @@ jobs: TEST_COMMAND: 'functional:FO:classic:01-03' - BASE_BRANCH: 1.7.8.x TEST_COMMAND: 'functional:FO:classic:04-07' - - BASE_BRANCH: 1.7.8.x - TEST_COMMAND: 'functional:FO:classic:08-12' - BASE_BRANCH: 1.7.8.x TEST_COMMAND: 'functional:FO:hummingbird:01-03' - BASE_BRANCH: 1.7.8.x @@ -153,8 +214,6 @@ jobs: TEST_COMMAND: 'functional:FO:classic:01-03' - BASE_BRANCH: 8.0.x TEST_COMMAND: 'functional:FO:classic:04-07' - - BASE_BRANCH: 8.0.x - TEST_COMMAND: 'functional:FO:classic:08-12' - BASE_BRANCH: 8.0.x TEST_COMMAND: 'functional:FO:hummingbird:01-03' - BASE_BRANCH: 8.0.x @@ -179,161 +238,3 @@ jobs: TEST_COMMAND: 'functional:FO:08-12' - BASE_BRANCH: develop TEST_COMMAND: 'sanity:productV2' - - env: - PR_NUMBER: ${{ github.event.inputs.pr_number }} - BASE_BRANCH: ${{ github.event.inputs.base_branch }} - PS_MODE_DEV: ${{ github.event.inputs.ps_mode_dev }} - PHP_VERSION: ${{ github.event.inputs.php_version }} - NODE_VERSION: ${{ github.event.inputs.node_version }} - REBASE_OR_MERGE: ${{ github.event.inputs.rebase_or_merge }} - PS_DIR: 'my_prestashop' - ## Install PrestaShop & UI Tests - VERSION: ${{ github.event.inputs.php_version }}-apache - PS_INSTALL_AUTO: 1 - DB_PASSWD: prestashop - DB_NAME: prestashop - DB_SERVER: mysql - DB_PREFIX: tst_ - PS_DOMAIN: ${{ ((github.event.inputs.base_branch == '8.0.x') || (github.event.inputs.base_branch == '1.7.8.x')) && 'localhost:8001' || 'localhost:8002' }} - PS_FOLDER_INSTALL: install-dev - PS_FOLDER_ADMIN: admin-dev - PS_COUNTRY: fr - PS_LANGUAGE: en - PS_DEV_MODE: ${{ github.event.inputs.ps_mode_dev == 'true' && '1' || '0' }} - PS_ENABLE_SSL: ${{ ((github.event.inputs.base_branch == '8.0.x') || (github.event.inputs.base_branch == '1.7.8.x')) && '0' || '1' }} - ADMIN_MAIL: 'demo@prestashop.com' - ADMIN_PASSWD: ${{ (github.event.inputs.base_branch == '1.7.8.x') && 'prestashop_demo' || 'Correct Horse Battery Staple' }} - - steps: - - name: Print Inputs values - shell: bash - run: echo "${{ toJSON(github.event.inputs) }}" - - # Checkout the repository - - uses: actions/checkout@v3 - with: - path: main - - # Checkout PrestaShop - - uses: actions/checkout@v3 - name: Checkout PrestaShop repository - with: - fetch-depth: 0 - repository: PrestaShop/PrestaShop - path: ${{ env.PS_DIR }} - - - name: Config git - run: | - git config --local user.email "$(git log --format='%ae' HEAD^!)" - git config --local user.name "$(git log --format='%an' HEAD^!)" - working-directory: ${{ env.PS_DIR }} - - # Get the PR - - name: Get pull request - working-directory: ${{ env.PS_DIR }} - run: | - git fetch origin pull/${{ env.PR_NUMBER }}/head:pr${{ env.PR_NUMBER }} - git checkout pr${{ env.PR_NUMBER }} - - - name: Rebase - working-directory: ${{ env.PS_DIR }} - if: ${{ env.REBASE_OR_MERGE == 'rebase' }} - run: | - git fetch origin ${{ env.BASE_BRANCH }}:${{ env.BASE_BRANCH }} - git rebase origin/${{ env.BASE_BRANCH }} - - - name: Merge - working-directory: ${{ env.PS_DIR }} - if: ${{ env.REBASE_OR_MERGE == 'merge' }} - run: | - git fetch origin ${{ env.BASE_BRANCH }}:${{ env.BASE_BRANCH }} - git merge origin/${{ env.BASE_BRANCH }} - - # Certificate - - name: Generate a certificate - if: (env.BASE_BRANCH == '8.1.x') || (env.BASE_BRANCH == 'develop') - run: | - ## Install MkCert - sudo apt install libnss3-tools - curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64" - chmod +x mkcert-v*-linux-amd64 - sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert - ## Generate certificate - mkcert -key-file ./${{ env.PS_DIR }}/.docker/ssl.key -cert-file ./${{ env.PS_DIR }}/.docker/ssl.crt localhost - ## Link certificate to Chrome Trust Store - mkdir -p $HOME/.pki/nssdb - certutil -d $HOME/.pki/nssdb -N - certutil -d sql:$HOME/.pki/nssdb -n localhost -A -t "TCu,Cu,Tu" -i ./${{ env.PS_DIR }}/.docker/ssl.crt - ## Add self-signed certificate to Chrome Trust Store - mkcert -install - - # Workaround until https://github.com/PrestaShop/PrestaShop/issues/29813 is fixed - - name: PrestaShop Configuration (Copy of Config API) - if: (env.BASE_BRANCH == '8.1.x') || (env.BASE_BRANCH == 'develop') - run: cp ./${{ env.PS_DIR }}/app/config/security_test.yml ./${{ env.PS_DIR }}/app/config/security_prod.yml - - - name: Adapt Back Office layout - if: inputs.backoffice_layout == 'symfony' - working-directory: ${{ env.PS_DIR }} - shell: bash - run: | - echo PS_FF_SYMFONY_LAYOUT=true >> .env - - # Create shop with Docker - - name: Build and run shop with docker - working-directory: ${{ env.PS_DIR }} - timeout-minutes: 15 - env: - DISABLE_MAKE: 0 - URL_FO: ${{ ((github.event.inputs.base_branch == '8.0.x') || (github.event.inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }} - VERSION: ${{ (github.event.inputs.base_branch == '1.7.8.x') && github.event.inputs.php_version || env.VERSION }} - run: | - USER_ID=$(id -u) GROUP_ID=$(id -g) \ - docker-compose -f docker-compose.yml up -d --build - bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} ${{ env.URL_FO }}en/)" != "200" ]]; do sleep 5; done' - - # UI Tests : Setup, Install & Execute - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - - - name: Setup NPM - run: npm install -g npm@7 - - - name: Install tests dependencies - working-directory: '${{ env.PS_DIR }}/tests/UI' - run: npm install - - - name: Install browsers - if: (env.BASE_BRANCH == 'develop') - working-directory: '${{ env.PS_DIR }}/tests/UI' - run: npx playwright install --with-deps - - - name: Run tests - id: runTests - run: | - export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem" - npm run test:${{ matrix.TEST_COMMAND }} - working-directory: '${{ env.PS_DIR }}/tests/UI' - env: - URL_FO: ${{ ((github.event.inputs.base_branch == '8.0.x') || (github.event.inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }} - DB_NAME: prestashop - DB_PASSWD: prestashop - HEADLESS: true - ENABLE_SSL: true - TAKE_SCREENSHOT_AFTER_FAIL: true - SMTP_SERVER: '172.17.0.1' - - # UI Tests : Upload screenshots - - run: echo "SCREENSHOT_CAMPAIGN=$( echo -e '${{ matrix.TEST_COMMAND }}' | tr ':' '-' )" >> $GITHUB_ENV - if: failure() && steps.runTests.outcome == 'failure' - - - uses: actions/upload-artifact@v3 - if: failure() && steps.runTests.outcome == 'failure' - with: - name: campaign-${{ env.SCREENSHOT_CAMPAIGN }} - path: | - ${{ env.PS_DIR }}/tests/UI/screenshots/ - ${{ env.PS_DIR }}/var/logs diff --git a/.github/workflows/pr_test_single_campaign.yml b/.github/workflows/pr_test_single_campaign.yml new file mode 100644 index 00000000..aab523f5 --- /dev/null +++ b/.github/workflows/pr_test_single_campaign.yml @@ -0,0 +1,151 @@ +name: Testing PrestaShop pull requests with a single test command +on: + workflow_dispatch: + inputs: + pr_number: + description: Pull request Id + required: true + base_branch: + type: choice + description: Base branch to rebase the PR + required: true + options: + - 'develop' + - '8.1.x' + - '8.0.x' + - '1.7.8.x' + default: 'develop' + test_command: + type: choice + description: Select one test command (it may not be available on the selected branch) + required: true + options: + - 'cldr' + - 'functional:API' + - 'functional:BO:login' + - 'functional:BO:dashboard' + - 'functional:BO:orders:01:0-1' + - 'functional:BO:orders:01-create-orders' + - 'functional:BO:orders:01-view-and-edit-order' + - 'functional:BO:orders:02' + - 'functional:BO:orders:03-05' + - 'functional:BO:catalog:01-02' + - 'functional:BO:catalog:03-04' + - 'functional:BO:catalog:05-06' + - 'functional:BO:catalog:07-08' + - 'functional:BO:customer:01' + - 'functional:BO:customer:02-03' + - 'functional:BO:customer-service' + - 'functional:BO:modules' + - 'functional:BO:design' + - 'functional:BO:shipping' + - 'functional:BO:payment' + - 'functional:BO:international:01' + - 'functional:BO:international:02' + - 'functional:BO:international:03-04' + - 'functional:BO:shop-parameters:01-02' + - 'functional:BO:shop-parameters:03-04' + - 'functional:BO:shop-parameters:05-07' + - 'functional:BO:advanced-parameters:01-06' + - 'functional:BO:advanced-parameters:07-10' + - 'functional:BO:advanced-parameters:11-12' + - 'functional:BO:header' + - 'functional:FO:01-03' + - 'functional:FO:04-07' + - 'functional:FO:08-12' + - 'functional:FO:classic:01-03' + - 'functional:FO:classic:04-07' + - 'functional:FO:classic:08-12' + - 'functional:FO:hummingbird:01-03' + - 'functional:productV2' + - 'functional:WS' + - 'modules' + - 'regression' + - 'sanity' + - 'sanity:productV2' + fast_fail: + type: boolean + description: Fast fail on first error + required: true + default: false + ps_mode_dev: + type: boolean + description: Use developer mode? + required: true + backoffice_layout: + type: choice + description: Backoffice layout + required: true + options: + - 'legacy' + - 'symfony' + default: 'legacy' + rebase_or_merge: + type: choice + required: true + description: Rebase or merge the pull request + options: + - 'rebase' + - 'merge' + default: 'rebase' + php_version: + type: choice + description: PHP version + required: true + options: + - '7.3' + - '7.4' + - '8.0' + - '8.1' + - '8.2' + default: '8.1' + node_version: + type: choice + description: Node version + required: true + options: + - '14.21.3' + - '16.20.1' + default: '14.21.3' + +jobs: + build-shop: + name: Prebuild shop and export artifacts for ${{ inputs.test_command }} + if: inputs.test_command != 'sanity' + uses: ./.github/workflows/build-shop.yml + with: + pr_number: ${{ inputs.pr_number }} + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + rebase_or_merge: ${{ inputs.rebase_or_merge }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + backoffice_layout: ${{ inputs.backoffice_layout }} + + test-pr: + name: Run single campaign ${{ inputs.test_command }} + if: inputs.test_command != 'sanity' + needs: build-shop + uses: ./.github/workflows/test-with-prebuilt-shop.yml + with: + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + test_command: ${{ inputs.test_command }} + fast_fail: ${{ inputs.fast_fail }} + + # Sanity campaign is run differently + sanity-test: + name: Run sanity campaign + if: inputs.test_command == 'sanity' + uses: ./.github/workflows/test-sanity.yml + with: + pr_number: ${{ inputs.pr_number }} + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + rebase_or_merge: ${{ inputs.rebase_or_merge }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + backoffice_layout: ${{ inputs.backoffice_layout }} + fast_fail: ${{ inputs.fast_fail }} diff --git a/.github/workflows/test-sanity.yml b/.github/workflows/test-sanity.yml new file mode 100644 index 00000000..7f76b6fa --- /dev/null +++ b/.github/workflows/test-sanity.yml @@ -0,0 +1,209 @@ +name: Install shop and run sanity tests +on: + workflow_call: + inputs: + pr_number: + type: string + description: Pull request Id + required: true + base_branch: + type: string + description: Base branch to rebase the PR + required: true + ps_mode_dev: + type: boolean + description: Enable/Disable the developer mode + required: true + rebase_or_merge: + type: string + required: true + description: Rebase or merge the pull request + php_version: + type: string + description: PHP version + required: true + node_version: + type: string + description: Node version + required: true + backoffice_layout: + type: string + description: Backoffice layout + required: true + fast_fail: + type: boolean + description: Fast fail on first error + required: true + default: false + +jobs: + test-sanity: + runs-on: ubuntu-latest + name: Run UI Tests ${{ inputs.test_command }} + env: + # Input values + PS_MODE_DEV: ${{ inputs.ps_mode_dev && '1' || '0' }} + PS_DEV_MODE: ${{ inputs.ps_mode_dev && '1' || '0' }} + PHP_VERSION: ${{ inputs.php_version }} + NODE_VERSION: ${{ inputs.node_version }} + VERSION: ${{ inputs.php_version }}-apache + PS_DOMAIN: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'localhost:8001' || 'localhost:8002' }} + PS_ENABLE_SSL: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && '0' || '1' }} + ADMIN_PASSWD: ${{ (inputs.base_branch == '1.7.8.x') && 'prestashop_demo' || 'Correct Horse Battery Staple' }} + # Fixed values + DB_USER: root + DB_PASSWD: prestashop + DB_NAME: prestashop + DB_PREFIX: tst_ + DB_SERVER: mysql + PS_DIR: 'my_prestashop' + PS_FOLDER_INSTALL: install-dev + PS_FOLDER_ADMIN: admin-dev + PS_COUNTRY: fr + PS_LANGUAGE: en + ADMIN_MAIL: 'demo@prestashop.com' + + steps: + - name: Print Inputs values + shell: bash + run: echo "${{ toJSON(inputs) }}" + + # Checkout repository to use custom actions + - uses: actions/checkout@v3 + with: + path: custom_actions + + - name: Checkout PrestaShop + uses: ./custom_actions/.github/workflows/actions/checkout-prestashop + with: + pr_number: ${{ inputs.pr_number }} + base_branch: ${{ inputs.base_branch }} + rebase_or_merge: ${{ inputs.rebase_or_merge }} + backoffice_layout: ${{ inputs.backoffice_layout }} + ps_dir: ${{ env.PS_DIR }} + + # Pre pull/build images (no need for keycloak) + - name: Pull mysql image in background + working-directory: ${{ env.PS_DIR }} + run: | + # Pull mysql image + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml pull -q mysql >& /dev/null & + - name: Build PrestaShop image in background + working-directory: ${{ env.PS_DIR }} + run: | + # Build prestashop image in background + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build >& /dev/null & + + # Certificate + - name: Generate a certificate + if: (inputs.base_branch == '8.1.x') || (inputs.base_branch == 'develop') + run: | + ## Install MkCert + sudo apt install libnss3-tools + curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64" + chmod +x mkcert-v*-linux-amd64 + sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert + ## Generate certificate + mkcert -key-file ./${{ env.PS_DIR }}/.docker/ssl.key -cert-file ./${{ env.PS_DIR }}/.docker/ssl.crt localhost + ## Link certificate to Chrome Trust Store + mkdir -p $HOME/.pki/nssdb + certutil -d $HOME/.pki/nssdb -N + certutil -d sql:$HOME/.pki/nssdb -n localhost -A -t "TCu,Cu,Tu" -i ./${{ env.PS_DIR }}/.docker/ssl.crt + ## Add self-signed certificate to Chrome Trust Store + mkcert -install + + # Run composer install before building the assets since the themes come from composer + - name: Get Composer Cache Directory + id: composer-cache-dir + run: | + echo "composer-cache-dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + working-directory: ${{ env.PS_DIR }} + shell: bash + - name: Restore composer cache dir + uses: actions/cache/restore@v3 + id: composer-cache + with: + path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + # Run composer install + - name: Install Composer dependencies + run: composer install --prefer-dist --optimize-autoloader + working-directory: ${{ env.PS_DIR }} + shell: bash + # Save composer cache when it didn't exist + - name: Save composer cache dir + uses: actions/cache/save@v3 + if: steps.composer-cache.outputs.cache-hit != 'true' + with: + path: ${{ steps.composer-cache-dir.outputs.composer-cache-dir }} + key: ${{ steps.composer-cache.outputs.cache-primary-key }} + + # Create shop with Docker without building assets, and initialize database and shop content + # No need to wait for install-dev ready it should be nearly automatic and just in case we build the assets after to leave + # a bit more time for the docker to fully init + - name: Build and run shop with docker + working-directory: ${{ env.PS_DIR }} + timeout-minutes: 15 + env: + URL_FO: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }} + VERSION: ${{ (inputs.base_branch == '1.7.8.x') && inputs.php_version || env.VERSION }} + # No assets built, already done and no install since the campaign handles it + DISABLE_MAKE: 1 + PS_INSTALL_AUTO: 0 + run: | + # First wait for all images to be ready + echo Check that all images are ready + until docker images | grep mysql; do echo Waiting for mysql image; sleep 1; done + until docker images | grep prestashop-git; do echo Waiting for prestashop-git image; sleep 1; done + # Then build and start the docker, no need to wait the install page is accessible right away + echo Build docker via docker composer + USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build prestashop-git + + # Install node dependencies and build assets + - name: Setup Node ${{ inputs.node_version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node_version }} + - name: Build assets in parallel and in background + run: | + (pushd ${{ env.PS_DIR }}/tests/UI; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + (pushd ${{ env.PS_DIR }}/admin-dev/themes/new-theme; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + (pushd ${{ env.PS_DIR }}/admin-dev/themes/default; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + (pushd ${{ env.PS_DIR }}/themes/classic/_dev; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + (pushd ${{ env.PS_DIR }}/themes/; touch buildLock; npm ci; npm run build; rm buildLock; popd) & + shell: bash + # Wait for all builds to be finished (the check is required because we encountered cases where the action exited before + # everything was built, probably because of the parallelization and background processes) + - name: Check that all builds are finished + run: | + buildLocks="tests/UI admin-dev/themes/new-theme/buildLock admin-dev/themes/default/buildLock themes/classic/_dev/buildLock themes/buildLock" + echo Checking for all these lock files $buildLocks + for lockFile in $buildLocks; do + lockFile="${{ env.PS_DIR }}/$lockFile" + if [ -f $lockFile ]; then + echo Wait for $lockFile to be removed + sleep 1 + while [ -f $lockFile ]; do + echo $lockFile still present wait a bit more + sleep 1 + done + fi + echo $lockFile is no longer present + done + shell: bash + # Playwright must be installed all the time, we only install chromium since it's the only browser used + - name: Install playwright + working-directory: ${{ env.PS_DIR }}/tests/UI + run: | + npx playwright install chromium + + - name: Run sanity campaign + uses: ./custom_actions/.github/workflows/actions/run-tests + with: + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + test_command: sanity + fast_fail: ${{ inputs.fast_fail }} + ps_dir: ${{ env.PS_DIR }} diff --git a/.github/workflows/test-with-prebuilt-shop.yml b/.github/workflows/test-with-prebuilt-shop.yml new file mode 100644 index 00000000..7465a3f5 --- /dev/null +++ b/.github/workflows/test-with-prebuilt-shop.yml @@ -0,0 +1,184 @@ +name: Run UI tests with prebuilt shop +on: + workflow_call: + inputs: + base_branch: + type: string + description: Base branch to rebase the PR + required: true + ps_mode_dev: + type: boolean + description: Enable/Disable the developer mode + required: true + php_version: + type: string + description: PHP version + required: true + node_version: + type: string + description: Node version + required: true + test_command: + type: string + description: Test command to run + required: true + fast_fail: + type: boolean + description: Fast fail on first error + required: true + default: false + +jobs: + install-from-artifact: + runs-on: ubuntu-latest + name: Run UI Tests ${{ inputs.test_command }} + env: + # Input values + PS_MODE_DEV: ${{ inputs.ps_mode_dev && '1' || '0' }} + PS_DEV_MODE: ${{ inputs.ps_mode_dev && '1' || '0' }} + PHP_VERSION: ${{ inputs.php_version }} + NODE_VERSION: ${{ inputs.node_version }} + VERSION: ${{ inputs.php_version }}-apache + PS_DOMAIN: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'localhost:8001' || 'localhost:8002' }} + PS_ENABLE_SSL: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && '0' || '1' }} + ADMIN_PASSWD: ${{ (inputs.base_branch == '1.7.8.x') && 'prestashop_demo' || 'Correct Horse Battery Staple' }} + # Fixed values + DB_USER: root + DB_PASSWD: prestashop + DB_NAME: prestashop + DB_PREFIX: tst_ + DB_SERVER: mysql + PS_DIR: 'my_prestashop' + PS_FOLDER_INSTALL: install-dev + PS_FOLDER_ADMIN: admin-dev + PS_COUNTRY: fr + PS_LANGUAGE: en + ADMIN_MAIL: 'demo@prestashop.com' + + steps: + - name: Print Inputs values + shell: bash + run: echo "${{ toJSON(inputs) }}" + + # Checkout repository to use custom actions + - uses: actions/checkout@v3 + with: + path: custom_actions + + - name: Download docker artifacts + uses: actions/download-artifact@v3 + with: + name: shop-artifacts + path: /tmp/shop-artifacts + + - name: Extract PrestaShop sources + run: | + unzip /tmp/shop-artifacts/sources.zip -d . + + # Pre pull/build images + - name: Pull mysql in background + working-directory: ${{ env.PS_DIR }} + run: | + # Pull mysql image + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml pull -q mysql >& /dev/null & + - name: Pull keycloak in background + if: inputs.test_command == 'functional:API' + working-directory: ${{ env.PS_DIR }} + run: | + # Pull keycloak image + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml pull -q keycloak >& /dev/null & + - name: Build PrestaShop image in background + working-directory: ${{ env.PS_DIR }} + run: | + # Build prestashop image in background + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build >& /dev/null & + + # Certificate + - name: Generate a certificate + if: (inputs.base_branch == '8.1.x') || (inputs.base_branch == 'develop') + run: | + ## Install MkCert + sudo apt install libnss3-tools + curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64" + chmod +x mkcert-v*-linux-amd64 + sudo cp mkcert-v*-linux-amd64 /usr/local/bin/mkcert + ## Generate certificate + mkcert -key-file ./${{ env.PS_DIR }}/.docker/ssl.key -cert-file ./${{ env.PS_DIR }}/.docker/ssl.crt localhost + ## Link certificate to Chrome Trust Store + mkdir -p $HOME/.pki/nssdb + certutil -d $HOME/.pki/nssdb -N + certutil -d sql:$HOME/.pki/nssdb -n localhost -A -t "TCu,Cu,Tu" -i ./${{ env.PS_DIR }}/.docker/ssl.crt + ## Add self-signed certificate to Chrome Trust Store + mkcert -install + + - name: Setup database + working-directory: ${{ env.PS_DIR }} + timeout-minutes: 5 + run: | + echo Starting mysql docker alone + USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build mysql + echo Wait until mysql is accessible minimum 10 seconds before testing + sleep 10 + until docker exec my_prestashop_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }}; do echo "Sleep and retry to check"; sleep 2; done + echo Copying dump into docker + docker cp /tmp/shop-artifacts/db_dump.sql my_prestashop_mysql_1:/tmp/db_dump.sql + echo Creating ${{ env.DB_NAME }} database + docker exec my_prestashop_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} -e "CREATE DATABASE IF NOT EXISTS ${{ env.DB_NAME }};" + echo Load dump into DB + docker exec my_prestashop_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} ${{ env.DB_NAME }} -e "source /tmp/db_dump.sql;" + + - name: Build keycloak + if: inputs.test_command == 'functional:API' + working-directory: ${{ env.PS_DIR }} + run: | + until docker images | grep keycloak; do echo Waiting for keycloak image; sleep 1; done + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml up -d --build keycloak + + - name: Start up shop docker + working-directory: ${{ env.PS_DIR }} + timeout-minutes: 5 + env: + VERSION: ${{ (inputs.base_branch == '1.7.8.x') && inputs.php_version || env.VERSION }} + URL_FO: ${{ ((inputs.base_branch == '8.0.x') || (inputs.base_branch == '1.7.8.x')) && 'http://localhost:8001/' || 'https://localhost:8002/' }} + # No install we force the sources and load the SQL dump + PS_INSTALL_AUTO: 0 + DISABLE_MAKE: 1 + # For API tests we build all containers (including keycloak) for other tests only prestashop is needed + BUILT_CONTAINERS: ${{ (inputs.test_command == 'functional:API') && '' || 'prestashop-git' }} + run: | + # First wait for all images to be ready + echo Check that all images are ready + until docker images | grep mysql; do echo Waiting for mysql image; sleep 1; done + until docker images | grep prestashop-git; do echo Waiting for prestashop-git image; sleep 1; done + echo Build the remaining dockers + USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build ${{ env.BUILT_CONTAINERS }} + echo Waiting for response from the FO + bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} ${{ env.URL_FO }}en/)" != "200" ]]; do sleep 5; done' + + # Test dependencies are installed manually in each sub job that test the build, it could have been integrated inside the archive to reduce time here + # but it turns out the archive is much bigger with all this code and it makes upload/download phase so much longer that it is more efficient to install + # this here + - name: Setup Node ${{ inputs.node_version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node_version }} + - name: Build test dependencies + working-directory: ${{ env.PS_DIR }}/tests/UI + run: | + npm ci + # Playwright must be installed all the time, we only install chromium since it's the only browser used + - name: Install playwright + working-directory: ${{ env.PS_DIR }}/tests/UI + run: | + npx playwright install chromium + + - name: Run campaign ${{ inputs.test_command }} on prebuilt shop + uses: ./custom_actions/.github/workflows/actions/run-tests + with: + base_branch: ${{ inputs.base_branch }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} + php_version: ${{ inputs.php_version }} + node_version: ${{ inputs.node_version }} + test_command: ${{ inputs.test_command }} + fast_fail: ${{ inputs.fast_fail }} + ps_dir: ${{ env.PS_DIR }}