From 6994197ad67300ce66a64664bb4f04c1a1ad4582 Mon Sep 17 00:00:00 2001 From: Kyle Taylor Date: Tue, 8 Mar 2022 15:59:51 -0600 Subject: [PATCH] [CMS-319] Add Github Actions support (#107) * Add Github Actions support - Convert TravisCI to Github Actions - Convert PHAR generation to use Box - Remove (now) unused prep scripts - Add release workflow (WIP) * Remove unused TravisCI / CircleCI config, remove console output * Update description * Add release workflow * Testing release * Add release asset * Try new changelog action --- .github/workflows/release.yml | 134 ++++++++++++++++++++++++++ .github/workflows/validate.yml | 86 +++++++++++++++++ .travis.yml | 45 --------- .wp_launch_check.stub | 12 +++ bin/install-package-tests.sh | 30 ------ bin/prepare.sh | 3 - box.json | 12 +++ circle.yml | 10 -- composer.json | 29 +++--- features/bootstrap/FeatureContext.php | 12 ++- features/config.feature | 18 ++-- php/commands/launchcheck.php | 37 ++++--- 12 files changed, 294 insertions(+), 134 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/validate.yml delete mode 100644 .travis.yml create mode 100644 .wp_launch_check.stub delete mode 100755 bin/install-package-tests.sh delete mode 100755 bin/prepare.sh create mode 100644 box.json delete mode 100644 circle.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e138fb4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,134 @@ +name: Deploy and Release +on: + push: + tags: ["v[0-9]+.[0-9]+.[0-9]+*"] + +jobs: + validate: + name: "Run validation test suite" + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ["7.2", "7.3", "7.4"] + env: + # GITHUB_CONTEXT: ${{ toJson(github) }} + PANTHEON_WPVULNDB_API_TOKEN: ${{ secrets.PANTHEON_WPVULNDB_API_TOKEN }} + WP_CLI_BIN_DIR: /tmp/wp-cli-phar + DB_NAME: pantheon + DB_USER: pantheon + DB_PASSWORD: pantheon + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: ${{ env.DB_NAME }} + MYSQL_HOST: 127.0.0.1 + MYSQL_USER: ${{ env.DB_USER }} + MYSQL_PASSWORD: ${{ env.DB_PASSWORD }} + MYSQL_ROOT_PASSWORD: rootpass + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + ini-values: post_max_size=256M, max_execution_time=120 + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache Composer Downloads + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Cache PHP dependencies + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }} + + - name: Install composer dependencies + run: | + composer --no-interaction --no-progress --prefer-dist install + + - name: Install WP-CLI + run: | + # The Behat test suite will pick up the executable found in $WP_CLI_BIN_DIR + mkdir -p $WP_CLI_BIN_DIR + curl -s https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > $WP_CLI_BIN_DIR/wp + chmod +x $WP_CLI_BIN_DIR/wp + + - name: Generate Phar + run: | + php -dphar.readonly=0 vendor/bin/box build -v + + - name: Run Behat tests + run: | + vendor/bin/behat --ansi + + - name: Archive phar + uses: actions/upload-artifact@v2 + with: + name: wp-launch-check-phar + path: wp_launch_check.phar + retention-days: 5 + + deploy-packages: + name: Deploy + runs-on: ubuntu-latest + needs: [validate] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Download Phar + uses: actions/download-artifact@v2 + with: + name: wp-launch-check-phar + + - name: Generate changelog + id: changelog + uses: metcalfc/changelog-generator@v1.0.0 + with: + myToken: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Release + id: create_release + uses: actions/create-release@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: | + ${{ steps.changelog.outputs.changelog }} + draft: false + prerelease: false + + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./wp_launch_check.phar + asset_name: wp_launch_check.phar + asset_content_type: application/zip diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..99df796 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,86 @@ +name: Behat tests +on: + pull_request: + branches: + - master + - main + +jobs: + validate: + name: "Run validation test suite" + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ["7.2", "7.3", "7.4"] + env: + # GITHUB_CONTEXT: ${{ toJson(github) }} + PANTHEON_WPVULNDB_API_TOKEN: ${{ secrets.PANTHEON_WPVULNDB_API_TOKEN }} + WP_CLI_BIN_DIR: /tmp/wp-cli-phar + DB_NAME: pantheon + DB_USER: pantheon + DB_PASSWORD: pantheon + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: ${{ env.DB_NAME }} + MYSQL_HOST: 127.0.0.1 + MYSQL_USER: ${{ env.DB_USER }} + MYSQL_PASSWORD: ${{ env.DB_PASSWORD }} + MYSQL_ROOT_PASSWORD: rootpass + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + ini-values: post_max_size=256M, max_execution_time=120 + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache Composer Downloads + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Cache PHP dependencies + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }} + + - name: Install composer dependencies + run: | + composer --no-interaction --no-progress --prefer-dist install + + - name: Install WP-CLI + run: | + # The Behat test suite will pick up the executable found in $WP_CLI_BIN_DIR + mkdir -p $WP_CLI_BIN_DIR + curl -s https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > $WP_CLI_BIN_DIR/wp + chmod +x $WP_CLI_BIN_DIR/wp + + - name: Generate Phar + run: | + php -dphar.readonly=0 vendor/bin/box build -v + + - name: Run Behat tests + run: | + vendor/bin/behat --ansi diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8232e81..0000000 --- a/.travis.yml +++ /dev/null @@ -1,45 +0,0 @@ -language: php -php: - - 7.4 - - 7.3 - - 7.2 -services: - - mysql -os: linux -notifications: - email: - on_success: never - on_failure: change - -branches: - only: - - master - - "/^v[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+.*$/" - -cache: - - composer - - "$HOME/.composer/cache" - -env: - global: - - WP_CLI_BIN_DIR=/tmp/wp-cli-phar - - PANTHEON_WPVULNDB_API_TOKEN=NI7BJgWm40MppXU3MedPTqsc9O3W6urSkClOcacagzM - - secure: qVuABE9laRLFk+2J5pJjmJI6YmRqEEailCvkwiN0Gqx+68KaB2t64djEnVYxWo2nxzZE7jZ0cNabQxd1mvFOWAZAvCetlKmLBfO8qoBsfMtqimWprSUA3fXqqXJ9YDmscK/zeOzM0cbnD7HbJ+bB7Zl6zHcjzTD019PD8FT3iDc= - -before_script: - - bash bin/install-package-tests.sh - - composer install - -script: "./vendor/bin/behat --ansi" - -before_deploy: - - bash bin/prepare.sh - -deploy: - provider: releases - token: - secure: mF9U4mO+B+lJKqK6rqom/nOlsLHDRlBVgVIQxUuO4xCPuygD1eer8Hfkvqo58tpsPWF24Iqek4NyFTZ7dY78vmhVUPCxS/nq/+6A0Dyg3uqFYK5F+Sn60e46ZATSOJVDlKTr62ZR04dq0tjrFBwXfNXqv9RMQGjaOVD/U+tKTsw= - file: wp_launch_check.phar - on: - repo: pantheon-systems/wp_launch_check - tags: true diff --git a/.wp_launch_check.stub b/.wp_launch_check.stub new file mode 100644 index 0000000..655683d --- /dev/null +++ b/.wp_launch_check.stub @@ -0,0 +1,12 @@ + diff --git a/bin/install-package-tests.sh b/bin/install-package-tests.sh deleted file mode 100755 index ed53897..0000000 --- a/bin/install-package-tests.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -PACKAGE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" - -download() { - if [ `which curl` ]; then - curl -s "$1" > "$2"; - elif [ `which wget` ]; then - wget -nv -O "$2" "$1" - fi -} - -install_wp_cli() { - - # the Behat test suite will pick up the executable found in $WP_CLI_BIN_DIR - mkdir -p $WP_CLI_BIN_DIR - download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar $WP_CLI_BIN_DIR/wp - chmod +x $WP_CLI_BIN_DIR/wp - -} - -install_db() { - mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot - mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"localhost" IDENTIFIED BY "password1"' -uroot -} - -install_wp_cli -install_db diff --git a/bin/prepare.sh b/bin/prepare.sh deleted file mode 100755 index 5f3acb1..0000000 --- a/bin/prepare.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -php -dphar.readonly=0 utils/make-phar.php diff --git a/box.json b/box.json new file mode 100644 index 0000000..0a4bb63 --- /dev/null +++ b/box.json @@ -0,0 +1,12 @@ +{ + "main": "php/commands/launchcheck.php", + "output": "wp_launch_check.phar", + "finder": [ + { + "name": "*.php", + "exclude": ["test", "tests", "Tests"], + "in": "php" + } + ], + "stub": ".wp_launch_check.stub" +} diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 64e7230..0000000 --- a/circle.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: 2 -jobs: - build: - working_directory: ~/pantheon-systems/wp_launch_check - parallelism: 1 - docker: - - image: circleci/php:7.1 - steps: - - checkout - - run: echo 'No tests to run' diff --git a/composer.json b/composer.json index 3269d84..d001d5e 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,17 @@ { - "name": "pantheon-systems/wp_launch_check", - "description": "Check against a WordPress for performance and security", - "type": "wp-cli-package", - "license": "MIT", - "authors": [], - "minimum-stability": "dev", - "autoload": { - "files": [ "php/commands/launchcheck.php" ] - }, - "require": {}, - "require-dev": { - "symfony/finder": "~2.3", - "behat/behat": "~2.5" - } + "name": "pantheon-systems/wp_launch_check", + "description": "Performs performance and security checks for WordPress.", + "type": "wp-cli-package", + "license": "MIT", + "authors": [], + "minimum-stability": "stable", + "autoload": { + "files": [ + "php/commands/launchcheck.php" + ] + }, + "require-dev": { + "humbug/box": "^2", + "behat/behat": "^2" + } } diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index 236957c..26aab1f 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -1,7 +1,6 @@ autoload->files ) ) { @@ -48,9 +52,9 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface { private static $cache_dir, $suite_cache_dir; private static $db_settings = array( - 'dbname' => 'wp_cli_test', - 'dbuser' => 'wp_cli_test', - 'dbpass' => 'password1', + 'dbname' => 'pantheon', + 'dbuser' => 'pantheon', + 'dbpass' => 'pantheon', 'dbhost' => '127.0.0.1', ); diff --git a/features/config.feature b/features/config.feature index 3689062..9199a30 100644 --- a/features/config.feature +++ b/features/config.feature @@ -34,13 +34,13 @@ Feature: Check the wp-config.php file ] + * + * [--format=] * : use to output json * * @when before_wp_load @@ -67,12 +66,12 @@ function config($args, $assoc_args) { /** * Checks the cron - * + * * ## OPTIONS - * - * [--format=] + * + * [--format=] * : use to output json - * + * */ function cron($args, $assoc_args) { $checker = new \Pantheon\Checker(); @@ -81,15 +80,15 @@ function cron($args, $assoc_args) { $format = isset($assoc_args['format']) ? $assoc_args['format'] : 'raw'; \Pantheon\Messenger::emit($format); } - + /** * Check database for potential issues - * + * * ## OPTIONS - * - * [--format=] + * + * [--format=] * : use to output json - * + * */ function database($args, $assoc_args) { $checker = new \Pantheon\Checker(); @@ -101,12 +100,12 @@ function database($args, $assoc_args) { /** * Checks for best practice - * + * * ## OPTIONS - * - * [--format=] + * + * [--format=] * : use to output json - * + * */ function general($args, $assoc_args) { $checker = new \Pantheon\Checker();