From 60268bc7f6a6190cd4c2176e77e2a9acf22bd13b Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Wed, 3 Apr 2024 23:40:31 +0200 Subject: [PATCH] Checkout keycloak module for API tests to launch docker from the module --- .../actions/launch-keycloak/action.yml | 16 ++++++++++++ .../workflows/actions/run-tests/action.yml | 2 +- .github/workflows/build-shop.yml | 1 - .github/workflows/pr_test_one.yml | 11 +++++++- .github/workflows/test-sanity.yml | 1 - .github/workflows/test-with-prebuilt-shop.yml | 25 ++++++------------- 6 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/actions/launch-keycloak/action.yml diff --git a/.github/workflows/actions/launch-keycloak/action.yml b/.github/workflows/actions/launch-keycloak/action.yml new file mode 100644 index 00000000..61d54494 --- /dev/null +++ b/.github/workflows/actions/launch-keycloak/action.yml @@ -0,0 +1,16 @@ +name: Launch keycloak +description: Checkout keycloak module for installation and to launch keycloak docker + +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + name: Checkout keycloak module + with: + repository: PrestaShop/keycloak_connector_demo + ref: v1.1.0 + path: keycloak_connector_demo + - name: Build keycloak docker and install module via CLI command + run: | + USER_ID=$(id -u) GROUP_ID=$(id -g) docker compose -f keycloak_connector_demo/docker-compose-ui.yml up -d + shell: bash diff --git a/.github/workflows/actions/run-tests/action.yml b/.github/workflows/actions/run-tests/action.yml index cec74568..41dc792f 100644 --- a/.github/workflows/actions/run-tests/action.yml +++ b/.github/workflows/actions/run-tests/action.yml @@ -80,7 +80,7 @@ runs: - name: Export docker keycloak logs run: | - docker logs my_prestashop-keycloak-1 > ${{ inputs.ps_dir }}/var/docker-logs/keycloak.log + docker logs keycloak_connector_demo-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-shop.yml b/.github/workflows/build-shop.yml index 64866575..25195442 100644 --- a/.github/workflows/build-shop.yml +++ b/.github/workflows/build-shop.yml @@ -82,7 +82,6 @@ jobs: 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: | diff --git a/.github/workflows/pr_test_one.yml b/.github/workflows/pr_test_one.yml index 66910fcd..f9a25fef 100644 --- a/.github/workflows/pr_test_one.yml +++ b/.github/workflows/pr_test_one.yml @@ -221,7 +221,7 @@ jobs: run: | git fetch origin ${{ inputs.BASE_BRANCH }} git ${{ inputs.REBASE_OR_MERGE }} origin/${{ inputs.BASE_BRANCH }} - + - name: Setup Environment timeout-minutes: 15 uses: ./.github/actions/setup-env @@ -238,6 +238,15 @@ jobs: INSTALL_AUTO: ${{ (matrix.TEST_CAMPAIGN == 'sanity') && 'false' || 'true' }} CP_API_CONFIG: ${{ (matrix.BASE_BRANCH == '8.1.x') && 'true' || 'false' }} + # Checkout repository to use custom actions + - uses: actions/checkout@v4 + with: + path: custom_actions + # Keycloak is only needed for API campaign + - name: Launch keycloak + uses: ./custom_actions/.github/workflows/actions/launch-keycloak + if: matrix.TEST_CAMPAIGN == 'functional:API' && matrix.BASE_BRANCH == 'develop' + - name: Run Tests id: runTests uses: ./.github/actions/ui-test diff --git a/.github/workflows/test-sanity.yml b/.github/workflows/test-sanity.yml index 8b9f2d85..7995827f 100644 --- a/.github/workflows/test-sanity.yml +++ b/.github/workflows/test-sanity.yml @@ -83,7 +83,6 @@ jobs: 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: | diff --git a/.github/workflows/test-with-prebuilt-shop.yml b/.github/workflows/test-with-prebuilt-shop.yml index ff8e3921..ece12fe1 100644 --- a/.github/workflows/test-with-prebuilt-shop.yml +++ b/.github/workflows/test-with-prebuilt-shop.yml @@ -74,7 +74,7 @@ jobs: - name: Extract PrestaShop sources run: | - unzip /tmp/shop-artifacts/sources.zip -d . + unzip -qq /tmp/shop-artifacts/sources.zip -d . # Pre pull/build images - name: Pull mysql in background @@ -82,12 +82,7 @@ jobs: 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: | @@ -129,13 +124,6 @@ jobs: 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 @@ -145,18 +133,21 @@ jobs: # 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 }} + USER_ID=$(id -u) GROUP_ID=$(id -g) docker compose -f docker-compose.yml up -d --build 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' + # Keycloak is only needed for API campaign + - name: Launch keycloak + uses: ./custom_actions/.github/workflows/actions/launch-keycloak + if: inputs.test_command == 'functional:API' && inputs.base_branch == 'develop' + # 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