Skip to content

Commit

Permalink
Improvements for Deployments
Browse files Browse the repository at this point in the history
Change Details
--------------

Use symplify/monorepo-split-github-action to split monorepo to individual repositories
Create a way to ignore some files from being deployed
Move docs to single point instead of per-package.
Add type-coverage checks
  • Loading branch information
jdamner committed May 24, 2024
1 parent d11d536 commit e8171a1
Show file tree
Hide file tree
Showing 24 changed files with 132 additions and 68 deletions.
29 changes: 16 additions & 13 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ on:
tags:
- "*"

env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}

jobs:
packages_split:
runs-on: ubuntu-latest
name: "Publish changes to ${{ matrix.packages.target_repo }}"

strategy:
fail-fast: false
Expand All @@ -25,6 +23,9 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.BOXUK_WP_ROBOT_ACCESS_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v4
with:
Expand All @@ -33,29 +34,31 @@ jobs:
run: npm install
- name: Build Packages
run: npm run build
- name: Remove `/packages/*/build` from gitignore
run: |
sed -i '/\/packages\/\*\/build/d' .gitignore
# no tag
- name: Rename all `.deployignore` files to `.gitignore` in package
working-directory: packages/${{ matrix.packages.local_path }}
run: mv .deployignore .gitignore

- name: Split Monorepo
if: "!startsWith(github.ref, 'refs/tags/')"
uses: "symplify/monorepo-split-github-action@2.3"
uses: "symplify/monorepo-split-github-action@v2.3.0"
env:
GITHUB_TOKEN: ${{ secrets.BOXUK_WP_ROBOT_ACCESS_TOKEN }}
with:
package_directory: "packages/${{ matrix.packages.local_path }}"
repository_organization: "boxuk"
repository_name: "${{ matrix.packages.target_repo }}"
user_name: "BoxUK Automated Package Management"
user_name: "boxuk-wp-robot"
user_email: "developers@boxuk.com"

# with tag
- name: Split Monorepo with Tag
if: "startsWith(github.ref, 'refs/tags/')"
uses: "symplify/monorepo-split-github-action@2.3"
uses: "symplify/monorepo-split-github-action@v2.3.0"
env:
GITHUB_TOKEN: ${{ secrets.BOXUK_WP_ROBOT_ACCESS_TOKEN }}
with:
tag: ${GITHUB_REF#refs/tags/}
package_directory: "packages/${{ matrix.packages.local_path }}"
repository_organization: "boxuk"
repository_name: "${{ matrix.packages.target_repo }}"
user_name: "BoxUK Automated Package Management"
user_name: "boxuk-wp-robot"
user_email: "developers@boxuk.com"
2 changes: 2 additions & 0 deletions .github/workflows/tests-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ jobs:
run: npm run lint
- name: Unit Test
run: npm run test
- name: Type Coverage
run: npm run type-coverage
- name: Build
run: npm run build
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions docs/editor-tools/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Box WordPress Editor Tools

A collection of tools for modifying the WordPress Editor.

## Quick Start!

The tools here don't load automatically, so you need to get them going.
The quickest way would be to add to `functions.php`:
```php
( new \Boxuk\BoxWpEditorTools\BlockLoader() )->init(); // loads all block.json from /wp-content/themes/{theme}/build/**/*/block.json
( new \Boxuk\BoxWpEditorTools\Comments() )->init(); // disables comments
( new \Boxuk\BoxWpEditorTools\EditorCleanup() )->init(); // Cleans the block-editor to prevent loading plugins
( new \Boxuk\BoxWpEditorTools\PostTypes() )->init(); // registers post-types defined in /wp-content/themes/{theme}/post-types.json
( new \Boxuk\BoxWpEditorTools\TemplatePersistence() )->init(); // saves template changes to disk, not to the database.
( new \Boxuk\BoxWpEditorTools\Security\Security() )->init(); // Enables security hardening.
```
There's more options than that, so checkout the links below:

## Features

- [Asset Loader](./docs/AssetLoader.md) - help load assets generated by [wp-scripts](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/).
- [Block Loader](./docs/BlockLoader.md) - auto-loads blocks to the editor.
- [Comment Disablement](./docs/Comments.md) - disables comments.
- [Editor Cleanup](./docs/EditorCleanup.md) - removes some unnecessary bits from the block editor.
- [Post Type Registrations](./docs/PostTypes.md) - speeds up post-type registration with a single JSON file.
- [Template Persistence](./docs/TemplatePersistence.md) - speeds up template modifications by saving to disk instead of the database.
- [Security](./docs/Security.md) - Adds security hardening.

## Contributing

The dependancies include [WordPress Stubs](https://github.com/php-stubs/wordpress-stubs), so your IDE should automatically include type information for all WP core functions. If they're not, it's likely a mis-configuration of your IDE. There's helper guides in the WordPress Stubs repo.

Working on the repo requires packaging this into a functioning WordPress installation. A ready-to-go solution is yet to be developed so a PR is welcome, preferrably where Docker is the only dependancy.
16 changes: 16 additions & 0 deletions docs/iconography/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Box WordPress Iconography Support

Add the ability to add icons inline to your content in the WordPress block editor.

## Quick Start!
~Add this plugin to your WordPress site and off you go! If you're using composer, then
it's as simple as `composer require boxuk/wp-iconography`.~

We need to setup packaging this as a plugin to be distrubutable, so watch this space - for now you'll need to include this repo and build the assets yourself using `npm run build`.

## Contributing
Working on the repo requires packaging this into a functioning WordPress installation. A ready-to-go solution is yet to be developed so a PR is welcome, preferrably where Docker is the only dependancy.

This package doesn't necessarily require composer dependancies to be installed, so `npm install` and `npm run start` should get you started.

The composer dependancies include [WordPress Stubs](https://github.com/php-stubs/wordpress-stubs), so your IDE should automatically include type information for all WP core functions if you need to edit the PHP file. If they're not, it's likely a mis-configuration of your IDE. There's helper guides in the WordPress Stubs repo.
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WP Packages

Contents:
- [Editor Tools](./editor-tools/index.md)
- [Iconography](./iconography/index.md)
32 changes: 31 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"lint:js:fix": "turbo run lint:js:fix",
"test": "turbo run test",
"test:unit": "turbo run test:unit",
"test:snapshots": "turbo run test:snapshots"
"test:snapshots": "turbo run test:snapshots",
"type-coverage": "turbo run type-coverage"
},
"devDependencies": {
"turbo": "^1.13.3"
Expand Down
2 changes: 2 additions & 0 deletions packages/editor-tools/.deployignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
tests
36 changes: 5 additions & 31 deletions packages/editor-tools/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
# Box WordPress Editor Tools
Please do not submit any Pull Requests here. They will be closed.
---

A collection of tools for modifying the WordPress Editor.
Please submit your PR here instead: https://github.com/boxuk/wp-packages

## Quick Start!

The tools here don't load automatically, so you need to get them going.
The quickest way would be to add to `functions.php`:
```php
( new \Boxuk\BoxWpEditorTools\BlockLoader() )->init(); // loads all block.json from /wp-content/themes/{theme}/build/**/*/block.json
( new \Boxuk\BoxWpEditorTools\Comments() )->init(); // disables comments
( new \Boxuk\BoxWpEditorTools\EditorCleanup() )->init(); // Cleans the block-editor to prevent loading plugins
( new \Boxuk\BoxWpEditorTools\PostTypes() )->init(); // registers post-types defined in /wp-content/themes/{theme}/post-types.json
( new \Boxuk\BoxWpEditorTools\TemplatePersistence() )->init(); // saves template changes to disk, not to the database.
( new \Boxuk\BoxWpEditorTools\Security\Security() )->init(); // Enables security hardening.
```
There's more options than that, so checkout the links below:

## Features

- [Asset Loader](./docs/AssetLoader.md) - help load assets generated by [wp-scripts](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/).
- [Block Loader](./docs/BlockLoader.md) - auto-loads blocks to the editor.
- [Comment Disablement](./docs/Comments.md) - disables comments.
- [Editor Cleanup](./docs/EditorCleanup.md) - removes some unnecessary bits from the block editor.
- [Post Type Registrations](./docs/PostTypes.md) - speeds up post-type registration with a single JSON file.
- [Template Persistence](./docs/TemplatePersistence.md) - speeds up template modifications by saving to disk instead of the database.
- [Security](./docs/Security.md) - Adds security hardening.

## Contributing

The dependancies include [WordPress Stubs](https://github.com/php-stubs/wordpress-stubs), so your IDE should automatically include type information for all WP core functions. If they're not, it's likely a mis-configuration of your IDE. There's helper guides in the WordPress Stubs repo.

Working on the repo requires packaging this into a functioning WordPress installation. A ready-to-go solution is yet to be developed so a PR is welcome, preferrably where Docker is the only dependancy.
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
2 changes: 2 additions & 0 deletions packages/iconography/.deployignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
tests
19 changes: 5 additions & 14 deletions packages/iconography/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
# Box WordPress Iconography Support
Please do not submit any Pull Requests here. They will be closed.
---

Add the ability to add icons inline to your content in the WordPress block editor.
Please submit your PR here instead: https://github.com/boxuk/wp-packages

## Quick Start!
~Add this plugin to your WordPress site and off you go! If you're using composer, then
it's as simple as `composer require boxuk/wp-iconography`.~

We need to setup packaging this as a plugin to be distrubutable, so watch this space - for now you'll need to include this repo and build the assets yourself using `npm run build`.

## Contributing
Working on the repo requires packaging this into a functioning WordPress installation. A ready-to-go solution is yet to be developed so a PR is welcome, preferrably where Docker is the only dependancy.

This package doesn't necessarily require composer dependancies to be installed, so `npm install` and `npm run start` should get you started.

The composer dependancies include [WordPress Stubs](https://github.com/php-stubs/wordpress-stubs), so your IDE should automatically include type information for all WP core functions if you need to edit the PHP file. If they're not, it's likely a mis-configuration of your IDE. There's helper guides in the WordPress Stubs repo.
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
6 changes: 4 additions & 2 deletions packages/iconography/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"test": "wp-scripts test-unit-js",
"test:snapshots": "wp-scripts test-unit-js --updateSnapshot",
"packages-update": "wp-scripts packages-update",
"start": "wp-scripts start"
"start": "wp-scripts start",
"type-coverage": "type-coverage --strict --at-least 99.83"
},
"author": "",
"license": "ISC",
Expand All @@ -26,6 +27,7 @@
"@wordpress/icons": "^9.44.0",
"@wordpress/interface": "^5.30.0",
"@wordpress/scripts": "^27.4.0",
"react": "^18.2.0"
"react": "^18.2.0",
"type-coverage": "^2.28.2"
}
}
2 changes: 1 addition & 1 deletion packages/iconography/src/IconToolbarButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ComponentProps } from 'react';

/* WordPress Dependencies */
import { __ } from '@wordpress/i18n';
Expand Down
4 changes: 2 additions & 2 deletions packages/iconography/src/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe( 'Should generate a rich-text format from icon', () => {
text: 'zoom_out',
formats: new Array( 8 ).fill( [
{ type: 'content-only/ms-outlined' },
] ),
] ) as { type: 'content-only/ms-outlined' }[],
start: 0,
end: 8,
replacements: [],
Expand All @@ -43,7 +43,7 @@ describe( 'Should generate a rich-text format from icon', () => {
text: 'something_else',
formats: new Array( 14 ).fill( [
{ type: 'content-only/ms-outlined' },
] ),
] ) as { type: 'content-only/ms-outlined' }[],
start: 0,
end: 14,
replacements: [],
Expand Down
4 changes: 2 additions & 2 deletions packages/iconography/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export function generateRichTextFormat(
* @return {IconGroupIcon[]} Array of { name, value } objects.
*/
export const getIconOptions = ( suffix: string ): IconGroupIcon[] => {
const iconNames = IconData.filter( ( iconName ) =>
const iconNames = IconData.filter( ( iconName: string ) =>
iconName.endsWith( suffix )
);

return iconNames.map( ( name ) => {
return iconNames.map( ( name: string ) => {
const value = snakeCase( name.replace( suffix, '' ) );
return { name, value };
} );
Expand Down
2 changes: 2 additions & 0 deletions tests/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Tests
Do not put tests here. This should be used for configuring the test environment. Your tests should live with your package.
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"test": {},
"test:unit": {},
"test:snapshots": {}
"test:snapshots": {},
"type-coverage": {}
}
}

0 comments on commit e8171a1

Please sign in to comment.