From c1ef47404486aa2f64fc7df3133dc24dd044103a Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 17 Apr 2024 15:17:52 +0300 Subject: [PATCH 01/11] UHF-9978: Never process external menu blocks --- hdbt.theme | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hdbt.theme b/hdbt.theme index 7b8f7a8e8..5aa7bd430 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -509,6 +509,11 @@ function hdbt_preprocess_input__submit(&$variables): void { * Implements hook_preprocess_HOOK(). */ function hdbt_preprocess_menu(&$variables): void { + if (isset($variables['attributes']['block_id'])) { + if (str_starts_with('external_menu_', $variables['attributes']['block_id'])) { + return; + } + } $apply_lang_attribute = array_key_exists('menu_type', $variables); if ( From d9755c08740a980efd37d21af2447159d5e61d19 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 17 Apr 2024 16:26:18 +0300 Subject: [PATCH 02/11] UHF-9978: Optimized menu attributes logic --- hdbt.theme | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/hdbt.theme b/hdbt.theme index 5aa7bd430..37f1b699e 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -509,10 +509,14 @@ function hdbt_preprocess_input__submit(&$variables): void { * Implements hook_preprocess_HOOK(). */ function hdbt_preprocess_menu(&$variables): void { - if (isset($variables['attributes']['block_id'])) { - if (str_starts_with('external_menu_', $variables['attributes']['block_id'])) { - return; - } + // Menu, mobile menu, fallback menu and sidebar menu tree depth. + // Counting from "instance", "main level", "level 3", "level 4", "level 5"... + $menu_depth = 5; + $variables['menu_depth'] = $menu_depth; + $variables['#attached']['drupalSettings']['menu_depth'] = $menu_depth; + + if (isset($variables['attributes']['block_id']) && str_starts_with('external_menu_', $variables['attributes']['block_id'])) { + return; } $apply_lang_attribute = array_key_exists('menu_type', $variables); @@ -526,12 +530,6 @@ function hdbt_preprocess_menu(&$variables): void { foreach ($variables['items'] as &$item) { _hdbt_menu_item_apply_attributes($item, $apply_lang_attribute); } - - // Menu, mobile menu, fallback menu and sidebar menu tree depth. - // Counting from "instance", "main level", "level 3", "level 4", "level 5"... - $menu_depth = 5; - $variables['menu_depth'] = $menu_depth; - $variables['#attached']['drupalSettings']['menu_depth'] = $menu_depth; } /** @@ -574,25 +572,15 @@ function _hdbt_menu_item_apply_attributes(array &$item, bool $apply_lang_attribu array_key_exists('original_link', $item) && $item['original_link'] instanceof MenuLinkContent ) { - // MenuLinkContent::getEntity() has protected visibility and cannot be used - // to directly fetch the entity. - $metadata = $item['original_link']->getMetaData(); - - if (!empty($metadata['entity_id'])) { - $entity_type_manager = Drupal::entityTypeManager(); - $menu_link_content = $entity_type_manager - ->getStorage('menu_link_content') - ->load($metadata['entity_id']); + $menu_link_content = $item['original_link']->getEntity(); - // Add the possible lang attribute to menu item attributes. - if ( - !empty($menu_link_content) && - $menu_link_content->hasField('lang_attribute') && - !$menu_link_content->get('lang_attribute')->isEmpty() - ) { - $lang_attribute = $menu_link_content->get('lang_attribute')->value; - $item['attributes']->setAttribute('lang', $lang_attribute); - } + // Add the possible lang attribute to menu item attributes. + if ( + $menu_link_content->hasField('lang_attribute') && + !$menu_link_content->get('lang_attribute')->isEmpty() + ) { + $lang_attribute = $menu_link_content->get('lang_attribute')->value; + $item['attributes']->setAttribute('lang', $lang_attribute); } } } From f619eaecf20c250902c7206c431e4e8eb9885815 Mon Sep 17 00:00:00 2001 From: tuutti Date: Wed, 17 Apr 2024 17:45:14 +0300 Subject: [PATCH 03/11] UHF-9978: Updated action --- .github/workflows/visual.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/visual.yml b/.github/workflows/visual.yml index b13229348..e92cc68f8 100644 --- a/.github/workflows/visual.yml +++ b/.github/workflows/visual.yml @@ -134,7 +134,7 @@ jobs: run: docker compose logs app > /tmp/container.log - name: Deploy to PR preview - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 if: github.ref != 'refs/heads/main' with: github_token: ${{ secrets.GITHUB_TOKEN }} From 290f555202344390b8f9f59eebd7e42bc2dd123e Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 18 Apr 2024 08:18:10 +0300 Subject: [PATCH 04/11] UHF-9978: Updated comment action --- .github/workflows/visual.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/visual.yml b/.github/workflows/visual.yml index e92cc68f8..4382bccba 100644 --- a/.github/workflows/visual.yml +++ b/.github/workflows/visual.yml @@ -142,14 +142,11 @@ jobs: destination_dir: pull/${{github.event.number}} - name: Update comment - uses: hasura/comment-progress@v2.3.0 if: github.ref != 'refs/heads/main' + uses: thollander/actions-comment-pull-request@v2 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - repository: ${{ github.repository }} - number: ${{ github.event.number }} - id: deploy-preview - recreate: true + comment_tag: status + pr_number: ${{ github.event.number }} message: "${{join(steps.run-tests.outputs.*, ' ')}}" - name: Upload container logs From aa1323202197d3988d3fae980de6c3d038651b2b Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 18 Apr 2024 08:40:00 +0300 Subject: [PATCH 05/11] UHF-9978: Updated php version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50d09230f..848960229 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['8.1'] + php-versions: ['8.3'] container: image: ghcr.io/city-of-helsinki/drupal-php-docker:${{ matrix.php-versions }}-alpine steps: From ba2c4664a495264ee567c1da8fbc4999de9ba2c4 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 18 Apr 2024 08:49:48 +0300 Subject: [PATCH 06/11] UHF-9978: Fetch entire git history --- .github/workflows/visual.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/visual.yml b/.github/workflows/visual.yml index 4382bccba..5c24742e7 100644 --- a/.github/workflows/visual.yml +++ b/.github/workflows/visual.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 1 + fetch-depth: 0 - name: Set variables run: echo "DRUPAL_ROOT=$HOME/drupal" >> $GITHUB_ENV From 0da254209d66421c262dd00b66cc8dbc44fd9c76 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 18 Apr 2024 09:04:01 +0300 Subject: [PATCH 07/11] UHF-9978: Ignore renovate branches --- .github/workflows/visual.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/visual.yml b/.github/workflows/visual.yml index 5c24742e7..a43b9c4ea 100644 --- a/.github/workflows/visual.yml +++ b/.github/workflows/visual.yml @@ -1,6 +1,8 @@ on: pull_request: types: [opened, reopened, synchronize] + branches-ignore: + - 'renovate/**' push: branches: - main From 8fab52449920823fa705a83bf5801a7fae0295ae Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 18 Apr 2024 09:15:04 +0300 Subject: [PATCH 08/11] UHF-9978: Install redis --- .github/workflows/visual.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/visual.yml b/.github/workflows/visual.yml index a43b9c4ea..f6631234f 100644 --- a/.github/workflows/visual.yml +++ b/.github/workflows/visual.yml @@ -45,7 +45,7 @@ jobs: COMPOSER_MIRROR_PATH_REPOS: 1 run: | composer config repositories.5 path $GITHUB_WORKSPACE - composer require drupal/$THEME_NAME -W + composer require drupal/redis drupal/$THEME_NAME -W # We use COMPOSER_MIRROR_PATH_REPOS=1 to mirror local repository # instead of symlinking it to make sure the code is available inside # the app container. @@ -79,6 +79,7 @@ jobs: if: steps.drupal-cache.outputs.cache-hit != 'true' run: | docker compose exec app bash -c "drush si minimal -y" + docker compose exec app bash -c "drush en redis -y" docker compose exec app bash -c "drush en helfi_test_content -y" docker compose exec app bash -c "drush sql-dump --result-file=/app/public/sites/default/files/latest.sql" From 1fd6bfbbcdb01c929e44eda7ba39432bb2f1e302 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 18 Apr 2024 11:08:49 +0300 Subject: [PATCH 09/11] UHF-9956: Queue visual regression tests, skip draft pull requests --- .github/workflows/visual.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/visual.yml b/.github/workflows/visual.yml index f6631234f..88b8db201 100644 --- a/.github/workflows/visual.yml +++ b/.github/workflows/visual.yml @@ -1,6 +1,6 @@ on: pull_request: - types: [opened, reopened, synchronize] + types: [opened, reopened, synchronize, ready_for_review] branches-ignore: - 'renovate/**' push: @@ -9,7 +9,12 @@ on: env: SIMPLETEST_DB: mysql://drupal:drupal@db:3306/drupal name: Visual regression tests + +concurrency: + group: visual-regression + jobs: + if: github.event.pull_request.draft == false tests: runs-on: ubuntu-latest steps: From d345dd41fe3c690b72522014cf5bb4e0b23c31d2 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 18 Apr 2024 11:10:14 +0300 Subject: [PATCH 10/11] UHF-9956: Fixed action workflow --- .github/workflows/visual.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/visual.yml b/.github/workflows/visual.yml index 88b8db201..0efe94fb3 100644 --- a/.github/workflows/visual.yml +++ b/.github/workflows/visual.yml @@ -14,8 +14,8 @@ concurrency: group: visual-regression jobs: - if: github.event.pull_request.draft == false tests: + if: github.event.pull_request.draft == false runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 3a3ec6ae484c56fdfc5a84eeade2da9259a0b786 Mon Sep 17 00:00:00 2001 From: tuutti Date: Thu, 18 Apr 2024 11:20:29 +0300 Subject: [PATCH 11/11] UHF-9956: Group PR close action to same visual regression group --- .github/workflows/pr-close-cleanup.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pr-close-cleanup.yml b/.github/workflows/pr-close-cleanup.yml index 555254f6f..6b1e2013c 100644 --- a/.github/workflows/pr-close-cleanup.yml +++ b/.github/workflows/pr-close-cleanup.yml @@ -3,6 +3,9 @@ on: pull_request: types: [closed] +concurrency: + group: visual-regression + jobs: delete_folder: runs-on: ubuntu-latest