Skip to content

Commit 90afc23

Browse files
authored
Merge pull request #1026 from Kit/github-action-build-css-js
GitHub Actions: Build CSS and JS
2 parents a0eec54 + 885e29f commit 90afc23

13 files changed

Lines changed: 130 additions & 20 deletions

File tree

61.3 KB
Loading

.github/workflows/deploy.yml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,39 @@ jobs:
2626
- name: Run Composer
2727
run: composer install --no-dev
2828

29-
# Confirm that expected files exist, to prevent deployment to wordpress.org
30-
# if e.g. composer install fails.
31-
- name: Check ConvertKit Library Exists
32-
id: check_files
33-
uses: andstor/file-existence-action@v1
34-
with:
35-
files: "vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-traits.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-v4.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-log.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-resource-v4.php, vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-review-request.php"
29+
# Build the frontend CSS and JS assets
30+
- name: Run npm
31+
run: |
32+
npm install
33+
npm run build
34+
35+
# Confirm that expected files exist
36+
# if e.g. `composer install` or `npm run build` fails
37+
- name: Check Kit WordPress Libraries and Assets Exists
38+
working-directory: ${{ env.PLUGIN_DIR }}
39+
run: |
40+
set -e
41+
42+
files=(
43+
"resources/frontend/css/frontend.css"
44+
"resources/frontend/js/dist/frontend.min.asset.php"
45+
"resources/frontend/js/dist/frontend.min.js"
46+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-traits.php"
47+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-v4.php"
48+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-log.php"
49+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-resource-v4.php"
50+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-review-request.php"
51+
)
52+
53+
for file in "${files[@]}"; do
54+
echo "Checking: $file"
55+
test -f "$file" || { echo "❌ Missing required file: $file"; exit 1; }
56+
done
57+
58+
echo "✅ All required files exist."
3659
3760
# Deploy to wordpress.org, if expected files exist.
3861
- name: WordPress Plugin Deploy
39-
if: steps.check_files.outputs.files_exists == 'true'
4062
id: deploy
4163
uses: 10up/action-wordpress-plugin-deploy@stable
4264
with:

.github/workflows/tests-backward-compat.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,38 @@ jobs:
270270
working-directory: ${{ env.PLUGIN_DIR }}
271271
run: composer update
272272

273+
# Build the frontend CSS and JS assets
274+
- name: Run npm
275+
working-directory: ${{ env.PLUGIN_DIR }}
276+
run: |
277+
npm install
278+
npm run build
279+
280+
# Confirm that expected files exist
281+
# if e.g. `composer install` or `npm run build` fails
282+
- name: Check Kit WordPress Libraries and Assets Exists
283+
working-directory: ${{ env.PLUGIN_DIR }}
284+
run: |
285+
set -e
286+
287+
files=(
288+
"resources/frontend/css/frontend.css"
289+
"resources/frontend/js/dist/frontend.min.asset.php"
290+
"resources/frontend/js/dist/frontend.min.js"
291+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-traits.php"
292+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-v4.php"
293+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-log.php"
294+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-resource-v4.php"
295+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-review-request.php"
296+
)
297+
298+
for file in "${files[@]}"; do
299+
echo "Checking: $file"
300+
test -f "$file" || { echo "❌ Missing required file: $file"; exit 1; }
301+
done
302+
303+
echo "✅ All required files exist."
304+
273305
- name: Build PHP Autoloader
274306
working-directory: ${{ env.PLUGIN_DIR }}
275307
run: composer dump-autoload

.github/workflows/tests.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,38 @@ jobs:
292292
working-directory: ${{ env.PLUGIN_DIR }}
293293
run: composer update
294294

295+
# Build the frontend CSS and JS assets
296+
- name: Run npm
297+
working-directory: ${{ env.PLUGIN_DIR }}
298+
run: |
299+
npm install
300+
npm run build
301+
302+
# Confirm that expected files exist
303+
# if e.g. `composer install` or `npm run build` fails
304+
- name: Check Kit WordPress Libraries and Assets Exists
305+
working-directory: ${{ env.PLUGIN_DIR }}
306+
run: |
307+
set -e
308+
309+
files=(
310+
"resources/frontend/css/frontend.css"
311+
"resources/frontend/js/dist/frontend.min.asset.php"
312+
"resources/frontend/js/dist/frontend.min.js"
313+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-traits.php"
314+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-api-v4.php"
315+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-log.php"
316+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-resource-v4.php"
317+
"vendor/convertkit/convertkit-wordpress-libraries/src/class-convertkit-review-request.php"
318+
)
319+
320+
for file in "${files[@]}"; do
321+
echo "Checking: $file"
322+
test -f "$file" || { echo "❌ Missing required file: $file"; exit 1; }
323+
done
324+
325+
echo "✅ All required files exist."
326+
295327
- name: Build PHP Autoloader
296328
working-directory: ${{ env.PLUGIN_DIR }}
297329
run: composer dump-autoload
@@ -396,6 +428,12 @@ jobs:
396428
- name: Run Composer
397429
run: composer install --no-dev
398430

431+
# Build the frontend CSS and JS assets.
432+
- name: Run npm
433+
run: |
434+
npm install
435+
npm run build
436+
399437
# Configure AWS Credentials
400438
- name: Configure AWS credentials
401439
id: credentials
@@ -408,7 +446,7 @@ jobs:
408446
# Create ZIP file
409447
- name: Create ZIP File
410448
run: |
411-
zip -r ${{ env.PLUGIN_SLUG }}.zip . -x ".git/*" ".github/*" ".scripts/*" ".wordpress-org/*" "log/*" "tests/*" "*.md" "*.yml" "*.json" "*.neon" "*.lock" "*.xml" "*.dist" "*.example" "*.testing" "vendor/convertkit/convertkit-wordpress-libraries/.git/*"
449+
zip -r ${{ env.PLUGIN_SLUG }}.zip . -x ".git/*" ".github/*" ".scripts/*" ".wordpress-org/*" "log/*" "node_modules/*" "tests/*" "*.md" "*.yml" "*.json" "*.neon" "*.lock" "*.xml" "*.dist" ".eslintrc.js" "*.example" "*.testing" "vendor/convertkit/convertkit-wordpress-libraries/.git/*"
412450
413451
# Exchange API Keys and Secrets for OAuth Tokens.
414452
- name: Exchange API Key and Secret for OAuth Tokens

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ log.txt
88
package-lock.json
99
phpstan.neon
1010
node_modules
11-
resources/frontend/css/*.map
11+
resources/frontend/css/
12+
resources/frontend/js/dist/
1213
tests/_output
1314
tests/_wordpress
1415
tests/Support/_generated

DEVELOPMENT.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ Typically, packages listed in this section would be internal development tools f
6060
- PHPStan
6161
- Codeception
6262

63-
### Build
64-
65-
Run `npm run build` to compile frontend CSS and JS in one step.
66-
6763
### CSS
6864

6965
Run `npm run watch:css` to compile frontend CSS to `resources/frontend/css/frontend.css` when working on SCSS in the `resources/frontend/scss` folder.
@@ -72,6 +68,22 @@ Run `npm run watch:css` to compile frontend CSS to `resources/frontend/css/front
7268

7369
Run `npm run watch:js` to compile frontend JS to `resources/frontend/js/dist/frontend-min.js` when working on JS in the `resources/frontend/js` folder.
7470

71+
### Build
72+
73+
Run `npm run build` to:
74+
- fix CSS to WordPress Coding Standards (`npm run fix:css`)
75+
- lint CSS to check WordPress Coding Standards met after any fixes (`npm run lint:css`)
76+
- fix JS to WordPress Coding Standards (`npm run fix:js`)
77+
- lint JS to check WordPress Coding Standards met after any fixes (`npm run lint:js`)
78+
- compile frontend CSS from `resources/frontend/scss` to `resources/frontend/css/frontend.css` (`npm run build:css`)
79+
- compile frontend JS from `resources/frontend/js` to `resources/frontend/js/dist` (`npm run build:js`)
80+
81+
If the build process fails, review the terminal and make applicable changes:
82+
83+
![npm run build errors](/.github/docs/npm-run-build-errors.png?raw=true)
84+
85+
GitHub actions will run this step for you on testing and deployment, but it's a useful command in development if you need a single command to cover CSS + JS.
86+
7587
## Committing Work
7688

7789
Remember to commit your changes to your branch relatively frequently, with a meaningful, short summary that explains what the change(s) do.

SETUP.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ This sets up:
9797
- JS compilation and minification
9898
- SASS compilation and minification
9999

100+
### Build JS and CSS
101+
102+
Run `npm run build` to build the frontend CSS and JS.
103+
100104
### Configure wp-config.php
101105

102106
In the root of your WordPress installation, find the `wp-config.php` file.

TESTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The following Composer commands can be used:
3434
| `composer fix-js-coding-standards` | `composer fix-js` | Fixes JS files to meet WordPress JS Coding Standards |
3535
| `composer build-js` | `composer build-js` | Builds the frontend JS file |
3636
| `composer watch-js` | `composer watch-js` | Builds the frontend JS file when changes are made to frontend JS files |
37-
| `composer build` | `composer build` | Builds frontend CSS and JS |
37+
| `composer build` | `composer build` | Fixes, lints and builds frontend CSS and JS |
3838
| `composer static-analysis` | `composer phpstan` | Runs PHPStan static analysis with increased memory limit |
3939
| `composer test` | `composer test` | Builds and runs end-to-end tests with `fail-fast` enabled |
4040
| `composer test-integration` | `composer test-integration` | Builds and runs integration tests with `fail-fast` enabled |
@@ -47,7 +47,7 @@ The following npm commands can be used, if preferred:
4747
| `npm run watch:css` | Builds the frontend CSS file when changes are made to SCSS files |
4848
| `npm run build:js` | Builds the frontend JS file |
4949
| `npm run watch:js` | Builds the frontend JS file when changes are made to frontend JS files |
50-
| `npm run build` | Builds frontend CSS and JS |
50+
| `npm run build` | Fixes, lints and builds frontend CSS and JS |
5151

5252
## Write (or modify) a test
5353

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"lint-js": "npm run lint:js",
3737
"fix-js": "npm run fix:js",
3838
"build": [
39+
"npm run fix:css",
40+
"npm run lint:css",
41+
"npm run fix:js",
42+
"npm run lint:js",
3943
"npm run build:css",
4044
"npm run build:js"
4145
],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"watch:js": "wp-scripts start resources/frontend/js/frontend.js --output-path=resources/frontend/js/dist --output-filename=frontend.min.js",
1111
"lint:js": "wp-scripts lint-js 'resources/frontend/js/*.js' --max-warnings=0",
1212
"fix:js": "wp-scripts lint-js 'resources/frontend/js/*.js' --fix",
13-
"build": "npm run build:css && npm run build:js"
13+
"build": "npm run fix:css && npm run lint:css && npm run fix:js && npm run lint:js && npm run build:css && npm run build:js"
1414
},
1515
"prettier": "@wordpress/prettier-config",
1616
"devDependencies": {

0 commit comments

Comments
 (0)