From c26fcb20aa40af992bcf5bb829e262e825a2a9c6 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Thu, 28 Sep 2023 15:11:20 -0700 Subject: [PATCH] Setup github actions and gitpod --- .circleci/config.yml | 112 ---------- .github/auto-label.json | 8 + .github/workflows/label.yml | 28 +++ .github/workflows/tests.yml | 211 ++++++++++++++++++ .gitpod.yml | 58 +++++ .gitpod/blt.yml | 25 +++ blt/ci.blt.yml | 6 +- .../{CircleCiCommands.php => CiCommands.php} | 10 +- composer.lock | 8 +- docroot/sites/settings/ci.settings.php | 54 ++--- .../sites/settings/default.local.settings.php | 7 +- tests/codeception.dist.yml | 10 + 12 files changed, 385 insertions(+), 152 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/auto-label.json create mode 100644 .github/workflows/label.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .gitpod.yml create mode 100644 .gitpod/blt.yml rename blt/src/Blt/Plugin/Commands/{CircleCiCommands.php => CiCommands.php} (87%) diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 10a6fbc..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,112 +0,0 @@ -version: 2 -# CircleCI integration with Drupal 8. - -# Reusable steps. - -## Add SSH Key -add_ssh: &add_ssh - add_ssh_keys: - fingerprints: - - "6f:84:bf:38:2c:c5:fe:25:46:14:94:54:f3:22:42:f5" - -## Add Known Hosts -add_known_hosts: &add_known_hosts - run: - name: Add SSH Known Hosts - command: | - ssh-keyscan svn-23450.prod.hosting.acquia.com >> ~/.ssh/known_hosts - ssh-keyscan stanfordgryphondev.ssh.prod.acquia-sites.com >> ~/.ssh/known_hosts - ssh-keyscan stanfordgryphonstg.ssh.prod.acquia-sites.com >> ~/.ssh/known_hosts - ssh-keyscan stanfordgryphon.ssh.prod.acquia-sites.com >> ~/.ssh/known_hosts - ssh-keyscan -t rsa,dsa github.com >> ~/.ssh/known_hosts - -## Defines the cache restoring mechanism. -restore_caches: &restore_caches - restore_cache: - # We use the composer.lock as a way to determine if we can cache our build. - keys: - - cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "composer.lock" }} - # fallback to using the latest cache if no exact match is found - - cache-{{ .Environment.CACHE_VERSION }}- - -## Defines the cache saving mechanism. -save_caches: &save_caches - save_cache: - paths: - - ./vendor - - ./docroot/modules/contrib - - ./docroot/modules/custom - - ./docroot/profiles/contrib - - ./docroot/profiles/custom - - ./docroot/themes/contrib - - ./docroot/themes/custom - - ./docroot/libraries - - ./docroot/core - key: cache-{{ .Environment.CACHE_VERSION }}-{{ checksum "composer.lock" }} - -## Defines images and working directory. -defaults: &defaults - docker: - - image: pookmish/drupal8ci:latest - - image: selenium/standalone-chrome:latest - - image: circleci/mysql:5.7 - environment: - MYSQL_DATABASE: drupal - MYSQL_USER: drupal - MYSQL_PASSWORD: drupal - MYSQL_ALLOW_EMPTY_PASSWORD: 1 - working_directory: /var/www/html - -vpge_codeception_acceptance: &vpge_codeception_acceptance - <<: *defaults - steps: - - checkout - - *restore_caches - - run: - name: Run Codeception Acceptance Tests - command: | - composer install --no-interaction - vendor/bin/blt blt:telemetry:disable --no-interaction - mkdir -p artifacts/_data - vendor/bin/blt circleci:drupal:install --profile=vpge_profile --no-interaction - vendor/bin/blt drupal:toggle:modules --no-interaction - vendor/bin/drush xmlsitemap-regenerate - vendor/bin/blt tests:codeception --test=vpge --no-interaction - - *save_caches - - store_test_results: - path: artifacts - - store_artifacts: - path: artifacts - -phpunit_coverage: &phpunit_coverage - <<: *defaults - steps: - - checkout - - *restore_caches - - run: - name: Run PHPUnit Coverage Tests - command: | - composer install --no-interaction - vendor/bin/blt blt:telemetry:disable --no-interaction - vendor/bin/blt circleci:drupal:setup --no-interaction - vendor/bin/blt tests:phpunit:coverage --no-interaction - - *save_caches - - store_test_results: - path: artifacts/phpunit - - store_artifacts: - path: artifacts/phpunit - -# Declare all of the jobs we should run. -jobs: - run-vpge-codeception-acceptance: - <<: *vpge_codeception_acceptance - run-phpunit-coverage: - <<: *phpunit_coverage - -# Declare a workflow that runs all of our jobs in parallel. -workflows: - version: 2 - tests: - jobs: - - run-vpge-codeception-acceptance - - run-phpunit-coverage diff --git a/.github/auto-label.json b/.github/auto-label.json new file mode 100644 index 0000000..e473f32 --- /dev/null +++ b/.github/auto-label.json @@ -0,0 +1,8 @@ +{ + "rules": { + "patch": ["*.info.yml"], + "frontend": ["*.js", "*.scss", "*.css", "*.twig", ".theme"], + "backend": ["*.php", "*.module"], + "ci": [".circleci", "blt", ".github"] + } +} diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml new file mode 100644 index 0000000..83cd5ef --- /dev/null +++ b/.github/workflows/label.yml @@ -0,0 +1,28 @@ +# This workflow will triage pull requests and apply a label based on the +# paths that are modified in the pull request. +# +# To use this workflow, you will need to set up a .github/labeler.yml +# file with configuration. For more information, see: +# https://github.com/actions/labeler/blob/master/README.md + +name: PR Labeler +on: + pull_request: + types: [opened, synchronize] +jobs: + pr-labeler: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: codelytv/pr-size-labeler@v1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + xs_max_size: '100' + s_max_size: '500' + m_max_size: '1000' + l_max_size: '3000' + fail_if_xl: 'false' + message_if_xl: '' + - uses: banyan/auto-label@1.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..0fc0b5b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,211 @@ +name: PHPUnit and Acceptance Tests +on: [push] +jobs: + phpunit: + name: PHPUnit Coverage Tests + runs-on: ubuntu-latest + env: + DRUPAL_DATABASE_NAME: drupal + DRUPAL_DATABASE_USERNAME: drupal + DRUPAL_DATABASE_PASSWORD: drupal + DRUPAL_DATABASE_HOST: mysql + container: + image: pookmish/drupal8ci:latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: drupal + MYSQL_USER: drupal + MYSQL_PASSWORD: drupal + MYSQL_ROOT_PASSWORD: drupal + ports: + - 33306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: + - uses: actions/checkout@v3 + - name: Restore Cache + uses: actions/cache@v3 + with: + path: | + vendor + docroot/core + docroot/libraries + docroot/modules/contrib + key: 1.x-${{ hashFiles('composer.json') }}-${{ hashFiles('composer.lock') }} + restore-keys: | + 1.x-${{ hashFiles('composer.json') }}-${{ hashFiles('composer.lock') }} + 1.x-${{ hashFiles('composer.json') }}- + 1.x- + - name: Run Unit Tests + env: + CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} + run: | + composer install -n + blt blt:telemetry:disable --no-interaction + blt tests:phpunit:coverage --no-interaction + - name: Save Test Results + uses: actions/upload-artifact@v3 + if: failure() + with: + name: unit-tests-results + path: $GITHUB_WORKSPACE/artifacts + acceptance: + name: Cardinal At Work Codeception Acceptance Tests + runs-on: ubuntu-latest + env: + DRUPAL_DATABASE_NAME: drupal + DRUPAL_DATABASE_USERNAME: drupal + DRUPAL_DATABASE_PASSWORD: drupal + DRUPAL_DATABASE_HOST: mysql + container: + image: pookmish/drupal8ci:latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: drupal + MYSQL_USER: drupal + MYSQL_PASSWORD: drupal + MYSQL_ROOT_PASSWORD: drupal + ports: + - 33306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: + - uses: actions/checkout@v3 + - name: Restore Cache + uses: actions/cache@v3 + with: + path: | + vendor + docroot/core + docroot/libraries + docroot/modules/contrib + key: 1.x-${{ hashFiles('composer.json') }}-${{ hashFiles('composer.lock') }} + restore-keys: | + 1.x-${{ hashFiles('composer.json') }}-${{ hashFiles('composer.lock') }} + 1.x-${{ hashFiles('composer.json') }}- + 1.x- + - name: Run tests + run: | + rm -rf /var/www/html + ln -snf $GITHUB_WORKSPACE /var/www/html + apachectl stop + apachectl start + composer install -n + blt blt:telemetry:disable --no-interaction + mysql -h mysql -P 3306 -u root -pdrupal -e 'SET GLOBAL max_allowed_packet=67108864;' + blt gryphon-ci:drupal:install --profile=vpge_profile --no-interaction + blt drupal:install -n + drush role:perm:add anonymous 'access content' + drush xmlsitemap:rebuild + blt codeception --suite=acceptance + - name: Save Test Results + uses: actions/upload-artifact@v3 + if: always() + with: + name: acceptance-tests-results + path: artifacts + functional: + name: Cardinal At Work Codeception Functional Tests + runs-on: ubuntu-latest + env: + DRUPAL_DATABASE_NAME: drupal + DRUPAL_DATABASE_USERNAME: drupal + DRUPAL_DATABASE_PASSWORD: drupal + DRUPAL_DATABASE_HOST: mysql + container: + image: pookmish/drupal8ci:latest + options: '--network-alias drupal8ci' + services: + selenium: + image: selenium/standalone-chrome:115.0 + options: '--shm-size="2g"' + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: drupal + MYSQL_USER: drupal + MYSQL_PASSWORD: drupal + MYSQL_ROOT_PASSWORD: drupal + ports: + - 33306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: + - uses: actions/checkout@v3 + - name: Restore Cache + uses: actions/cache@v3 + with: + path: | + vendor + docroot/core + docroot/libraries + docroot/modules/contrib + docroot/modules/custom + key: 1.x-${{ hashFiles('composer.json') }}-${{ hashFiles('composer.lock') }} + restore-keys: | + 1.x-${{ hashFiles('composer.json') }}-${{ hashFiles('composer.lock') }} + 1.x-${{ hashFiles('composer.json') }}- + 1.x- + - name: Install Site + run: | + rm -rf /var/www/html + ln -snf $GITHUB_WORKSPACE /var/www/html + apachectl stop + apachectl start + composer install -n + blt blt:telemetry:disable --no-interaction + mysql -h mysql -P 3306 -u root -pdrupal -e 'SET GLOBAL max_allowed_packet=67108864;' + blt gryphon-ci:drupal:install --profile=vpge_profile --no-interaction + drush role:perm:add anonymous 'access content' + drush xmlsitemap:rebuild + mkdir -p artifacts/_data/ + - name: Run tests + run: blt codeception --suite=functional + - name: Save Test Results + uses: actions/upload-artifact@v3 + if: always() + with: + name: functional-tests-results + path: artifacts +# deploy: +# name: Deploy Artifact +# needs: [phpunit, acceptance, functional] +# runs-on: ubuntu-latest +# env: +# DRUPAL_DATABASE_NAME: drupal +# DRUPAL_DATABASE_USERNAME: drupal +# DRUPAL_DATABASE_PASSWORD: drupal +# DRUPAL_DATABASE_HOST: mysql +# container: +# image: pookmish/drupal8ci:latest +# steps: +# - uses: actions/checkout@v3 +# - name: Restore Cache +# uses: actions/cache@v3 +# with: +# path: | +# vendor +# docroot/core +# docroot/libraries +# docroot/modules/contrib +# key: 1.x-${{ hashFiles('composer.json') }}-${{ hashFiles('composer.lock') }} +# restore-keys: | +# 1.x-${{ hashFiles('composer.json') }}-${{ hashFiles('composer.lock') }} +# 1.x-${{ hashFiles('composer.json') }}- +# 1.x- +# - name: Deploy Artifact +# env: +# SSH_KEY: ${{secrets.SSH_KEY}} +# run: | +# mkdir -p ~/.ssh +# echo $SSH_KEY | base64 -d > ~/.ssh/id_rsa +# chmod 600 ~/.ssh/id_rsa +# eval `ssh-agent -s` +# ssh-add ~/.ssh/id_rsa +# ssh-keyscan svn-23450.prod.hosting.acquia.com > ~/.ssh/known_hosts +# git config --global user.email "sws-developers@lists.stanford.edu" +# git config --global user.name "Github Actions" +# composer install -n +# blt blt:telemetry:disable --no-interaction +# blt deploy -v -n diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..0b78289 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,58 @@ +github: + prebuilds: + master: true + branches: true + pullRequests: true + pullRequestsFromForks: false + addCheck: false + addComment: false + addBadge: false +additionalRepositories: + - url: https://github.com/SU-SWS/vpge_profile + checkoutLocation: vpge_profile +ports: + - port: 3306 + onOpen: ignore + visibility: private + - port: 33060 + onOpen: ignore + visibility: private + - port: 8001 + onOpen: open-preview + visibility: public +image: pookmish/drupal8ci:gitpod +tasks: + - before: > + eval $(command gp env -e) && + mkdir -p ~/.ssh && + [[ ! -z $SSH_PUBLIC_KEY ]] && + echo $SSH_PUBLIC_KEY | base64 -d > ~/.ssh/id_rsa.pub && + chmod 644 ~/.ssh/id_rsa.pub && + [[ ! -z $SSH_PRIVATE_KEY ]] && + echo $SSH_PRIVATE_KEY | base64 -d > ~/.ssh/id_rsa && + chmod 600 ~/.ssh/id_rsa && + [[ ! -z $GITCONFIG ]] && + echo $GITCONFIG | base64 -d > ~/.gitconfig && + chmod 644 ~/.gitconfig + init: > + export PREVIEW_FULL_URL=`gp url 8001` && + export PREVIEW_URL=${PREVIEW_FULL_URL#"https://"} && + composer update --no-interaction && + rm -rf docroot/*/custom/* && + composer install --prefer-source --no-interaction && + cd docroot/profiles/custom/vpge_profile && + git remote set-url origin git@github.com:SU-SWS/vpge_profile.git && + cd $GITPOD_REPO_ROOT && + cp .gitpod/blt.yml blt/local.blt.yml && + mkdir -p docroot/sites/settings && + find docroot/sites/ -name 'local*' | xargs rm -rf && + blt blt:telemetry:disable --no-interaction && + blt settings && + blt drupal:install -n + command: | + apache2ctl restart + drush uli + drush uli | xargs gp preview --external + git config core.fileMode false + blt blt:telemetry:disable --no-interaction + git remote set-url origin git@github.com:SU-SWS/ace-vpgegryphon.git diff --git a/.gitpod/blt.yml b/.gitpod/blt.yml new file mode 100644 index 0000000..7ccae82 --- /dev/null +++ b/.gitpod/blt.yml @@ -0,0 +1,25 @@ +# Override any settings as necessary by copying to local.blt.yml +#project: +# local: +# protocol: http +# hostname: mysite.dev + +# You can set custom project aliases in drush/sites/*.site.yml. +# All local:* targets are run against drush.aliases.local. +#drush: +# aliases: +# local: local.mysite.dev + +drupal: + account: + mail: sws-developers@lists.stanford.edu + db: + port: 3306 + host: localhost + username: root + password: '' + database: 'drupal' +project: + local: + protocol: https + hostname: '${env.PREVIEW_URL}' diff --git a/blt/ci.blt.yml b/blt/ci.blt.yml index adaf924..0afe7af 100644 --- a/blt/ci.blt.yml +++ b/blt/ci.blt.yml @@ -19,8 +19,8 @@ project: drupal: db: - host: 127.0.0.1 + host: mysql port: 3306 - username: root - password: '' + username: drupal + password: drupal database: drupal diff --git a/blt/src/Blt/Plugin/Commands/CircleCiCommands.php b/blt/src/Blt/Plugin/Commands/CiCommands.php similarity index 87% rename from blt/src/Blt/Plugin/Commands/CircleCiCommands.php rename to blt/src/Blt/Plugin/Commands/CiCommands.php index 25855f2..37650bc 100644 --- a/blt/src/Blt/Plugin/Commands/CircleCiCommands.php +++ b/blt/src/Blt/Plugin/Commands/CiCommands.php @@ -8,17 +8,15 @@ /** * Class GryphonCommands. */ -class CircleCiCommands extends BltTasks { +class CiCommands extends BltTasks { /** * Setup the directory with drupal settings files. * - * @command circleci:drupal:setup + * @command gryphon-ci:drupal:setup */ public function setupDrupal() { $root = $this->getConfigValue('repo.root'); - $tasks[] = $this->taskExec('dockerize -wait tcp://localhost:3306 -timeout 1m'); - $tasks[] = $this->taskExec('apachectl stop; apachectl start'); // Cleanup any local or remnant files. $files = glob("$root/docroot/sites/*/local.*"); @@ -45,11 +43,11 @@ public function setupDrupal() { * * @throws \Acquia\Blt\Robo\Exceptions\BltException * - * @command circleci:drupal:install + * @command gryphon-ci:drupal:install * @options profile Specify which profile to install. */ public function installDrupal(array $options = ['profile' => NULL]) { - $this->invokeCommand('circleci:drupal:setup'); + $this->invokeCommand('gryphon-ci:drupal:setup'); if ($options['profile']) { $root = $this->getConfigValue('repo.root'); diff --git a/composer.lock b/composer.lock index b2127bf..b3ff183 100644 --- a/composer.lock +++ b/composer.lock @@ -20202,12 +20202,12 @@ "source": { "type": "git", "url": "https://github.com/SU-SWS/vpge_profile.git", - "reference": "ff5916762df7a256e16a6d4fddf15323c0ea53d4" + "reference": "594de8c282c05f220acc4ed58397bfbad4ea3488" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/SU-SWS/vpge_profile/zipball/ff5916762df7a256e16a6d4fddf15323c0ea53d4", - "reference": "ff5916762df7a256e16a6d4fddf15323c0ea53d4", + "url": "https://api.github.com/repos/SU-SWS/vpge_profile/zipball/594de8c282c05f220acc4ed58397bfbad4ea3488", + "reference": "594de8c282c05f220acc4ed58397bfbad4ea3488", "shasum": "" }, "require": { @@ -20377,7 +20377,7 @@ "support": { "source": "https://github.com/SU-SWS/vpge_profile/tree/10.x" }, - "time": "2023-09-28T04:50:01+00:00" + "time": "2023-09-28T21:56:31+00:00" }, { "name": "symfony-cmf/routing", diff --git a/docroot/sites/settings/ci.settings.php b/docroot/sites/settings/ci.settings.php index a903085..6bb867b 100755 --- a/docroot/sites/settings/ci.settings.php +++ b/docroot/sites/settings/ci.settings.php @@ -10,22 +10,22 @@ /** * Database configuration. */ -$databases = array( +$databases = [ 'default' => - array( - 'default' => - array( - 'database' => $db_name, - 'username' => 'root', - 'password' => '', - 'host' => '127.0.0.1', - 'port' => '3306', - 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', - 'driver' => 'mysql', - 'prefix' => '', - ), - ), -); + [ + 'default' => + [ + 'database' => $db_name, + 'username' => 'drupal', + 'password' => 'drupal', + 'host' => 'mysql', + 'port' => '3306', + 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', + 'driver' => 'mysql', + 'prefix' => '', + ], + ], +]; $dir = dirname(DRUPAL_ROOT); @@ -48,6 +48,7 @@ assert_options(ASSERT_ACTIVE, TRUE); assert_options(ASSERT_EXCEPTION, TRUE); + /** * Show all error messages, with backtrace information. * @@ -96,16 +97,17 @@ /** * Configure static caches. * - * Note: you should test with the config, bootstrap, and discovery caches enabled to - * test that metadata is cached as expected. However, in the early stages of development, - * you may want to disable them. Overrides to these bins must be explicitly set for each - * bin to change the default configuration provided by Drupal core in core.services.yml. - * See https://www.drupal.org/node/2754947 + * Note: you should test with the config, bootstrap, and discovery caches + * enabled to test that metadata is cached as expected. However, in the early + * stages of development, you may want to disable them. Overrides to these bins + * must be explicitly set for each bin to change the default configuration + * provided by Drupal core in core.services.yml. See + * https://www.drupal.org/node/2754947 */ - // $settings['cache']['bins']['bootstrap'] = 'cache.backend.null'; - // $settings['cache']['bins']['discovery'] = 'cache.backend.null'; - // $settings['cache']['bins']['config'] = 'cache.backend.null'; +// $settings['cache']['bins']['bootstrap'] = 'cache.backend.null'; +// $settings['cache']['bins']['discovery'] = 'cache.backend.null'; +// $settings['cache']['bins']['config'] = 'cache.backend.null'; /** @@ -157,6 +159,8 @@ * * See full description in default.settings.php. */ -$settings['trusted_host_patterns'] = array( +$settings['trusted_host_patterns'] = [ '^.+$', -); +]; + +error_reporting(E_ALL & ~E_DEPRECATED); diff --git a/docroot/sites/settings/default.local.settings.php b/docroot/sites/settings/default.local.settings.php index 85abffc..c7f0439 100644 --- a/docroot/sites/settings/default.local.settings.php +++ b/docroot/sites/settings/default.local.settings.php @@ -7,6 +7,11 @@ * The settings in this file will be applied to every multisites. */ +error_reporting(E_ALL & ~E_DEPRECATED); +if (PHP_SAPI !== 'cli') { + ini_set('memory_limit', '256M'); +} + /** * SAMLAuth configuration */ @@ -20,8 +25,6 @@ 'key' => DRUPAL_ROOT . '/../keys/workgroup_api.key', ]; -error_reporting(E_ALL & ~E_DEPRECATED); - // Saml login doesn't work on gitpod or tugboat, don't set config values. if (getenv('GITPOD_WORKSPACE_URL') || getenv('TUGBOAT_REPO')) { unset($config['samlauth.authentication']); diff --git a/tests/codeception.dist.yml b/tests/codeception.dist.yml index 20c2968..47e4962 100644 --- a/tests/codeception.dist.yml +++ b/tests/codeception.dist.yml @@ -43,3 +43,13 @@ modules: cleanup_test: true cleanup_failed: false cleanup_suite: true +env: + ci: + modules: + config: + WebDriver: + url: 'http://drupal8ci/' + browser: chrome + host: selenium + port: 4444 + restart: true