-
Notifications
You must be signed in to change notification settings - Fork 8
184 lines (151 loc) · 7.14 KB
/
coding-standards.yml
File metadata and controls
184 lines (151 loc) · 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Coding Standards
# When to run tests.
on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- main
jobs:
dependabot-metadata:
# Name.
name: Dependabot Metadata
# Virtual Environment to use.
# @see: https://github.com/actions/virtual-environments
runs-on: ubuntu-latest
# Don't run if the PR is not from Dependabot.
if: github.actor == 'dependabot[bot]'
# Outputs.
outputs:
package-ecosystem: ${{ steps.metadata.outputs.package-ecosystem }}
# Steps to fetch Dependabot metadata.
steps:
- name: Fetch Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v3
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
tests:
# Name.
name: Coding Standards / WordPress ${{ matrix.wp-versions }} / PHP ${{ matrix.php-versions }}
# Virtual Environment to use.
# @see: https://github.com/actions/virtual-environments
runs-on: ubuntu-latest
# Requieres the dependabot-metadata job to have run successfully.
needs: [dependabot-metadata]
# Always allow non-Dependabot PRs and pushes.
# For Dependabot PRs, only run when the update is for composer (skip github-actions updates).
if: |
always() &&
(
github.actor != 'dependabot[bot]' ||
needs.dependabot-metadata.outputs.package-ecosystem == 'composer'
)
# 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: /home/runner/work/convertkit-wordpress/convertkit-wordpress/wordpress
PLUGIN_DIR: /home/runner/work/convertkit-wordpress/convertkit-wordpress/wordpress/wp-content/plugins/convertkit
DB_NAME: test
DB_USER: root
DB_PASS: root
DB_HOST: localhost
INSTALL_PLUGINS: "classic-editor contact-form-7 elementor forminator woocommerce wordpress-seo litespeed-cache w3-total-cache" # Don't include this repository's Plugin here.
# Defines the WordPress and PHP Versions matrix to run tests on.
strategy:
matrix:
wp-versions: [ 'latest' ] #[ '6.1.1', 'latest' ]
php-versions: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ] #[ '7.3', '7.4', '8.0', '8.1' ]
# Steps to install, configure and run tests
steps:
- 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 WordPress
run: wget https://wordpress.org/wordpress-${{ matrix.wp-versions }}.tar.gz
- name: Extract WordPress
run: tar xfz wordpress-${{ matrix.wp-versions }}.tar.gz
# Checkout (copy) this repository's Plugin to this VM.
- name: Checkout Plugin
uses: actions/checkout@v6
with:
path: ${{ env.PLUGIN_DIR }}
# This step is deliberate, to force PHP 7.4 for WP-CLI to work.
# PHP 8.x results in the workflow failing due to incompatibilities between WP-CLI and PHP 8.x.
- name: Install PHP 7.4.26
uses: shivammathur/setup-php@v2
with:
php-version: 7.4.26
coverage: xdebug
# 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 --admin_email=wordpress@convertkit.local
# 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 }}
# These should be stored as a separated list of URLs in the repository Settings > Secrets > Repository Secret > CONVERTKIT_PAID_PLUGIN_URLS.
# We cannot include the URLs in this file, as they're not Plugins we are permitted to distribute.
- name: Install and Activate Paid Third Party WordPress Plugins
working-directory: ${{ env.ROOT_DIR }}
run: wp-cli plugin install ${{ secrets.CONVERTKIT_PAID_PLUGIN_URLS }} --activate
# Install PHP version to run tests against.
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
tools: cs2pr
# 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
# Installs WordPress scripts for CSS and JS Coding Standards.
- name: Run npm install
working-directory: ${{ env.PLUGIN_DIR }}
run: npm install
# Run PHP Coding Standards on Tests.
- name: Run WordPress PHP Coding Standards on Tests
working-directory: ${{ env.PLUGIN_DIR }}
if: ${{ contains('8.1 8.2 8.3 8.4', matrix.php-versions) }}
run: php vendor/bin/phpcs -q --standard=phpcs.tests.xml --report=checkstyle ./tests | cs2pr
# Run PHP Coding Standards on Plugin.
- name: Run WordPress PHP Coding Standards
working-directory: ${{ env.PLUGIN_DIR }}
run: php vendor/bin/phpcs -q --standard=phpcs.xml --report=checkstyle ./ | cs2pr
# Run CSS Coding Standards on Plugin.
- name: Run WordPress CSS Coding Standards
working-directory: ${{ env.PLUGIN_DIR }}
run: npm run lint:css
# Run JS Coding Standards on Plugin.
- name: Run WordPress JS Coding Standards
working-directory: ${{ env.PLUGIN_DIR }}
run: npm run lint:js
# Run PHPStan for static analysis.
- name: Run PHPStan Static Analysis
working-directory: ${{ env.PLUGIN_DIR }}
run: php vendor/bin/phpstan analyse --memory-limit=1250M