Skip to content

Commit 8c031c2

Browse files
chore: add .github/copilot-instructions.md (#126)
Co-authored-by: joshjohanning-repo-settings-sync[bot] <237077283+joshjohanning-repo-settings-sync[bot]@users.noreply.github.com>
1 parent 74cb5e5 commit 8c031c2

1 file changed

Lines changed: 160 additions & 0 deletions

File tree

.github/copilot-instructions.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# GitHub Copilot Instructions for Node.js Actions
2+
3+
## Project Overview
4+
5+
This is a Node.js GitHub Action template with ESLint, Prettier, Jest testing, and ncc bundling. Follow these guidelines when making changes.
6+
7+
## Code Quality Standards
8+
9+
### ESLint Configuration
10+
11+
- Follow the existing ESLint configuration in `eslint.config.js`
12+
- Use ES modules (`import`/`export`) consistently
13+
- Prefer `const` over `let` when variables don't change
14+
- Use descriptive variable names and JSDoc comments for functions
15+
- Handle errors gracefully with try/catch blocks
16+
17+
### Prettier Formatting
18+
19+
- Code is automatically formatted with Prettier
20+
- Run `npm run format:write` to format all files
21+
- Use single quotes for strings unless they contain single quotes
22+
- Line length limit is enforced by Prettier config
23+
24+
### Import Organization
25+
26+
```javascript
27+
// Always follow this import order:
28+
import * as core from '@actions/core';
29+
import * as github from '@actions/github';
30+
import { Octokit } from '@octokit/rest';
31+
// ... other imports
32+
```
33+
34+
## Testing Guidelines
35+
36+
### Jest Test Structure
37+
38+
- Use ES modules with `jest.unstable_mockModule()` for mocking
39+
- Mock `@actions/core`, `@actions/github`, and external APIs
40+
- Test both success and error scenarios
41+
- Use descriptive test names that explain the behavior
42+
43+
### Mock Patterns
44+
45+
```javascript
46+
// Always mock modules before importing
47+
jest.unstable_mockModule('@actions/core', () => mockCore);
48+
const { functionToTest } = await import('../src/index.js');
49+
```
50+
51+
### Test Coverage
52+
53+
- Write unit tests for all exported functions
54+
- Test error handling paths
55+
- Mock external dependencies (GitHub API, file system, etc.)
56+
- Aim for meaningful assertions, not just code coverage
57+
58+
## GitHub Actions Patterns
59+
60+
### Input Handling
61+
62+
- Use our custom `getInput()` function for reliable local/CI compatibility
63+
- Validate inputs early in the function
64+
- Provide sensible defaults where appropriate
65+
- Log input values for debugging (except sensitive data)
66+
67+
### Output Setting
68+
69+
- Always set outputs using `core.setOutput()`
70+
- Use descriptive output names that match `action.yml`
71+
- Include outputs in job summaries when available
72+
73+
### Error Handling
74+
75+
- Use `core.setFailed()` for action failures
76+
- Use `core.warning()` for non-fatal issues
77+
- Catch and handle API errors gracefully
78+
- Provide helpful error messages
79+
80+
### Local Development Support
81+
82+
- Support running locally with environment variables
83+
- Handle missing GitHub Actions environment gracefully
84+
- Provide clear documentation for local testing
85+
86+
## File Organization
87+
88+
### Source Structure
89+
90+
- Main logic in `src/index.js`
91+
- Export functions for testing
92+
- Keep functions focused and single-purpose
93+
- Use JSDoc comments for all exported functions
94+
95+
### Build Process
96+
97+
- Use `npm run package` to bundle with ncc
98+
- Don't commit the bundled `dist/` directory (during publishing this gets published to **tag-only**)
99+
- Run `npm run all` before committing (format, lint, test, package)
100+
101+
## Documentation Standards
102+
103+
### README Updates
104+
105+
- Keep usage examples up to date with `action.yml`
106+
- Document all inputs and outputs
107+
- Include local development instructions
108+
- Update feature lists when adding functionality
109+
110+
### Code Comments
111+
112+
- Use JSDoc for function documentation
113+
- Include parameter types and return types
114+
- Add inline comments for complex logic
115+
- Document environment variable requirements
116+
117+
## Dependencies
118+
119+
### Adding New Dependencies
120+
121+
- Prefer `@actions/*` packages for GitHub Actions functionality
122+
- Keep dependencies minimal and well-maintained
123+
- Update both `dependencies` and `devDependencies` appropriately
124+
- Test that bundling still works after adding dependencies
125+
126+
### Version Management
127+
128+
- **Always increment the package.json version for each change**
129+
- Use semantic versioning (major.minor.patch)
130+
- Increment patch for bug fixes, minor for new features, major for breaking changes
131+
- Update version before creating releases or publishing changes
132+
133+
### GitHub API Usage
134+
135+
- Use `@octokit/rest` for REST API calls
136+
- Use `@actions/github` for context and helpers
137+
- Handle rate limiting and authentication errors
138+
- Cache API responses when appropriate
139+
- Use pagination when necessary
140+
141+
### GitHub Instance Support
142+
143+
- **Always support GitHub.com, GHES, and GHEC-DR** using `github-api-url` input with default `${{ github.api_url }}`
144+
- Initialize Octokit with a fallback `baseUrl`: `new Octokit({ auth: token, baseUrl: apiUrl || 'https://api.github.com' })`
145+
- GHES/GHE documentation doesn't typically need to be called out separately in the README unless there are specific differences to highlight
146+
147+
## Performance Considerations
148+
149+
- Avoid unnecessary API calls (respect rate limits)
150+
- Use efficient data structures for large datasets
151+
- Handle large datasets with pagination and streaming when possible
152+
- Cache API responses when appropriate to reduce redundant calls
153+
154+
## Security Best Practices
155+
156+
- Never log sensitive data (tokens, secrets)
157+
- Use `core.setSecret()` to mask sensitive values
158+
- Validate and sanitize user inputs
159+
- Follow principle of least privilege for token permissions
160+
- Document when using a GitHub App would be more appropriate than `github.token` or a PAT

0 commit comments

Comments
 (0)