Skip to content

Commit

Permalink
Merge pull request #168 from localgovdrupal/2.x
Browse files Browse the repository at this point in the history
2.1.10 release
  • Loading branch information
finnlewis authored Jun 18, 2024
2 parents 6bc1557 + 9701f5b commit 70c73de
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 203 deletions.
206 changes: 6 additions & 200 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,205 +7,11 @@ on:
pull_request:
branches:
- '2.x'

env:
LOCALGOV_DRUPAL_PROJECT: localgovdrupal/localgov_guides
LOCALGOV_DRUPAL_PROJECT_PATH: web/modules/contrib/localgov_guides
workflow_dispatch:

jobs:

build:
name: Install LocalGov Drupal
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
localgov-version:
- '3.x'
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'

steps:

- name: Save git branch and git repo names to env if this is not a pull request
if: github.event_name != 'pull_request'
run: |
echo "GIT_BASE=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "HEAD_USER=localgovdrupal" >> $GITHUB_ENV
- name: Save git branch and git repo names to env if this is a pull request
if: github.event_name == 'pull_request'
run: |
echo "GIT_BASE=${GITHUB_BASE_REF}" >> $GITHUB_ENV
echo "GIT_BRANCH=${GITHUB_HEAD_REF}" >> $GITHUB_ENV
export HEAD="${{ github.event.pull_request.head.label }}"
echo "HEAD_USER=${HEAD%%:*}" >> $GITHUB_ENV
- name: Set composer branch reference for version branches
if: endsWith(github.ref, '.x')
run: echo "COMPOSER_REF=${GIT_BRANCH}-dev" >> $GITHUB_ENV

- name: Set composer branch reference for non-version branches
if: endsWith(github.ref, '.x') == false
run: echo "COMPOSER_REF=dev-${GIT_BRANCH}" >> $GITHUB_ENV

- name: Get the latest tagged release for branch version
run: |
LATEST_RELEASE=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/${GIT_BASE%'.x'} | grep -Po '(?<=refs/tags/)[^"]+' | tail -1)
if [ -z $LATEST_RELEASE ]; then LATEST_RELEASE=1; fi
echo "LATEST_RELEASE=${LATEST_RELEASE}" >> $GITHUB_ENV
- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Clone drupal_container
uses: actions/checkout@v2
with:
repository: localgovdrupal/drupal-container
ref: php${{ matrix.php-version }}

- name: Create LocalGov Drupal project
run: |
composer create-project --stability dev --no-install localgovdrupal/localgov-project ./html "${{ matrix.localgov-version }}"
composer --working-dir=./html require --no-install localgovdrupal/localgov:${{ matrix.localgov-version }}-dev
composer --working-dir=./html require --no-install drupal/core-recommended:${{ matrix.drupal-version }} drupal/core-composer-scaffold:${{ matrix.drupal-version }} drupal/core-project-message:${{ matrix.drupal-version }} drupal/core-dev:${{ matrix.drupal-version }}
composer --working-dir=./html install
- name: Obtain the test target using Composer
if: env.HEAD_USER == 'localgovdrupal'
run: |
composer --working-dir=html config repositories.1 vcs [email protected]:${LOCALGOV_DRUPAL_PROJECT}.git
composer global config github-oauth.github.com ${{ github.token }}
composer --working-dir=./html require --with-all-dependencies ${LOCALGOV_DRUPAL_PROJECT}:"${COMPOSER_REF} as ${LATEST_RELEASE}"
- name: Obtain the test target using Git
if: env.HEAD_USER != 'localgovdrupal'
uses: actions/checkout@v2
with:
path: ${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}

phpcs:
name: Coding standards checks
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
localgov-version:
- '3.x'
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Run coding standards checks
run: |
cd html
./bin/phpcs -p ${LOCALGOV_DRUPAL_PROJECT_PATH}
phpstan:
name: Deprecated code checks
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
localgov-version:
- '3.x'
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Run deprecated code checks
run: |
cd html
./bin/phpstan analyse -c ./phpstan.neon ${LOCALGOV_DRUPAL_PROJECT_PATH}
phpunit:
name: PHPUnit tests
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
localgov-version:
- '3.x'
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'

steps:

- name: Clone Drupal container
uses: actions/checkout@v2
with:
repository: localgovdrupal/drupal-container
ref: php${{ matrix.php-version }}

- name: Cached workspace
uses: actions/cache@v2
with:
path: ./html
key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }}
restore-keys: |
localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-
- name: Start Docker environment
run: docker-compose -f docker-compose.yml up -d

- name: Run PHPUnit tests
run: |
mkdir -p ./html/web/sites/simpletest && chmod 777 ./html/web/sites/simpletest
sed -i "s#http://localgov.lndo.site#http://drupal#" ./html/phpunit.xml.dist
docker exec -t drupal bash -c 'chown docker:docker -R /var/www/html'
docker exec -u docker -t drupal bash -c "cd /var/www/html && ./bin/paratest --processes=4 /var/www/html/${{ env.LOCALGOV_DRUPAL_PROJECT_PATH }}"
tests:
uses: localgovdrupal/localgov_shared_workflows/.github/workflows/[email protected]
with:
project: 'localgovdrupal/localgov_guides'
project_path: 'web/modules/contrib/localgov_guides'
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ id: node.localgov_guides_page.localgov_guides_parent
field_name: localgov_guides_parent
entity_type: node
bundle: localgov_guides_page
label: 'Parent page'
label: 'Guide parent page'
description: 'The guide overview page this guide page is part of.'
required: true
translatable: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ settings:
label: 'Guides prev next block'
provider: localgov_guides
label_display: '0'
show_title: true
visibility: { }
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ settings:
label: 'Guides prev next block'
provider: localgov_guides
label_display: '0'
show_title: true
visibility: { }
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ id: node.localgov_guides_overview.localgov_services_parent
field_name: localgov_services_parent
entity_type: node
bundle: localgov_guides_overview
label: 'Services: Parent'
label: 'Service parent page'
description: ''
required: false
translatable: true
Expand Down
2 changes: 1 addition & 1 deletion localgov_guides.module
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function localgov_guides_optional_fields_settings($services, $topics) {
'placeholder' => '',
'match_limit' => 10,
],
'weight' => 51,
'weight' => -1,
])->save();
}
if ($topics && !$form_display->getComponent('localgov_topics')) {
Expand Down
52 changes: 52 additions & 0 deletions src/Plugin/PreviewLinkAutopopulate/Guides.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Drupal\localgov_guides\Plugin\PreviewLinkAutopopulate;

use Drupal\node\NodeInterface;
use Drupal\preview_link\PreviewLinkAutopopulatePluginBase;

/**
* Auto-populate Guide preview links.
*
* @PreviewLinkAutopopulate(
* id = "localgov_guides",
* label = @Translation("Add all the pages for this guide"),
* description = @Translation("Add guide overview and page nodes to preview link."),
* supported_entities = {
* "node" = {
* "localgov_guides_overview",
* "localgov_guides_page",
* }
* },
* )
*/
class Guides extends PreviewLinkAutopopulatePluginBase {

/**
* {@inheritdoc}
*/
public function getPreviewEntities(): array {
$guide_nodes = [];

// Find guide overview.
$node = $this->getEntity();
if ($node->bundle() == 'localgov_guides_overview') {
$overview = $node;
}
elseif ($node->bundle() == 'localgov_guides_page') {
$overview = $node->get('localgov_guides_parent')->entity;
}
$guide_nodes[] = $overview;

// Find guide pages.
$guide_pages = $overview->get('localgov_guides_pages')->referencedEntities();
foreach ($guide_pages as $guide_page) {
if ($guide_page instanceof NodeInterface && $guide_page->access('view')) {
$guide_nodes[] = $guide_page;
}
}

return $guide_nodes;
}

}

0 comments on commit 70c73de

Please sign in to comment.