Skip to content

Commit d706efd

Browse files
committed
Add general agent script, workflow, and documentation
Introduces a functional Node.js agent script (.github/agents/agent-script.js) that lists files and outputs environment info, along with a corresponding GitHub Actions workflow (.github/workflows/agent-workflow.yml) for automation and artifact upload. Updates agent documentation to reference the new agent and workflow as templates for future automation. Adds generate-plugin.md to document plugin generation and build/test scripts.
1 parent 596506e commit d706efd

File tree

4 files changed

+220
-8
lines changed

4 files changed

+220
-8
lines changed

.github/agents/agent-script.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
// agent-script.js
3+
// Functional agent script: lists files in the current directory and writes output to a file.
4+
5+
const fs = require('fs');
6+
const path = require('path');
7+
8+
const args = process.argv.slice(2);
9+
const env = {
10+
DRY_RUN: process.env.DRY_RUN,
11+
VERBOSE: process.env.VERBOSE,
12+
GITHUB_TOKEN: process.env.GITHUB_TOKEN ? '***' : undefined
13+
};
14+
15+
console.log('Agent Script Running');
16+
console.log('Arguments:', args);
17+
console.log('Environment:', env);
18+
19+
// List files in the current directory
20+
const files = fs.readdirSync(process.cwd());
21+
console.log('Files in current directory:', files);
22+
23+
// Write output to a file for workflow artifact
24+
const output = {
25+
args,
26+
env,
27+
files
28+
};
29+
const outputPath = path.join(process.cwd(), 'agent-output.json');
30+
fs.writeFileSync(outputPath, JSON.stringify(output, null, 2));
31+
console.log('Output written to', outputPath);
32+
33+
process.exit(0);

.github/agents/agent.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,30 @@ This file documents the primary automation agent(s) for this repository, their p
1414

1515
---
1616

17-
## Primary Agent: wp-block-build.agent.js
17+
## Primary Agents
1818

19-
- **Agent Script:** `.github/agents/wp-block-build.agent.js`
20-
- **Spec:** `.github/agents/wp-block-build.agent.md`
21-
- **Workflow:** `.github/workflows/block-plugin-build-and-e2e.yml`
22-
- **Purpose:** Automate build, lint, test, and validation for this block plugin using WordPress and org standards.
19+
- **Block Plugin Build Agent:**
20+
21+
- **Agent Script:** `.github/agents/wp-block-build.agent.js`
22+
- **Spec:** `.github/agents/wp-block-build.agent.md`
23+
- **Workflow:** `.github/workflows/block-plugin-build-and-e2e.yml`
24+
- **Purpose:** Automate build, lint, test, and validation for this block plugin using WordPress and org standards.
25+
26+
- **General Automation Agent Example:**
27+
- **Agent Script:** `.github/agents/agent-script.js`
28+
- **Workflow:** `.github/workflows/agent-workflow.yml`
29+
- **Purpose:** Demonstrates a functional Node.js agent and workflow for file listing, environment echo, and artifact upload. Use as a template for new automation agents.
2330

2431
### Usage
2532

26-
- **GitHub Actions:** See the workflow file for triggers and environment variables
27-
- **Local:** `node .github/agents/wp-block-build.agent.js`
33+
- **Block Plugin Build Agent:**
34+
35+
- **GitHub Actions:** See `.github/workflows/block-plugin-build-and-e2e.yml` for triggers and environment variables
36+
- **Local:** `node .github/agents/wp-block-build.agent.js`
37+
38+
- **General Automation Agent Example:**
39+
- **GitHub Actions:** See `.github/workflows/agent-workflow.yml` for triggers and environment variables
40+
- **Local:** `node .github/agents/agent-script.js --example`
2841

2942
### Environment Variables
3043

@@ -34,10 +47,15 @@ This file documents the primary automation agent(s) for this repository, their p
3447

3548
### Maintenance
3649

37-
- Keep the agent aligned with repo tooling (linters, build, tests)
50+
- Keep all agents aligned with repo tooling (linters, build, tests)
3851
- Update documentation and scripts as workflows evolve
3952
- See [WP Block Build Agent Spec](./wp-block-build.agent.md) for detailed build process and requirements
53+
- Use `.github/agents/agent-script.js` and `.github/workflows/agent-workflow.yml` as a starting point for new automation agents. Update references in this file and in all AI ops/instruction files as new agents are added.
4054

4155
---
4256

57+
---
58+
59+
> **Note:** The files `.github/agents/agent-script.js` and `.github/workflows/agent-workflow.yml` are now functional examples. Use them as templates for new agents. All AI ops and instruction files (see Related Files above) should reference these agents and workflows as appropriate for discoverability and onboarding.
60+
4361
For more information on agent usage, see [Custom Instructions](../custom-instructions.md), [Workflows](../../workflows/), and [Global AI Rules (AGENTS.md)](../../AGENTS.md).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
jobs:
2+
name: Agent Workflow
3+
4+
on:
5+
workflow_dispatch:
6+
7+
agent-job:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
- name: Setup Node.js
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: '18.x'
16+
- name: Run agent script
17+
run: |
18+
node .github/agents/agent-script.js --from-workflow
19+
env:
20+
DRY_RUN: false
21+
VERBOSE: true
22+
- name: Upload agent output
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: agent-output
26+
path: agent-output.json

docs/generate-plugin.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Single Block Plugin Generation & Build Scripts
2+
3+
This document explains how to use the scripts in the `bin/` directory to generate, build, and test a new single block plugin from this scaffold.
4+
5+
## Overview
6+
7+
The `bin/` directory contains utility scripts for:
8+
9+
- Generating a new single block plugin from the scaffold with custom metadata
10+
- Building the plugin for production
11+
- Running all tests and static analysis
12+
- Updating the plugin version across all files
13+
- Setting up the WordPress PHPUnit test environment
14+
15+
## Scripts
16+
17+
### 1. `generate-single-block-plugin.js`
18+
19+
Generates a new plugin by copying the scaffold and replacing all mustache placeholders with your provided values.
20+
21+
**Usage:**
22+
23+
```sh
24+
node bin/generate-single-block-plugin.js --slug my-block --name "My Block" --description "Description here" --author "Your Name" --author_uri "https://yourdomain.com" --version "1.0.0"
25+
```
26+
27+
- The generated plugin will be placed in an `output-plugin/` directory in your current working directory.
28+
- All placeholders like `{{slug}}`, `{{name}}`, etc., will be replaced with your values.
29+
- You can safely edit the generated plugin independently of the scaffold.
30+
31+
**Arguments:**
32+
33+
- `--slug` (required): Plugin slug (e.g., `my-block`)
34+
- `--name`: Plugin display name
35+
- `--description`: Plugin description
36+
- `--author`: Author name
37+
- `--author_uri`: Author website
38+
- `--version`: Plugin version
39+
40+
### 2. `build.sh`
41+
42+
Builds the plugin, installs dependencies, lints, and runs tests.
43+
44+
**Usage:**
45+
46+
```sh
47+
bin/build.sh
48+
```
49+
50+
- Installs Node.js and Composer dependencies
51+
- Builds plugin assets
52+
- Runs linting and tests
53+
- Outputs a summary and next steps
54+
55+
### 3. `test.sh`
56+
57+
Runs all plugin tests (JS, PHP, E2E) and static analysis.
58+
59+
**Usage:**
60+
61+
```sh
62+
bin/test.sh
63+
```
64+
65+
- Installs dependencies if needed
66+
- Runs JavaScript and PHP unit tests
67+
- Runs PHP static analysis and linting
68+
- Runs E2E tests if `wp-env` is available
69+
70+
### 4. `update-version.js`
71+
72+
Updates the plugin version across all relevant files.
73+
74+
**Usage:**
75+
76+
```sh
77+
node bin/update-version.js <new-version>
78+
```
79+
80+
- Updates `package.json`, `composer.json`, main plugin file, block.json, and README.md
81+
- Prints a summary and next steps
82+
83+
### 5. `install-wp-tests.sh`
84+
85+
Shell script to set up the WordPress PHPUnit test environment. Used internally for CI and local test setup.
86+
87+
**Usage:**
88+
89+
```sh
90+
bin/install-wp-tests.sh <wp-version> <db-name> <db-user> <db-pass> [db-host]
91+
```
92+
93+
- Downloads and configures the WordPress test suite for PHP unit testing.
94+
95+
## Workflow Example
96+
97+
1. Generate a new plugin:
98+
99+
```sh
100+
node bin/generate-single-block-plugin.js --slug my-block --name "My Block" --description "A custom block" --author "Jane Doe"
101+
```
102+
103+
2. Enter the generated plugin directory:
104+
105+
```sh
106+
cd output-plugin
107+
```
108+
109+
3. Build the plugin:
110+
111+
```sh
112+
bin/build.sh
113+
```
114+
115+
4. Run all tests:
116+
117+
```sh
118+
bin/test.sh
119+
```
120+
121+
5. Update the version:
122+
123+
```sh
124+
node bin/update-version.js 1.2.0
125+
```
126+
127+
## Notes
128+
129+
- The `build.sh` and `test.sh` scripts expect a valid `package.json` and `composer.json` in the plugin root.
130+
- The `generate-single-block-plugin.js` script will not overwrite an existing `output-plugin/` directory.
131+
- For advanced usage, see comments in each script.
132+
133+
---
134+
135+
For more details, see the inline documentation in each script in the `bin/` directory.

0 commit comments

Comments
 (0)