@codfish/actions 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.github/codeql-config.yml +21 -0
  2. package/.github/dependabot.yml +35 -0
  3. package/.github/workflows/claude-code-review.yml +43 -0
  4. package/.github/workflows/claude.yml +39 -0
  5. package/.github/workflows/release.yml +48 -0
  6. package/.github/workflows/security.yml +103 -0
  7. package/.github/workflows/update-docs.yml +38 -0
  8. package/.github/workflows/validate.yml +210 -0
  9. package/.husky/pre-commit +1 -0
  10. package/.nvmrc +1 -0
  11. package/AGENT.md +129 -0
  12. package/CLAUDE.md +3 -0
  13. package/CONTRIBUTING.md +316 -0
  14. package/README.md +207 -0
  15. package/SECURITY.md +208 -0
  16. package/bin/generate-docs.js +432 -0
  17. package/comment/README.md +82 -0
  18. package/comment/action.yml +102 -0
  19. package/eslint.config.js +8 -0
  20. package/npm-publish-pr/README.md +145 -0
  21. package/npm-publish-pr/action.yml +171 -0
  22. package/package.json +52 -0
  23. package/setup-node-and-install/README.md +139 -0
  24. package/setup-node-and-install/action.yml +220 -0
  25. package/tests/fixtures/.node-version +1 -0
  26. package/tests/fixtures/.nvmrc +1 -0
  27. package/tests/fixtures/lockfiles/package-lock.json +12 -0
  28. package/tests/fixtures/lockfiles/pnpm-lock.yaml +9 -0
  29. package/tests/fixtures/lockfiles/yarn.lock +7 -0
  30. package/tests/fixtures/package-json/minimal.json +4 -0
  31. package/tests/fixtures/package-json/scoped.json +6 -0
  32. package/tests/fixtures/package-json/valid.json +13 -0
  33. package/tests/integration/comment/basic.bats +95 -0
  34. package/tests/integration/npm-pr-version/basic.bats +353 -0
  35. package/tests/integration/setup-node-and-install/basic.bats +200 -0
  36. package/tests/scripts/test-helpers.sh +113 -0
  37. package/tests/scripts/test-runner.sh +115 -0
@@ -0,0 +1,316 @@
1
+ # Contributing to codfish/actions
2
+
3
+ Thank you for your interest in contributing! This document provides guidelines for contributing to this repository.
4
+
5
+ <!-- prettier-ignore-start -->
6
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
7
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
8
+ ## Table of Contents
9
+
10
+ - [Code of Conduct](#code-of-conduct)
11
+ - [Getting Started](#getting-started)
12
+ - [Development Workflow](#development-workflow)
13
+ - [1. Create a Branch](#1-create-a-branch)
14
+ - [2. Make Your Changes](#2-make-your-changes)
15
+ - [3. Test Your Changes](#3-test-your-changes)
16
+ - [4. Commit Your Changes](#4-commit-your-changes)
17
+ - [Action Development Guidelines](#action-development-guidelines)
18
+ - [Directory Structure](#directory-structure)
19
+ - [Action Naming](#action-naming)
20
+ - [Action Definition (action.yml)](#action-definition-actionyml)
21
+ - [Implementation Guidelines](#implementation-guidelines)
22
+ - [Error Handling](#error-handling)
23
+ - [Package Manager Detection](#package-manager-detection)
24
+ - [Testing](#testing)
25
+ - [Test Structure](#test-structure)
26
+ - [Writing Tests](#writing-tests)
27
+ - [Running Tests](#running-tests)
28
+ - [Documentation](#documentation)
29
+ - [README Structure](#readme-structure)
30
+ - [Documentation Updates](#documentation-updates)
31
+ - [Auto-Generated Documentation](#auto-generated-documentation)
32
+ - [Submitting Changes](#submitting-changes)
33
+ - [Pull Request Process](#pull-request-process)
34
+ - [PR Requirements](#pr-requirements)
35
+ - [Review Process](#review-process)
36
+ - [Action Ideas](#action-ideas)
37
+ - [Getting Help](#getting-help)
38
+ - [Recognition](#recognition)
39
+
40
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
41
+ <!-- prettier-ignore-end -->
42
+
43
+ ## Code of Conduct
44
+
45
+ This project follows the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected
46
+ to uphold this code.
47
+
48
+ ## Getting Started
49
+
50
+ 1. **Fork the repository** and clone it locally
51
+ 2. **Install dependencies**: `pnpm install`
52
+ 3. **Set up your development environment**:
53
+ ```bash
54
+ # Install act for local testing (optional but recommended)
55
+ brew install act # macOS
56
+ # or
57
+ curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash # Linux
58
+ ```
59
+
60
+ ## Development Workflow
61
+
62
+ ### 1. Create a Branch
63
+
64
+ ```bash
65
+ git checkout -b feature/your-feature-name
66
+ # or
67
+ git checkout -b fix/your-bug-fix
68
+ ```
69
+
70
+ ### 2. Make Your Changes
71
+
72
+ Follow the [Action Development Guidelines](#action-development-guidelines) below.
73
+
74
+ ### 3. Test Your Changes
75
+
76
+ ```bash
77
+ # Run all tests
78
+ pnpm test
79
+
80
+ # Run specific test types
81
+ pnpm test:integration
82
+ pnpm test:unit
83
+
84
+ # Run linting
85
+ pnpm lint
86
+ ```
87
+
88
+ ### 4. Commit Your Changes
89
+
90
+ Use clear, descriptive commit messages:
91
+
92
+ ```bash
93
+ git commit -m "feat(setup-node): add yarn berry support"
94
+ git commit -m "fix(comment): handle empty tag input properly"
95
+ git commit -m "docs(npm-pr-version): update README with new examples"
96
+ ```
97
+
98
+ ## Action Development Guidelines
99
+
100
+ ### Directory Structure
101
+
102
+ Each action should be in its own directory at the repository root:
103
+
104
+ ```
105
+ action-name/
106
+ ├── action.yml # Action definition
107
+ ├── README.md # Action documentation
108
+ └── [implementation files]
109
+ ```
110
+
111
+ ### Action Naming
112
+
113
+ - Use **kebab-case** for action directory names
114
+ - Action names should be descriptive and follow the pattern: `verb-noun` or `noun-verb`
115
+ - Examples: `setup-node-and-install`, `npm-pr-version`, `comment`
116
+
117
+ ### Action Definition (action.yml)
118
+
119
+ ```yaml
120
+ name: action-name
121
+ description: Clear, concise description of what the action does
122
+
123
+ inputs:
124
+ input-name:
125
+ description: Clear description of the input parameter
126
+ required: true|false
127
+ default: 'default-value' # if applicable
128
+
129
+ outputs:
130
+ output-name:
131
+ description: Clear description of the output
132
+ value: '${{ steps.step-id.outputs.output-name }}'
133
+
134
+ runs:
135
+ using: composite
136
+ steps:
137
+ # Implementation steps
138
+ ```
139
+
140
+ ### Implementation Guidelines
141
+
142
+ 1. **Use composite actions** for consistency and transparency
143
+ 2. **Validate inputs** early with clear error messages
144
+ 3. **Handle errors gracefully** with actionable feedback
145
+ 4. **Use consistent formatting**:
146
+ - ❌ for errors
147
+ - ✅ for success messages
148
+ - 📦 for package manager operations
149
+ - 📋 for informational messages
150
+ 5. **Support multiple package managers** when applicable (npm/yarn/pnpm)
151
+ 6. **Follow security best practices** - never log secrets or sensitive data
152
+
153
+ ### Error Handling
154
+
155
+ ```bash
156
+ # Good error handling example
157
+ if [ ! -f "package.json" ]; then
158
+ echo "❌ ERROR: package.json not found in current directory"
159
+ echo "Make sure you're running this action in a directory with a package.json file"
160
+ exit 1
161
+ fi
162
+ ```
163
+
164
+ ### Package Manager Detection
165
+
166
+ When applicable, detect package managers in this order:
167
+
168
+ 1. `yarn.lock` → yarn
169
+ 2. `pnpm-lock.yaml` → pnpm
170
+ 3. `package-lock.json` → npm
171
+ 4. No lockfile → npm (default)
172
+
173
+ ## Testing
174
+
175
+ ### Test Structure
176
+
177
+ ```
178
+ tests/
179
+ ├── integration/ # Full action tests
180
+ │ └── action-name/
181
+ │ └── basic.bats
182
+ ├── fixtures/ # Test data
183
+ │ ├── package-json/
184
+ │ └── lockfiles/
185
+ └── scripts/
186
+ ├── test-runner.sh
187
+ └── test-helpers.sh
188
+ ```
189
+
190
+ ### Writing Tests
191
+
192
+ 1. **Create integration tests** for each action in `tests/integration/action-name/`
193
+ 2. **Use the bats testing framework** for shell script testing
194
+ 3. **Test error conditions** as well as success scenarios
195
+ 4. **Use test fixtures** from `tests/fixtures/` when possible
196
+
197
+ Example test:
198
+
199
+ ```bash
200
+ @test "action-name: handles valid input" {
201
+ # Setup
202
+ cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
203
+
204
+ # Test
205
+ run bash -c 'your-test-command'
206
+
207
+ # Assertions
208
+ assert_success
209
+ assert_output_contains "expected-output"
210
+ }
211
+ ```
212
+
213
+ ### Running Tests
214
+
215
+ ```bash
216
+ # All tests
217
+ pnpm test
218
+
219
+ # Specific action tests
220
+ ./tests/scripts/test-runner.sh integration
221
+ ```
222
+
223
+ ## Documentation
224
+
225
+ ### README Structure
226
+
227
+ Each action should have a comprehensive README.md with:
228
+
229
+ 1. **Title and description**
230
+ 2. **Table of contents** (for longer READMEs)
231
+ 3. **Usage section** with basic example
232
+ 4. **Inputs table** with descriptions
233
+ 5. **Outputs table** (if applicable)
234
+ 6. **Examples section** with various use cases
235
+ 7. **Special features** (package manager detection, etc.)
236
+
237
+ ### Documentation Updates
238
+
239
+ - Update action README when changing inputs/outputs
240
+ - **Run `pnpm docs:generate`** to auto-update the main project README
241
+ - Update CLAUDE.md when changing project structure
242
+ - Add inline comments for complex logic
243
+
244
+ ### Auto-Generated Documentation
245
+
246
+ The main project README's "Available Actions" section is automatically generated from:
247
+
248
+ - `action.yml` files (name, description, inputs, outputs)
249
+ - Individual action README files (usage examples)
250
+
251
+ **When to regenerate documentation:**
252
+
253
+ - After adding a new action
254
+ - After changing action.yml inputs/outputs
255
+ - After updating action descriptions
256
+ - Before submitting a PR
257
+
258
+ ```bash
259
+ # Generate updated documentation
260
+ pnpm docs:generate
261
+
262
+ # Review the changes
263
+ git diff README.md
264
+ ```
265
+
266
+ ## Submitting Changes
267
+
268
+ ### Pull Request Process
269
+
270
+ 1. **Create a descriptive PR title**: `feat(action-name): add new feature`
271
+ 2. **Fill out the PR template** completely
272
+ 3. **Link related issues** using keywords (Closes #123)
273
+ 4. **Request review** from maintainers
274
+ 5. **Address feedback** promptly and respectfully
275
+
276
+ ### PR Requirements
277
+
278
+ - [ ] All tests pass
279
+ - [ ] Code follows existing style guidelines
280
+ - [ ] Documentation is updated
281
+ - [ ] Changes are tested in real GitHub Actions workflows
282
+ - [ ] No security vulnerabilities introduced
283
+
284
+ ### Review Process
285
+
286
+ 1. **Automated checks** must pass (tests, linting, security scans)
287
+ 2. **Manual review** by maintainers
288
+ 3. **Testing** in real-world scenarios
289
+ 4. **Approval** and merge
290
+
291
+ ## Action Ideas
292
+
293
+ Looking for contribution ideas? Here are some actions that would be valuable:
294
+
295
+ - `slack-notify` - Send Slack notifications
296
+ - `docker-build-push` - Build and push Docker images
297
+ - `semantic-release` - Automated semantic versioning
298
+ - `cache-restore-save` - Advanced caching patterns
299
+ - `monorepo-changed` - Detect changed packages in monorepos
300
+ - `performance-test` - Lighthouse/performance testing
301
+
302
+ ## Getting Help
303
+
304
+ - **GitHub Discussions**: Ask questions and discuss ideas
305
+ - **Issues**: Report bugs or request features
306
+ - **Discord/Slack**: [Link if available]
307
+
308
+ ## Recognition
309
+
310
+ Contributors will be recognized in:
311
+
312
+ - Commit messages with `Co-authored-by`
313
+ - Release notes
314
+ - Contributors section (if added)
315
+
316
+ Thank you for contributing! 🎉
package/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # codfish/actions
2
+
3
+ A collection of reusable GitHub Actions for common development workflows. Each action is self-contained and designed for
4
+ maximum reusability across different projects.
5
+
6
+ <!-- prettier-ignore-start -->
7
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
8
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9
+ ## Table of Contents
10
+
11
+ - [Usage](#usage)
12
+ - [Available Actions](#available-actions)
13
+ - [comment](#comment)
14
+ - [npm-pr-version](#npm-pr-version)
15
+ - [setup-node-and-install](#setup-node-and-install)
16
+ - [Contributing](#contributing)
17
+ - [Example Workflow](#example-workflow)
18
+
19
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
20
+ <!-- prettier-ignore-end -->
21
+
22
+ ## Usage
23
+
24
+ Reference actions using the following format:
25
+
26
+ ```yaml
27
+ uses: codfish/actions/{action-name}@main
28
+ uses: codfish/actions/{action-name}@v1
29
+ uses: codfish/actions/{action-name}@v1.0.1
30
+ uses: codfish/actions/{action-name}@feature-branch
31
+ uses: codfish/actions/{action-name}@aff1a9d
32
+ ```
33
+
34
+ ## Available Actions
35
+
36
+ <!-- start action docs -->
37
+
38
+ ### [comment](./comment/)
39
+
40
+ Creates or updates a comment in a pull request with optional tagging for upsert functionality
41
+
42
+ **Inputs:**
43
+
44
+ | Input | Description | Required | Default |
45
+ | --------- | ------------------------------------------------------------------------------------- | -------- | ------- |
46
+ | `message` | The comment message content (supports markdown formatting) | Yes | - |
47
+ | `tag` | Unique identifier to find and update existing comments (required when upsert is true) | No | - |
48
+ | `upsert` | Update existing comment with matching tag instead of creating new comment | No | `false` |
49
+
50
+ **Usage:**
51
+
52
+ ```yaml
53
+ - name: Comment on PR
54
+ uses: codfish/actions/comment@v1
55
+ with:
56
+ message: '✅ Build successful!'
57
+ tag: 'build-status'
58
+ upsert: true
59
+ ```
60
+
61
+ ### [npm-pr-version](./npm-publish-pr/)
62
+
63
+ Publishes package with PR-specific version (0.0.0-PR-123--abc1234) using detected package manager (npm/yarn/pnpm) and
64
+ automatically comments on PR
65
+
66
+ **Inputs:**
67
+
68
+ | Input | Description | Required | Default |
69
+ | -------------- | ----------------------------------------------------------------------------------- | -------- | ---------------- |
70
+ | `npm-token` | Registry authentication token with publish permissions (works with npm/yarn/pnpm) | No | - |
71
+ | `github-token` | GitHub token with pull request comment permissions (typically secrets.GITHUB_TOKEN) | Yes | - |
72
+ | `comment` | Whether to comment on the PR with the published version (true/false) | No | `true` |
73
+ | `comment-tag` | Tag to use for PR comments (for comment identification and updates) | No | `npm-publish-pr` |
74
+
75
+ **Outputs:**
76
+
77
+ | Output | Description |
78
+ | --------------- | --------------------------------------------------------------------- |
79
+ | `version` | Generated PR-specific version number (0.0.0-PR-{number}--{short-sha}) |
80
+ | `package-name` | Package name from package.json |
81
+ | `error-message` | Error message if publish fails |
82
+
83
+ **Usage:**
84
+
85
+ ```yaml
86
+ steps:
87
+ - uses: actions/checkout@v5
88
+
89
+ - uses: codfish/actions/setup-node-and-install@v1
90
+ with:
91
+ node-version: lts/*
92
+
93
+ - run: npm run build
94
+
95
+ - uses: codfish/actions/npm-pr-version@v1
96
+ with:
97
+ npm-token: ${{ secrets.NPM_TOKEN }}
98
+ github-token: ${{ secrets.GITHUB_TOKEN }}
99
+ ```
100
+
101
+ ### [setup-node-and-install](./setup-node-and-install/)
102
+
103
+ Sets up Node.js environment and installs dependencies with automatic package manager detection (npm/pnpm/yarn),
104
+ intelligent caching, and .nvmrc/.node-version support
105
+
106
+ **Inputs:**
107
+
108
+ | Input | Description | Required | Default |
109
+ | ------------------- | ----------------------------------------------------------------------------------------------------- | -------- | ------- |
110
+ | `node-version` | Node.js version to install (e.g. '24', 'lts/\*'). Defaults to .nvmrc or .node-version file if present | No | - |
111
+ | `cache-key-suffix` | Additional suffix for cache key to enable multiple caches per workflow | No | - |
112
+ | `install-options` | Extra command-line options to pass to npm/pnpm/yarn install | No | - |
113
+ | `working-directory` | Directory containing package.json and lockfile | No | `.` |
114
+
115
+ **Usage:**
116
+
117
+ ```yaml
118
+ steps:
119
+ - uses: actions/checkout@v5
120
+
121
+ # will install latest Node v18.x
122
+ - uses: codfish/actions/setup-node-and-install@v1
123
+ with:
124
+ node-version: 18
125
+ cache-key-suffix: '-${{ github.head_ref || github.event.release.tag_name }}'
126
+
127
+ - run: npm test
128
+ ```
129
+
130
+ <!-- end action docs -->
131
+
132
+ ## Contributing
133
+
134
+ Each action follows these conventions:
135
+
136
+ - **Directory structure**: Actions are in kebab-case directories at the repository root
137
+ - **Required files**: `action.yml`, `README.md`
138
+ - **Composite actions**: All actions use `composite` type for simplicity and transparency
139
+ - **Documentation**: Each action includes comprehensive usage examples and input/output documentation
140
+
141
+ ## Example Workflow
142
+
143
+ Complete workflow using multiple actions together:
144
+
145
+ ```yaml
146
+ name: CI/CD Pipeline
147
+ on:
148
+ pull_request:
149
+ types: [opened, synchronize]
150
+
151
+ jobs:
152
+ test-and-publish:
153
+ runs-on: ubuntu-latest
154
+ steps:
155
+ - uses: actions/checkout@v5
156
+
157
+ - uses: codfish/actions/setup-node-and-install@v1
158
+ with:
159
+ node-version: 'lts/*'
160
+
161
+ - name: Run tests
162
+ run: |
163
+ npm test 2>&1 | tee test-output.txt
164
+ if grep -q "All tests passed" test-output.txt; then
165
+ echo "status=✅ passed" >> $GITHUB_OUTPUT
166
+ else
167
+ echo "status=❌ failed" >> $GITHUB_OUTPUT
168
+ fi
169
+ echo "count=$(grep -c "✓\|√\|PASS" test-output.txt || echo "unknown")" >> $GITHUB_OUTPUT
170
+ id: test
171
+
172
+ - name: Build package
173
+ run: npm run build
174
+
175
+ - name: Calculate build size
176
+ run: |
177
+ if [ -d "dist" ]; then
178
+ size=$(du -sh dist | cut -f1)
179
+ elif [ -d "build" ]; then
180
+ size=$(du -sh build | cut -f1)
181
+ elif [ -f "package.json" ]; then
182
+ size=$(du -sh . --exclude=node_modules | cut -f1)
183
+ else
184
+ size="unknown"
185
+ fi
186
+ echo "size=$size" >> $GITHUB_OUTPUT
187
+ id: build
188
+
189
+ - uses: codfish/actions/comment@v1
190
+ with:
191
+ message: |
192
+ ## 🚀 **Build Summary**
193
+
194
+ **Tests**: ${{ steps.test.outputs.status }} (${{ steps.test.outputs.count }} tests)
195
+ **Build**: ✅ completed successfully
196
+ **Size**: ${{ steps.build.outputs.size }}
197
+
198
+ Ready for testing! 🎉
199
+ tag: 'build-summary'
200
+ upsert: true
201
+
202
+ - uses: codfish/actions/npm-pr-version@v1
203
+ with:
204
+ npm-token: ${{ secrets.NPM_TOKEN }}
205
+ github-token: ${{ secrets.GITHUB_TOKEN }}
206
+ comment-tag: 'pr-package'
207
+ ```