Skip to content

Commit 8a493d5

Browse files
Mossakaclaude
andcommitted
chore: add actions/setup from gh-aw repo
This action is required by the GitHub organization workflow for the release process to succeed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1a407f7 commit 8a493d5

376 files changed

Lines changed: 90514 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

actions/README.md

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
# GitHub Actions Directory
2+
3+
This directory contains custom GitHub Actions for the gh-aw project. These actions are used internally by compiled workflows to provide functionality such as MCP server file management.
4+
5+
## Directory Structure
6+
7+
Each action follows a standard structure:
8+
9+
```
10+
actions/{action-name}/
11+
├── action.yml # Action metadata and configuration
12+
├── index.js # Bundled action code (generated, committed)
13+
├── src/ # Source files
14+
│ └── index.js # Main action source
15+
└── README.md # Action-specific documentation
16+
```
17+
18+
## Available Actions
19+
20+
### setup
21+
22+
Copies workflow script files to the agent environment. This action embeds all necessary JavaScript files used across all workflow jobs and copies them to a specified destination directory.
23+
24+
[Documentation](./setup/README.md)
25+
26+
### noop
27+
28+
Processes noop safe output - a fallback output type that logs messages for transparency without taking any GitHub API actions.
29+
30+
[Documentation](./noop/README.md)
31+
32+
### minimize_comment
33+
34+
Minimizes (hides) a comment using the GraphQL API.
35+
36+
[Documentation](./minimize_comment/README.md)
37+
38+
### close_issue
39+
40+
Closes a GitHub issue.
41+
42+
[Documentation](./close_issue/README.md)
43+
44+
### close_pull_request
45+
46+
Closes a GitHub pull request.
47+
48+
[Documentation](./close_pull_request/README.md)
49+
50+
### close_discussion
51+
52+
Closes a GitHub discussion.
53+
54+
[Documentation](./close_discussion/README.md)
55+
56+
## Building Actions
57+
58+
Actions are built using the Go-based build system that reuses the bundler and script registry infrastructure from the workflow compiler.
59+
60+
The build process:
61+
62+
1. Reads source files from `actions/{action-name}/src/`
63+
2. Identifies and embeds required JavaScript dependencies from `pkg/workflow/js/`
64+
3. Uses the same bundler infrastructure as workflow compilation
65+
4. Bundles everything into `actions/{action-name}/index.js`
66+
5. Validates `action.yml` files
67+
68+
### Build Commands
69+
70+
```bash
71+
# Build all actions (generates index.js files)
72+
make actions-build
73+
# or
74+
gh aw actions-build
75+
76+
# Validate action.yml files
77+
make actions-validate
78+
# or
79+
gh aw actions-validate
80+
81+
# Clean generated files
82+
# Clean generated files
83+
make actions-clean
84+
# or
85+
gh aw actions-clean
86+
```
87+
88+
The build system uses:
89+
- **Bundler Infrastructure**: Same JavaScript bundler used for workflow compilation (`pkg/workflow/bundler.go`)
90+
- **Script Registry**: Centralized registry for managing JavaScript sources (`pkg/workflow/script_registry.go`)
91+
- **Embedded Sources**: All JavaScript files from `pkg/workflow/js/` via `GetJavaScriptSources()`
92+
93+
## Development Guidelines
94+
95+
### Generating Actions from JavaScript Modules
96+
97+
You can automatically generate action scaffolding from existing JavaScript modules in `pkg/workflow/js/`:
98+
99+
```bash
100+
# Generate action.yml and README.md for selected JavaScript modules
101+
make generate-action-metadata
102+
# or
103+
go run ./internal/tools/generate-action-metadata generate
104+
```
105+
106+
This tool will:
107+
1. Parse JavaScript files to extract inputs (from `core.getInput()`) and outputs (from `core.setOutput()`)
108+
2. Extract descriptions from JSDoc comments
109+
3. Generate `action.yml` with proper structure
110+
4. Generate `README.md` with usage examples
111+
5. Copy source files to `actions/{action-name}/src/index.js`
112+
113+
After generation, you need to:
114+
1. Review and refine the generated `action.yml` and `README.md`
115+
2. Update the dependency mapping in `pkg/cli/actions_build_command.go`
116+
3. Run `make actions-build` to bundle dependencies
117+
118+
### Creating a New Action
119+
120+
1. **Create the directory structure:**
121+
```bash
122+
mkdir -p actions/{action-name}/src
123+
```
124+
125+
2. **Create action.yml:**
126+
Define the action metadata, inputs, outputs, and runtime configuration.
127+
```yaml
128+
name: 'Action Name'
129+
description: 'Action description'
130+
author: 'GitHub Next'
131+
132+
inputs:
133+
input-name:
134+
description: 'Input description'
135+
required: false
136+
default: 'default-value'
137+
138+
outputs:
139+
output-name:
140+
description: 'Output description'
141+
142+
runs:
143+
using: 'node20'
144+
main: 'index.js'
145+
```
146+
147+
3. **Create source file (src/index.js):**
148+
Write the action logic using `@actions/core` and `@actions/github`:
149+
```javascript
150+
const core = require('@actions/core');
151+
152+
async function run() {
153+
try {
154+
const input = core.getInput('input-name');
155+
core.info(`Processing: ${input}`);
156+
157+
// Action logic here
158+
159+
core.setOutput('output-name', 'result');
160+
} catch (error) {
161+
core.setFailed(`Action failed: ${error.message}`);
162+
}
163+
}
164+
165+
run();
166+
```
167+
168+
4. **Update dependency mapping:**
169+
Add the action to the dependency map in `pkg/cli/actions_build_command.go` to specify which JavaScript files from `pkg/workflow/js/` should be embedded.
170+
171+
5. **Build and test:**
172+
```bash
173+
make actions-build
174+
make actions-validate
175+
```
176+
177+
6. **Create README.md:**
178+
Document the action's purpose, usage, inputs, outputs, and examples.
179+
180+
### Action Requirements
181+
182+
- **Runtime**: Actions must use Node.js 20 (`using: 'node20'`)
183+
- **Dependencies**: Use `@actions/core` and `@actions/github` for GitHub Actions integration
184+
- **Error Handling**: Always wrap main logic in try-catch and use `core.setFailed()` for errors
185+
- **Logging**: Use `core.info()`, `core.warning()`, and `core.error()` for output
186+
- **Outputs**: Set outputs using `core.setOutput(name, value)`
187+
188+
### Embedding Files
189+
190+
The build system supports embedding JavaScript files from `pkg/workflow/js/` into actions. To use this:
191+
192+
1. Define a `FILES` constant in your source file:
193+
```javascript
194+
const FILES = {
195+
// This will be populated by the build script
196+
};
197+
```
198+
199+
2. Add the files to the dependency map in `scripts/build-actions.js`
200+
201+
3. The build script will replace the empty `FILES` object with the actual file contents
202+
203+
4. Use the embedded files in your action:
204+
```javascript
205+
for (const [filename, content] of Object.entries(FILES)) {
206+
fs.writeFileSync(path.join(destination, filename), content, 'utf8');
207+
}
208+
```
209+
210+
## Action Types
211+
212+
This directory supports two types of actions:
213+
214+
### 1. Simple Actions (Single-file)
215+
216+
Actions with all logic in `src/index.js` without additional source files.
217+
218+
### 2. Complex Actions (Multi-file)
219+
220+
Actions that use multiple source files in the `src/` directory. The build system will bundle them together.
221+
222+
## Validation
223+
224+
The build system validates:
225+
226+
-`action.yml` exists and contains required fields
227+
-`action.yml` uses `node20` runtime
228+
- ✅ Source files exist in `src/` directory
229+
- ✅ Required dependencies are available
230+
231+
## Git Management
232+
233+
### Files Committed to Git
234+
235+
-`action.yml` - Action metadata
236+
-`index.js` - **Bundled action code (generated but committed)**
237+
-`src/` - Source files
238+
-`README.md` - Documentation
239+
240+
### Files Excluded from Git
241+
242+
-`node_modules/` - Dependencies (if any)
243+
-`*.tmp` - Temporary files
244+
-`.build/` - Build artifacts
245+
246+
**Note**: The bundled `index.js` files are committed to the repository because GitHub Actions requires the complete action code to be present when the action is used. This is standard practice for JavaScript actions.
247+
248+
## Testing
249+
250+
Test actions locally by:
251+
252+
1. Creating a test workflow in `.github/workflows/`
253+
2. Using the action with a local path:
254+
```yaml
255+
- uses: ./actions/setup
256+
with:
257+
destination: /tmp/test
258+
```
259+
3. Running the workflow on GitHub Actions
260+
261+
## Troubleshooting
262+
263+
### Build fails with "File not found"
264+
265+
Ensure the dependency files exist in `pkg/workflow/js/` and are listed correctly in the dependency map.
266+
267+
### Action fails at runtime
268+
269+
Check that:
270+
- All required inputs are provided
271+
- The bundled `index.js` is up to date (run `make actions-build`)
272+
- The action has necessary permissions
273+
274+
### Validation fails
275+
276+
Ensure `action.yml` includes all required fields:
277+
- `name`
278+
- `description`
279+
- `runs` with `using: 'node20'` and `main: 'index.js'`
280+
281+
## References
282+
283+
- [GitHub Actions - Creating JavaScript actions](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action)
284+
- [GitHub Actions Toolkit](https://github.com/actions/toolkit)
285+
- [@actions/core documentation](https://github.com/actions/toolkit/tree/main/packages/core)

0 commit comments

Comments
 (0)