Skip to content

Commit

Permalink
Merge pull request #398 from City-of-Helsinki/UHF-11137
Browse files Browse the repository at this point in the history
UHF-11137: Reusable workflows
  • Loading branch information
hyrsky authored Dec 20, 2024
2 parents ec7ff3c + 7f9f481 commit 49fc75c
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 241 deletions.
35 changes: 1 addition & 34 deletions .github/workflows/artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,4 @@ on:
name: Build artifacts
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install and start Stonehenge
run: |
git clone -b 5.x https://github.com/druidfi/stonehenge.git ~/stonehenge
cd ~/stonehenge && make up
# This must be done after we start Stonehenge.
- name: Setup Docker compose environment variables
run: |
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV
- name: Start project
run: make up

- name: Build project
run: docker compose exec app bash -c "composer install --no-interaction"

- name: Setup drupal and save database dump
run: |
docker compose exec app bash -c "drush si -y && drush cr"
docker compose exec app bash -c "drush si --existing-config -y"
docker compose exec app bash -c "drush cr"
docker compose exec app bash -c "drush cim -y"
docker compose exec app bash -c "drush sql-dump --result-file=/app/latest.sql"
- name: Upload latest database dump
uses: actions/upload-artifact@v4
with:
name: latest.sql
path: latest.sql
retention-days: 10
uses: city-of-helsinki/drupal-gh-actions/.github/workflows/build-artifact.yml@main
80 changes: 3 additions & 77 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,80 +5,6 @@ on:
name: CI
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# TODO: This check does not pass.
#- name: Make sure configuration was exported in correct language (en or und)
# run: |
# OUTPUT=$(grep -oP '^langcode: \b(?!(?:en|und)\b)\w+' conf -R || true)

# if [ ! -z "$OUTPUT" ]; then
# echo "Found configuration that does not match the pattern 'langcode: (en|und)':" >> $GITHUB_STEP_SUMMARY
# echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY
# exit 1
# fi

- name: Install and start Stonehenge
run: |
git clone -b 5.x https://github.com/druidfi/stonehenge.git ~/stonehenge
cd ~/stonehenge && make up
# This must be done after we start Stonehenge.
- name: Setup Docker compose environment variables
run: |
echo "COMPOSE_FILE=compose.yaml:compose.ci.yaml" >> $GITHUB_ENV
echo "COMPOSE_PROFILES=" >> $GITHUB_ENV
- name: Start project
run: make up

- name: Build project
run: docker compose exec app bash -c "composer install --no-interaction"

- name: Scan security updates
run: docker compose exec app bash -c "composer audit"

- name: Check that subtheme is not built with dev mode
run: docker compose exec app bash -c "if grep -q 'sourceMappingURL=' -R public/themes/custom/hdbt_subtheme/dist/css; then exit 1; fi"

# TODO: This check does not pass.
#- name: Run PHPCS
# run: |
# docker compose exec app bash -c "vendor/bin/phpcs public/modules/custom/"
# docker compose exec app bash -c "vendor/bin/phpcs public/themes/custom/"

- name: Run phpstan
run: docker compose exec app bash -c "vendor/bin/phpstan analyze"

- name: Download latest dump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh run download -n latest.sql

- name: Install Drupal
run: |
docker compose exec app bash -c "mysql --user=drupal --password=drupal --database=drupal --host=db --port=3306 -A < latest.sql"
docker compose exec app bash -c "drush deploy"
- name: Run PHPUnit tests
run: |
docker compose exec app bash -c "mkdir -p /app/results"
if [ -d "tests/" ]; then
docker compose exec app bash -c "composer test-php tests/"
fi
docker compose exec app bash -c "composer test-php public/modules/custom"
- name: Export logs
if: always()
run: docker compose logs app > results/service.log

- name: Create an artifact from test report
uses: actions/upload-artifact@v4
if: always()
with:
name: results
path: results/
retention-days: 1
uses: city-of-helsinki/drupal-gh-actions/.github/workflows/project-tests.yml@main
with:
check_config_language: false
104 changes: 3 additions & 101 deletions .github/workflows/update-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,106 +3,8 @@ on:
repository_dispatch:
types: [config_change]
name: Update config
env:
GH_TOKEN: ${{ github.token }}
jobs:
update-config:
runs-on: ubuntu-latest
container:
image: ghcr.io/city-of-helsinki/drupal-web:8.3
options: --hostname app --user 1001
services:
db:
image: mysql:8
env:
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: drupal
ports:
- 3306:3306

steps:
- uses: actions/checkout@v4

- name: Check if required secrets are set
env:
AUTOMATIC_UPDATE_TOKEN: ${{ secrets.AUTOMATIC_UPDATE_TOKEN }}
if: env.AUTOMATIC_UPDATE_TOKEN == ''
run: exit 1

- name: Download latest dump
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh run download -n latest.sql
- name: Prepare setup
run: |
# We install Drupal from existing dump, so locale_install() hook
# is never fired. Make sure the translations folder exists.
mkdir -p public/sites/default/files/translations -p
- name: Build project
run: |
composer install --no-interaction
$(drush sql:connect) < latest.sql
drush cim -y && drush updb -y && drush cr
composer update drupal/helfi_* drupal/hdbt* -W --no-interaction
drush cr
# Update translations from localize.drupal.org and helfi-modules
# before running update hooks to reduce clutter in configuration files.
drush locale:check && drush locale:update
drush updb -y
# Update translations from helfi_platform_config. These translations
# consists of overrides for non customised translations and will
# override current translation with a non customised translation.
drush helfi:locale-import helfi_platform_config
drush cex -y
# Update platform
drush helfi:tools:update-platform
- name: Check module versions
id: module-status
run: |
MODE="delete"
drush helfi:tools:check-composer-versions $GITHUB_WORKSPACE/composer.lock --format=markdown_table >> $GITHUB_STEP_SUMMARY && EXIT_CODE=$? || EXIT_CODE=$?
if [ "$EXIT_CODE" -eq 3 ]; then
MODE="upsert"
echo " " >> $GITHUB_STEP_SUMMARY
echo ":warning: Failed to install the latest version of the packages listed above" >> $GITHUB_STEP_SUMMARY
echo " " >> $GITHUB_STEP_SUMMARY
echo "Please run \`composer why-not drupal/package_name package_version\` to see why." >> $GITHUB_STEP_SUMMARY
fi
echo "MODE=$MODE" >> $GITHUB_OUTPUT
cat $GITHUB_STEP_SUMMARY > /tmp/pr-message.txt
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit-message: Update configuration
token: ${{ secrets.AUTOMATIC_UPDATE_TOKEN }}
title: Automatic update
labels: auto-update
body: |
- Updated active configuration.
- Updated platform
branch: update-configuration

- name: Attempt to find PR
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
id: find-pr
run: echo "number=$(gh pr list --base ${BRANCH_NAME} --head update-configuration --json number --jq '.[].number')" >> $GITHUB_OUTPUT

- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
if: ${{ steps.find-pr.outputs.number != '' }}
with:
comment_tag: status
mode: ${{ steps.module-status.outputs.MODE }}
filePath: /tmp/pr-message.txt
pr_number: ${{ steps.find-pr.outputs.number }}
uses: city-of-helsinki/drupal-gh-actions/.github/workflows/update-config.yml@main
secrets:
automatic_update_token: ${{ secrets.AUTOMATIC_UPDATE_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Admin tools.
*/

declare(strict_types=1);

use Drupal\Core\Entity\ContentEntityInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Drupal\infofinland_admin_tools\Controller;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Custom module for checking broken links.
*/

declare(strict_types=1);

/**
* Implements hook_cron().
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Drupal\infofinland_brokenlink_checker\Plugin\QueueWorker;

use Drupal\Core\Entity\EntityTypeManagerInterface;
Expand All @@ -8,8 +10,6 @@
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\Logger\LoggerChannelInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\InvalidArgumentException;

/**
* Save queue item in a node.
Expand Down Expand Up @@ -100,39 +100,38 @@ public function processItem($response) {

try {
$code = $this->checkUrlStatus($response->field_language_link_value);
} catch (\Exception $e) {
}
catch (\Exception $e) {
$logger_params['@message'] = $e->getMessage();
// This happens for example following reasons,
// cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
// This happens for example following reasons,
// cURL error 28: Operation timed out after 30001 milliseconds with 0
// bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
// If this happens, the broken link status gets an empty value.
$this->logger->warning('Checking cURL status failed: parent_id: @parent_id , id: @id , url: @url - @message ', $logger_params);
return;
}

if ($code === 200 || $code === 301 || $code === 302 || $code === 303) {
if ($linkNode = $this->entityTypeManager->getStorage('node')->load($response->parent_id)) {
$linkNode->set('field_broken_link', false);
$linkNode->set('field_broken_link', FALSE);
$linkNode->save();
}

if ($languageLinkParagraph = $this->entityTypeManager->getStorage('paragraph')->load($response->id)) {
$languageLinkParagraph->set('field_broken_link', false);
$languageLinkParagraph->set('field_broken_link', FALSE);
$languageLinkParagraph->save();
}

// $logger_params['@code'] = $code;
// $this->logger->warning('Checking URL status passed: parent_id: @parent_id , id: @id , url: @url - code: @code ', $logger_params);
}
else {
if ($linkNode = $this->entityTypeManager->getStorage('node')->load($response->parent_id)) {
$linkNode->set('field_broken_link', true);
$linkNode->set('field_broken_link', TRUE);
$linkNode->save();
}

if ($languageLinkParagraph = $this->entityTypeManager->getStorage('paragraph')->load($response->id)) {
$languageLinkParagraph->set('field_broken_link', true);
$languageLinkParagraph->set('field_broken_link', TRUE);
$languageLinkParagraph->save();
}
}

$logger_params['@code'] = $code;
$this->logger->warning('Checking URL status failed: parent_id: @parent_id , id: @id , url: @url - code: @code ', $logger_params);
Expand All @@ -146,6 +145,7 @@ public function processItem($response) {
* The url.
*
* @return int
* The status code.
*/
private function checkUrlStatus(string $url): int {
$response = $this->httpClient->get($url, [
Expand All @@ -162,4 +162,5 @@ private function checkUrlStatus(string $url): int {

return $response->getStatusCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function infofinland_common_update_9005(): void {
}

/**
* Remove webform submissions from database;
* Remove webform submissions from database.
*/
function infofinland_common_update_9006(): void {
$storage_handler = \Drupal::entityTypeManager()
Expand All @@ -133,7 +133,6 @@ function infofinland_common_update_9006(): void {
$storage_handler->delete($ids);
}


/**
* Update ownership of broken nodes. Removed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ function _infofinland_common_add_paragraphs_to_node_translations(EntityInterface

$item_to_queue = [
'nid' => $entity->id(),
'data' => json_encode($added_paragraphs)
'data' => json_encode($added_paragraphs),
];

/** @var \Drupal\Core\Queue\QueueFactoryInterface $queue_factory */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Token integration for the Infofinland common module.
*/

declare(strict_types=1);

use Drupal\Core\Render\BubbleableMetadata;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Drupal\infofinland_common\Commands;

use Drupal\Core\Entity\EntityTypeManagerInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Drupal\infofinland_common\Controller;

use Drupal\Core\Access\AccessResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Drupal\infofinland_common\Controller;

use Drupal\simple_oauth\Controller\Oauth2Token;
Expand Down
Loading

0 comments on commit 49fc75c

Please sign in to comment.