From 61ddb534d352bcac0055b5f8e056b6f76a42c995 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Tue, 26 Sep 2023 02:20:31 +0200 Subject: [PATCH] Fix checkout on develop, build docker images explicitely for old branches that do not have the dependencies set in their docker-compose.yml file, dynamize docker names the prefix is based on root folder --- .../workflows/actions/archive-shop/action.yml | 4 +++- .../actions/checkout-prestashop/action.yml | 10 +------- .../workflows/actions/run-tests/action.yml | 9 +++---- .github/workflows/build-release.yml | 2 +- .github/workflows/build-shop.yml | 16 ++++++++++--- .github/workflows/test-sanity.yml | 4 ++-- .github/workflows/test-with-prebuilt-shop.yml | 12 ++++++---- .github/workflows/upgrade-shop.yml | 24 ++++++++++++------- .github/workflows/upgrade_test.yml | 5 ++++ 9 files changed, 52 insertions(+), 34 deletions(-) diff --git a/.github/workflows/actions/archive-shop/action.yml b/.github/workflows/actions/archive-shop/action.yml index 01e4f79b..bc92f146 100644 --- a/.github/workflows/actions/archive-shop/action.yml +++ b/.github/workflows/actions/archive-shop/action.yml @@ -22,6 +22,8 @@ runs: using: "composite" steps: - name: Archive shop content + env: + DOCKER_PREFIX: ${{ inputs.ps_dir }} run: | mkdir -p /tmp/${{ inputs.artifact_name }} pushd ${{ inputs.ps_dir }}; zip -q -r /tmp/${{ inputs.artifact_name }}/sources.zip . -x \ @@ -37,7 +39,7 @@ runs: "tests/Resources/**/*" \ "tests/Unit/**/*" \ ".git/**/*"; popd - docker exec my_prestashop_mysql_1 /usr/bin/mysqldump -u ${{ inputs.db_user }} -p${{ inputs.db_password }} ${{ inputs.db_name }} > /tmp/${{ inputs.artifact_name }}/db_dump.sql + docker exec ${{ env.DOCKER_PREFIX }}_mysql_1 /usr/bin/mysqldump -u ${{ inputs.db_user }} -p${{ inputs.db_password }} ${{ inputs.db_name }} > /tmp/${{ inputs.artifact_name }}/db_dump.sql shell: bash - name: Upload shop artifacts "${{ inputs.artifact_name }}" diff --git a/.github/workflows/actions/checkout-prestashop/action.yml b/.github/workflows/actions/checkout-prestashop/action.yml index 8486ce7e..6d84f940 100644 --- a/.github/workflows/actions/checkout-prestashop/action.yml +++ b/.github/workflows/actions/checkout-prestashop/action.yml @@ -62,21 +62,13 @@ runs: # Or simply get the branch/tag - name: Get ref from repository ${{ inputs.repository_ref }} - if: inputs.pr_number == '' && inputs.rebase_or_merge == '' + if: inputs.pr_number == '' && inputs.rebase_or_merge == '' && inputs.repository_ref != 'develop' working-directory: ${{ inputs.ps_dir }} run: | git fetch origin ${{ inputs.repository_ref }}:${{ inputs.repository_ref }} git checkout ${{ inputs.repository_ref }} shell: bash - - name: Merge - working-directory: ${{ inputs.ps_dir }} - if: ${{ inputs.rebase_or_merge == 'merge' }} - run: | - git fetch origin ${{ inputs.base_branch }}:${{ inputs.base_branch }} - git merge 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: startsWith(inputs.repository_ref, '8.1') || (inputs.repository_ref == 'develop') diff --git a/.github/workflows/actions/run-tests/action.yml b/.github/workflows/actions/run-tests/action.yml index 0b3b97b8..db76d83c 100644 --- a/.github/workflows/actions/run-tests/action.yml +++ b/.github/workflows/actions/run-tests/action.yml @@ -47,7 +47,6 @@ runs: 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 @@ -70,16 +69,18 @@ runs: shell: bash - name: Export docker logs + env: + DOCKER_PREFIX: ${{ inputs.ps_dir }} 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 + docker logs ${{ env.DOCKER_PREFIX }}_mysql_1 > ${{ inputs.ps_dir }}/var/docker-logs/mysql.log + docker logs ${{ env.DOCKER_PREFIX }}_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 + docker logs ${{ inputs.ps_dir }}_keycloak_1 > ${{ inputs.ps_dir }}/var/docker-logs/keycloak.log if: failure() && inputs.test_command == 'functional:API' shell: bash diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index e7a2332b..21c72979 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -51,7 +51,7 @@ jobs: id: export-folder working-directory: ${{ env.PS_TARGET }} run: | - exportFolder=$(pwd)/$(ls tools/build/releases/) + exportFolder=$(pwd)/tools/build/releases/$(ls tools/build/releases/) echo "export-folder=$exportFolder" >> $GITHUB_OUTPUT - name: Upload built release diff --git a/.github/workflows/build-shop.yml b/.github/workflows/build-shop.yml index a69e2d18..31a89b0b 100644 --- a/.github/workflows/build-shop.yml +++ b/.github/workflows/build-shop.yml @@ -43,7 +43,7 @@ on: jobs: build-shop-artifacts: runs-on: ubuntu-latest - name: Build shop artifacts + name: Build shop artifacts based on ${{ inputs.repository_ref }} env: # Input values PS_MODE_DEV: ${{ inputs.ps_mode_dev && '1' || '0' }} @@ -100,7 +100,7 @@ jobs: 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 & + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build prestashop-git >& /dev/null & # Run composer install before building the assets since the themes come from composer - name: Get Composer Cache Directory @@ -196,7 +196,7 @@ jobs: 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 + USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build prestashop-git mysql 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' @@ -211,6 +211,15 @@ jobs: db_name: ${{ env.DB_NAME }} artifact_name: ${{ inputs.artifact_name }} + - name: Export docker logs + if: failure() + env: + DOCKER_PREFIX: ${{ env.PS_DIR }} + run: | + mkdir -p ${{ env.PS_DIR }}/var/docker-logs + docker logs ${{ env.DOCKER_PREFIX }}_prestashop-git_1 > ${{ env.PS_DIR }}/var/docker-logs/prestashop.log + docker logs ${{ env.DOCKER_PREFIX }}_mysql_1 > ${{ env.PS_DIR }}/var/docker-logs/mysql.log + - name: Save logs in case of error uses: actions/upload-artifact@v3 if: failure() @@ -218,3 +227,4 @@ jobs: name: Build error export logs path: | ${{ env.PS_DIR }}/var/logs + ${{ env.PS_DIR }}/var/docker-logs diff --git a/.github/workflows/test-sanity.yml b/.github/workflows/test-sanity.yml index e5831538..eb3006ed 100644 --- a/.github/workflows/test-sanity.yml +++ b/.github/workflows/test-sanity.yml @@ -91,7 +91,7 @@ jobs: 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 & + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build prestashop-git >& /dev/null & # Certificate - name: Generate a certificate @@ -156,7 +156,7 @@ jobs: 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 + USER_ID=$(id -u) GROUP_ID=$(id -g) docker-compose -f docker-compose.yml up -d --build prestashop-git mysql # Install node dependencies and build assets - name: Setup Node ${{ inputs.node_version }} diff --git a/.github/workflows/test-with-prebuilt-shop.yml b/.github/workflows/test-with-prebuilt-shop.yml index 5dd7c092..dcc8c2f3 100644 --- a/.github/workflows/test-with-prebuilt-shop.yml +++ b/.github/workflows/test-with-prebuilt-shop.yml @@ -87,7 +87,7 @@ jobs: 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 & + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build prestashop-git >& /dev/null & # Certificate - name: Generate a certificate @@ -110,18 +110,20 @@ jobs: - name: Setup database working-directory: ${{ env.PS_DIR }} timeout-minutes: 5 + env: + DOCKER_PREFIX: ${{ env.PS_DIR }} 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 + until docker exec ${{ env.DOCKER_PREFIX }}_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 ${{ steps.download-shop.outputs.db-dump-path }} my_prestashop_mysql_1:/tmp/db_dump.sql + docker cp ${{ steps.download-shop.outputs.db-dump-path }} ${{ env.DOCKER_PREFIX }}_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 }};" + docker exec ${{ env.DOCKER_PREFIX }}_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;" + docker exec ${{ env.DOCKER_PREFIX }}_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' diff --git a/.github/workflows/upgrade-shop.yml b/.github/workflows/upgrade-shop.yml index 490f4349..a872b101 100644 --- a/.github/workflows/upgrade-shop.yml +++ b/.github/workflows/upgrade-shop.yml @@ -76,7 +76,7 @@ jobs: 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 & + USER_ID=$(id -u) GROUP_ID=$(id -g) nohup docker-compose -f docker-compose.yml build prestashop-git >& /dev/null & # Certificate - name: Generate a certificate @@ -99,18 +99,20 @@ jobs: - name: Setup database working-directory: ${{ env.PS_DIR }} timeout-minutes: 5 + env: + DOCKER_PREFIX: ${{ env.PS_DIR }} 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 + until docker exec ${{ env.DOCKER_PREFIX }}_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 ${{ steps.download-shop.outputs.db-dump-path }} my_prestashop_mysql_1:/tmp/db_dump.sql + docker cp ${{ steps.download-shop.outputs.db-dump-path }} ${{ env.DOCKER_PREFIX }}_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 }};" + docker exec ${{ env.DOCKER_PREFIX }}_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;" + docker exec ${{ env.DOCKER_PREFIX }}_mysql_1 /usr/bin/mysql -u ${{ env.DB_USER }} -p${{ env.DB_PASSWD }} ${{ env.DB_NAME }} -e "source /tmp/db_dump.sql;" - name: Start up shop docker working-directory: ${{ env.PS_DIR }} @@ -144,7 +146,9 @@ jobs: working-directory: ${{ env.PS_DIR }}/modules/autoupgrade - name: Install module via CLI commands - run: docker exec -u www-data my_prestashop_prestashop-git_1 php bin/console prestashop:module install autoupgrade + env: + DOCKER_PREFIX: ${{ env.PS_DIR }} + run: docker exec -u www-data ${{ env.DOCKER_PREFIX }}_prestashop-git_1 php bin/console prestashop:module install autoupgrade - name: Prepare archive folder run: mkdir -p ${{ env.PS_DIR }}/modules/autoupgrade/releases/download @@ -164,10 +168,12 @@ jobs: echo "{\"channel\":\"archive\",\"archive_prestashop\":\"$zipFile\",\"archive_num\":\"$zipVersion\", \"archive_xml\":\"$xmlFile\", \"PS_AUTOUP_CHANGE_DEFAULT_THEME\":"0", \"skip_backup\": "1"}" > ${{ env.PS_DIR }}/modules/autoupgrade/config.json - name: Run CLI upgrade based on target release archive + env: + DOCKER_PREFIX: ${{ env.PS_DIR }} run: | - docker exec -u www-data my_prestashop_prestashop-git_1 php modules/autoupgrade/cli-updateconfig.php --from=modules/autoupgrade/config.json --dir=admin-dev - docker exec -u www-data my_prestashop_prestashop-git_1 php modules/autoupgrade/tests/testCliProcess.php modules/autoupgrade/cli-upgrade.php --dir="admin-dev" --action="compareReleases" - docker exec -u www-data my_prestashop_prestashop-git_1 php modules/autoupgrade/tests/testCliProcess.php modules/autoupgrade/cli-upgrade.php --dir=admin-dev + docker exec -u www-data ${{ env.DOCKER_PREFIX }}_prestashop-git_1 php modules/autoupgrade/cli-updateconfig.php --from=modules/autoupgrade/config.json --dir=admin-dev + docker exec -u www-data ${{ env.DOCKER_PREFIX }}_prestashop-git_1 php modules/autoupgrade/tests/testCliProcess.php modules/autoupgrade/cli-upgrade.php --dir="admin-dev" --action="compareReleases" + docker exec -u www-data ${{ env.DOCKER_PREFIX }}_prestashop-git_1 php modules/autoupgrade/tests/testCliProcess.php modules/autoupgrade/cli-upgrade.php --dir=admin-dev # Prepare archive contents to share with following jobs - name: Archive shop content diff --git a/.github/workflows/upgrade_test.yml b/.github/workflows/upgrade_test.yml index d3e39280..4f02852d 100644 --- a/.github/workflows/upgrade_test.yml +++ b/.github/workflows/upgrade_test.yml @@ -36,6 +36,10 @@ on: - 'v4.15.0' - 'v4.14.2' default: 'dev' + ps_mode_dev: + type: boolean + description: Use developer mode? + required: true php_version: type: choice description: PHP version @@ -62,6 +66,7 @@ jobs: uses: ./.github/workflows/build-shop.yml with: repository_ref: ${{ inputs.source_ref }} + ps_mode_dev: ${{ inputs.ps_mode_dev }} php_version: ${{ inputs.php_version }} node_version: ${{ inputs.node_version }} artifact_name: source_shop