1.3.7 #249
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run Tests | |
| # When to run tests. | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| tests: | |
| # Name. | |
| name: ${{ matrix.test-groups }} / WordPress ${{ matrix.wp-versions }} / PHP ${{ matrix.php-versions }} | |
| # Virtual Environment to use. | |
| # @see: https://github.com/actions/virtual-environments | |
| runs-on: ubuntu-latest | |
| # Environment Variables. | |
| # Accessible by using ${{ env.NAME }} | |
| # Use ${{ secrets.NAME }} to include any GitHub Secrets in ${{ env.NAME }} | |
| # The base folder will always be /home/runner/work/github-repo-name/github-repo-name | |
| env: | |
| ROOT_DIR: /var/www/html | |
| PLUGIN_DIR: /var/www/html/wp-content/plugins/convertkit-membermouse | |
| DB_NAME: test | |
| DB_USER: root | |
| DB_PASS: root | |
| DB_HOST: localhost | |
| INSTALL_PLUGINS: "https://hub.membermouse.com/download.php" # Don't include this repository's Plugin here. | |
| CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }} # ConvertKit API Key, stored in the repository's Settings > Secrets | |
| CONVERTKIT_API_SECRET: ${{ secrets.CONVERTKIT_API_SECRET }} # ConvertKit API Secret, stored in the repository's Settings > Secrets | |
| CONVERTKIT_API_KEY_NO_DATA: ${{ secrets.CONVERTKIT_API_KEY_NO_DATA }} # ConvertKit API Key for ConvertKit account with no data, stored in the repository's Settings > Secrets | |
| CONVERTKIT_API_SECRET_NO_DATA: ${{ secrets.CONVERTKIT_API_SECRET_NO_DATA }} # ConvertKit API Secret for ConvertKit account with no data, stored in the repository's Settings > Secrets | |
| CONVERTKIT_OAUTH_CLIENT_ID: ${{ secrets.CONVERTKIT_OAUTH_CLIENT_ID }} | |
| CONVERTKIT_OAUTH_REDIRECT_URI: ${{ secrets.CONVERTKIT_OAUTH_REDIRECT_URI }} | |
| KIT_OAUTH_REDIRECT_URI: ${{ secrets.KIT_OAUTH_REDIRECT_URI }} | |
| # Defines the WordPress and PHP Versions matrix to run tests on | |
| # WooCommerce 5.9.0 requires WordPress 5.6 or greater, so we do not test on earlier versions | |
| # If testing older WordPress versions, ensure they are e.g. 5.7.4, 5.6.6 that have the X3 SSL fix: https://core.trac.wordpress.org/ticket/54207 | |
| # For PHP, make sure that an nginx configuration file exists for the required PHP version in this repository at tests/nginx/php-x.x.conf | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| wp-versions: [ 'latest' ] #[ '6.1.1', 'latest' ] | |
| php-versions: [ '8.1', '8.2', '8.3', '8.4' ] #[ '7.3', '7.4', '8.0', '8.1' ] | |
| # Folder names within the 'tests' folder to run tests in parallel. | |
| test-groups: [ | |
| 'EndToEnd/bundle', | |
| 'EndToEnd/general', | |
| 'EndToEnd/member', | |
| 'EndToEnd/member-update', | |
| 'EndToEnd/product', | |
| 'Integration' | |
| ] | |
| # Steps to install, configure and run tests | |
| steps: | |
| - name: Define Test Group Name | |
| id: test-group | |
| uses: mad9000/actions-find-and-replace-string@5 | |
| with: | |
| source: ${{ matrix.test-groups }} | |
| find: '/' | |
| replace: '-' | |
| replaceAll: true | |
| # Checkout Plugin to /home/runner/work/convertkit-membermouse/convertkit-membermouse/convertkit-membermouse | |
| # We cannot checkout to ${{ env.PLUGIN_DIR }} as GitHub Actions require it be first placed in /home/runner/work/repo/repo | |
| - name: Checkout Plugin | |
| uses: actions/checkout@v4 | |
| with: | |
| path: /home/runner/work/convertkit-membermouse/convertkit-membermouse/convertkit-membermouse | |
| - name: Start MySQL | |
| run: sudo systemctl start mysql.service | |
| - name: Create MySQL Database | |
| run: | | |
| mysql -e 'CREATE DATABASE test;' -u${{ env.DB_USER }} -p${{ env.DB_PASS }} | |
| mysql -e 'SHOW DATABASES;' -u${{ env.DB_USER }} -p${{ env.DB_PASS }} | |
| # WordPress won't be able to connect to the DB if we don't perform this step. | |
| - name: Permit MySQL Password Auth for MySQL 8.0 | |
| run: mysql -e "ALTER USER '${{ env.DB_USER }}'@'${{ env.DB_HOST }}' IDENTIFIED WITH mysql_native_password BY '${{ env.DB_PASS }}';" -u${{ env.DB_USER }} -p${{ env.DB_PASS }} | |
| # Some workflows checkout WordPress from GitHub, but that seems to bring a bunch of uncompiled files with it. | |
| # Instead download from wordpress.org stable. | |
| - name: Download and Extract WordPress | |
| run: | | |
| sudo chown -R runner:docker /var/www/html | |
| ls -la /var/www/html | |
| cd /var/www/html | |
| wget https://wordpress.org/wordpress-${{ matrix.wp-versions }}.tar.gz | |
| tar xfz wordpress-${{ matrix.wp-versions }}.tar.gz | |
| mv wordpress/* . | |
| rm -rf wordpress wordpress-${{ matrix.wp-versions }}.tar.gz | |
| # We install WP-CLI, as it provides useful commands to setup and install WordPress through the command line. | |
| - name: Install WP-CLI | |
| run: | | |
| curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | |
| chmod +x wp-cli.phar | |
| sudo mv wp-cli.phar /usr/local/bin/wp-cli | |
| - name: Setup wp-config.php | |
| working-directory: ${{ env.ROOT_DIR }} | |
| run: wp-cli config create --dbname=${{ env.DB_NAME }} --dbuser=${{ env.DB_USER }} --dbpass=${{ env.DB_PASS }} --dbhost=${{ env.DB_HOST }} --locale=en_DB | |
| - name: Install WordPress | |
| working-directory: ${{ env.ROOT_DIR }} | |
| run: wp-cli core install --url=127.0.0.1 --title=ConvertKit --admin_user=admin --admin_password=password [email protected] | |
| # env.INSTALL_PLUGINS is a list of Plugin slugs, space separated e.g. contact-form-7 woocommerce. | |
| - name: Install Free Third Party WordPress Plugins | |
| working-directory: ${{ env.ROOT_DIR }} | |
| run: wp-cli plugin install ${{ env.INSTALL_PLUGINS }} | |
| # Move Plugin | |
| - name: Move Plugin | |
| run: mv /home/runner/work/convertkit-membermouse/convertkit-membermouse/convertkit-membermouse ${{ env.PLUGIN_DIR }} | |
| # WP_DEBUG = true is required so all PHP errors are output and caught by tests (E_ALL). | |
| # WP_DEBUG = false for PHP 8.4, otherwise E_DEPRECATED is output due to MemberMouse. | |
| - name: Enable WP_DEBUG | |
| if: ${{ matrix.test-groups != 'EndToEnd/member-update' && matrix.php-versions != '8.4' }} | |
| working-directory: ${{ env.ROOT_DIR }} | |
| run: | | |
| wp-cli config set WP_DEBUG true --raw | |
| # FS_METHOD = direct is required for WP_Filesystem to operate without suppressed PHP fopen() errors that trip up tests. | |
| - name: Enable FS_METHOD | |
| working-directory: ${{ env.ROOT_DIR }} | |
| run: | | |
| wp-cli config set FS_METHOD direct | |
| # This step is deliberately after WordPress installation and configuration, as enabling PHP 8.x before using WP-CLI results | |
| # in the workflow failing due to incompatibilities between WP-CLI and PHP 8.x. | |
| # By installing PHP at this stage, we can still run our tests against e.g. PHP 8.x. | |
| - name: Install PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php-versions }} | |
| coverage: xdebug | |
| # Configure nginx to use the PHP version and WOrdPress installation at /var/www/html | |
| - name: Configure nginx site | |
| run: | | |
| sudo rm -f /etc/nginx/sites-enabled/default | |
| sudo tee /etc/nginx/sites-available/default > /dev/null << 'EOF' | |
| server { | |
| listen 80 default_server; | |
| listen [::]:80 default_server; | |
| root /var/www/html; | |
| index index.php; | |
| server_name localhost; | |
| location / { | |
| try_files $uri $uri/ /index.php?$args; | |
| } | |
| location ~ \.php$ { | |
| include snippets/fastcgi-php.conf; | |
| fastcgi_pass unix:/run/php/php${{ matrix.php-versions }}-fpm.sock; | |
| # Prevent 502 Bad Gateway error "upstream sent too big header while reading response header from upstream" | |
| fastcgi_buffers 16 16k; | |
| fastcgi_buffer_size 32k; | |
| fastcgi_busy_buffers_size 64k; | |
| } | |
| location ~ /\.ht { | |
| deny all; | |
| } | |
| } | |
| EOF | |
| sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default || true | |
| - name: Test nginx | |
| run: sudo nginx -t | |
| - name: Start nginx | |
| run: sudo systemctl start nginx.service | |
| - name: Install chromedriver | |
| uses: nanasess/setup-chromedriver@master | |
| - name: Start chromedriver | |
| run: | | |
| export DISPLAY=:99 | |
| chromedriver --port=9515 --url-base=/wd/hub & | |
| sudo Xvfb -ac :99 -screen 0 1920x1080x24 > /dev/null 2>&1 & # optional | |
| # Exchange API Keys and Secrets for OAuth Tokens. | |
| - name: Exchange API Key and Secret for OAuth Tokens | |
| id: get-oauth-tokens | |
| run: | | |
| response=$(curl -s -X POST "${{ secrets.CONVERTKIT_EXCHANGE_API_KEYS_ENDPOINT }}?api_key=${{ env.CONVERTKIT_API_KEY }}&api_secret=${{ env.CONVERTKIT_API_SECRET }}&client_id=${{ env.CONVERTKIT_OAUTH_CLIENT_ID }}&redirect_uri=${{ env.CONVERTKIT_OAUTH_REDIRECT_URI }}&tenant_name=github-actions-${{ steps.test-group.outputs.value }}-${{ matrix.php-versions }}") | |
| access_token=$(echo "$response" | jq -r '.oauth.access_token') | |
| refresh_token=$(echo "$response" | jq -r '.oauth.refresh_token') | |
| echo "CONVERTKIT_OAUTH_ACCESS_TOKEN=$access_token" >> $GITHUB_ENV | |
| echo "CONVERTKIT_OAUTH_REFRESH_TOKEN=$refresh_token" >> $GITHUB_ENV | |
| response=$(curl -s -X POST "${{ secrets.CONVERTKIT_EXCHANGE_API_KEYS_ENDPOINT }}?api_key=${{ env.CONVERTKIT_API_KEY_NO_DATA }}&api_secret=${{ env.CONVERTKIT_API_SECRET_NO_DATA }}&client_id=${{ env.CONVERTKIT_OAUTH_CLIENT_ID }}&redirect_uri=${{ env.CONVERTKIT_OAUTH_REDIRECT_URI }}&tenant_name=github-actions-${{ steps.test-group.outputs.value }}-${{ matrix.php-versions }}") | |
| access_token=$(echo "$response" | jq -r '.oauth.access_token') | |
| refresh_token=$(echo "$response" | jq -r '.oauth.refresh_token') | |
| echo "CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA=$access_token" >> $GITHUB_ENV | |
| echo "CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA=$refresh_token" >> $GITHUB_ENV | |
| # Write any secrets, such as API keys, to the .env.testing file now. | |
| - name: Define GitHub Secrets in .env.testing | |
| uses: DamianReeves/[email protected] | |
| with: | |
| path: ${{ env.PLUGIN_DIR }}/.env.testing | |
| contents: | | |
| CONVERTKIT_API_KEY=${{ env.CONVERTKIT_API_KEY }} | |
| CONVERTKIT_API_SECRET=${{ env.CONVERTKIT_API_SECRET }} | |
| CONVERTKIT_API_KEY_NO_DATA=${{ env.CONVERTKIT_API_KEY_NO_DATA }} | |
| CONVERTKIT_API_SECRET_NO_DATA=${{ env.CONVERTKIT_API_SECRET_NO_DATA }} | |
| CONVERTKIT_OAUTH_ACCESS_TOKEN=${{ env.CONVERTKIT_OAUTH_ACCESS_TOKEN }} | |
| CONVERTKIT_OAUTH_REFRESH_TOKEN=${{ env.CONVERTKIT_OAUTH_REFRESH_TOKEN }} | |
| CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA=${{ env.CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA }} | |
| CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA=${{ env.CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA }} | |
| CONVERTKIT_OAUTH_CLIENT_ID=${{ env.CONVERTKIT_OAUTH_CLIENT_ID }} | |
| CONVERTKIT_OAUTH_REDIRECT_URI=${{ env.CONVERTKIT_OAUTH_REDIRECT_URI }} | |
| KIT_OAUTH_REDIRECT_URI=${{ env.KIT_OAUTH_REDIRECT_URI }} | |
| write-mode: overwrite | |
| # Installs wp-browser, Codeception, PHP CodeSniffer and anything else needed to run tests. | |
| - name: Run Composer | |
| working-directory: ${{ env.PLUGIN_DIR }} | |
| run: composer update | |
| - name: Build PHP Autoloader | |
| working-directory: ${{ env.PLUGIN_DIR }} | |
| run: composer dump-autoload | |
| # This ensures that applicable files and folders can be written to by WordPress and cache Plugins. | |
| - name: Set File and Folder Permissions | |
| run: | | |
| sudo chmod 767 ${{ env.ROOT_DIR }} | |
| sudo chown www-data:www-data ${{ env.ROOT_DIR }} | |
| sudo chmod 767 ${{ env.ROOT_DIR }}/wp-config.php | |
| sudo chown www-data:www-data ${{ env.ROOT_DIR }}/wp-config.php | |
| sudo chmod 767 ${{ env.ROOT_DIR }}/wp-content | |
| sudo chown www-data:www-data ${{ env.ROOT_DIR }}/wp-content | |
| sudo chmod -R 767 ${{ env.ROOT_DIR }}/wp-content/uploads | |
| sudo chown www-data:www-data ${{ env.ROOT_DIR }}/wp-content/uploads | |
| # This ensures the Plugin's log file can be written to. | |
| # We don't recursively do this, as it'll prevent Codeception from writing to the /tests/_output directory. | |
| - name: Set Permissions for Plugin Directory | |
| run: | | |
| sudo chmod g+w ${{ env.PLUGIN_DIR }} | |
| sudo chown www-data:www-data ${{ env.PLUGIN_DIR }} | |
| # Build Codeception Tests. | |
| - name: Build Tests | |
| working-directory: ${{ env.PLUGIN_DIR }} | |
| run: php vendor/bin/codecept build | |
| # Run Codeception Acceptance Tests. | |
| - name: Run tests/${{ matrix.test-groups }} | |
| working-directory: ${{ env.PLUGIN_DIR }} | |
| run: php vendor/bin/codecept run tests/${{ matrix.test-groups }} --fail-fast | |
| # Artifacts are data generated by this workflow that we want to access, such as log files, screenshots, HTML output. | |
| # The if: failure() directive means that this will run when the workflow fails e.g. if a test fails, which is needed | |
| # because we want to see why a test failed. | |
| - name: Upload nginx Error Log to Artifact | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nginx-error-log-${{ steps.test-group.outputs.value }}-${{ matrix.php-versions }}.log | |
| path: /var/log/nginx/error.log | |
| - name: Upload Test Results to Artifact | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-${{ steps.test-group.outputs.value }}-${{ matrix.php-versions }} | |
| path: ${{ env.PLUGIN_DIR }}/tests/_output/ | |
| - name: Upload Plugin Log File to Artifact | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: log-${{ steps.test-group.outputs.value }}-${{ matrix.php-versions }}.txt | |
| path: ${{ env.PLUGIN_DIR }}/log/log.txt |