Skip to content

Commit 126bfd9

Browse files
CopilotJamesIves
andcommitted
Add Copilot instructions for better repository understanding
Co-authored-by: JamesIves <[email protected]>
1 parent 61b8354 commit 126bfd9

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

.github/copilot-instructions.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# GitHub Pages Deploy Action - Copilot Instructions
2+
3+
## Project Overview
4+
5+
This is a GitHub Action that automates the deployment of projects to GitHub Pages. It's written in TypeScript and runs on Node.js v22.11.0. The action supports various deployment methods including token-based and SSH-based deployments, can deploy to different branches, and handles both same-repository and cross-repository deployments.
6+
7+
## Architecture
8+
9+
- **Language**: TypeScript (targeting ES6)
10+
- **Runtime**: Node.js v22.11.0
11+
- **Package Manager**: Yarn
12+
- **Testing Framework**: Jest
13+
- **Code Quality**: ESLint + Prettier
14+
15+
### Key Source Files
16+
17+
- `src/main.ts` - Entry point for the action
18+
- `src/git.ts` - Git operations and deployment logic
19+
- `src/worktree.ts` - Git worktree management
20+
- `src/execute.ts` - Command execution utilities
21+
- `src/ssh.ts` - SSH key configuration
22+
- `src/constants.ts` - Type definitions and constants
23+
- `src/util.ts` - Utility functions
24+
25+
## Development Guidelines
26+
27+
### Code Style
28+
29+
1. **TypeScript**: Use strict typing where possible. The project has `noImplicitAny: false` but strive for explicit types
30+
2. **Imports**: Use ES6 import syntax
31+
3. **String Interpolation**: Use template literals for string concatenation
32+
4. **Error Handling**: Use try-catch blocks and return Error objects when needed
33+
5. **Comments**: Use JSDoc-style comments for functions and important code blocks
34+
6. **Naming Conventions**:
35+
- Use camelCase for variables and functions
36+
- Use PascalCase for types and interfaces
37+
- Use descriptive names that clearly indicate purpose
38+
39+
### Git Operations
40+
41+
- Always use `git --no-pager` to avoid pagination issues in automated contexts
42+
- Use temporary deployment branches with pattern: `github-pages-deploy-action-{randomString}` (NOT with forward slashes to avoid Git ref conflicts)
43+
- Always clean up temporary branches and directories after deployment
44+
- Suppress sensitive information in git output (tokens, SSH keys)
45+
46+
### Testing
47+
48+
- **Test Location**: `__tests__/` directory
49+
- **Test Files**: Match source files with `.test.ts` suffix (e.g., `git.test.ts` for `src/git.ts`)
50+
- **Test Framework**: Jest with ts-jest
51+
- **Coverage**: Maintain high test coverage (currently comprehensive)
52+
- **Run Tests**: `yarn test`
53+
- **Test Patterns**:
54+
- Mock external dependencies (especially `@actions/core`, `@actions/exec`, `@actions/io`)
55+
- Test both success and failure scenarios
56+
- Test edge cases and error conditions
57+
- Use descriptive test names with "should" statements
58+
59+
### Building and Linting
60+
61+
- **Build**: `yarn build` - Compiles TypeScript to `lib/` directory
62+
- **Lint**: `yarn lint` - Runs ESLint with auto-fix
63+
- **Lint Check**: `yarn lint:check` - Runs ESLint without auto-fix
64+
- **Format**: `yarn lint:format` - Runs Prettier with auto-fix
65+
- **Format Check**: `yarn lint:format:check` - Runs Prettier without auto-fix
66+
67+
**Important**: The `node_modules/` and `lib/` directories should NOT be committed to the `dev` branch but are required for distribution branches.
68+
69+
### Pull Request Guidelines
70+
71+
1. Test changes by deploying to a real repository using your fork
72+
2. Ensure all integration tests pass
73+
3. Update README.md if changes require documentation
74+
4. Run linting and formatting: `yarn lint && yarn lint:format`
75+
5. Run test suite: `yarn test`
76+
6. Build successfully: `yarn build`
77+
7. Highlight any breaking changes
78+
8. Keep `node_modules/` and `lib/` out of PRs (only needed for distribution)
79+
80+
### Security Considerations
81+
82+
- Never log or expose tokens, SSH keys, or other sensitive data
83+
- Use `suppressSensitiveInformation()` utility for sanitizing output
84+
- Validate all user inputs
85+
- Use the principle of least privilege for permissions
86+
87+
### Common Patterns
88+
89+
1. **Action Configuration**: ActionInterface from constants.ts contains all configuration
90+
2. **Status Returns**: Use Status enum (SUCCESS, FAILED, SKIPPED, RUNNING_CHECKS)
91+
3. **Info Logging**: Use `info()` from @actions/core for user feedback
92+
4. **Error Handling**: Catch errors, extract messages with `extractErrorMessage()`, return Error objects
93+
5. **File Operations**: Use @actions/io functions (mkdirP, rmRF, etc.)
94+
6. **Command Execution**: Use the `execute()` wrapper function, not direct exec
95+
96+
### Deployment Flow
97+
98+
1. Initialize git configuration (`init()`)
99+
2. Generate or use worktree for deployment (`generateWorktree()`)
100+
3. Prepare deployment files
101+
4. Create temporary deployment branch
102+
5. Commit and push changes
103+
6. Clean up temporary resources
104+
7. Return deployment status
105+
106+
## Key Features to Preserve
107+
108+
- Support for gh-pages and docs branches
109+
- Cross-repository deployment capability
110+
- GitHub Enterprise compatibility
111+
- SSH and token-based authentication
112+
- Dry-run mode for testing
113+
- Silent mode for reduced output
114+
- Tag support
115+
- Force push capability
116+
- Clean deployment option
117+
- Custom commit messages
118+
- Git configuration options (user.name, user.email, etc.)
119+
120+
## Known Issues and Gotchas
121+
122+
- Temporary branch names must not use forward slashes to avoid Git ref conflicts with existing branches
123+
- Some tools auto-generate `.gitignore` files that can affect deployments
124+
- Multiple rapid deployments require concurrency controls in workflow configuration
125+
- Permissions must be set correctly (Read and Write for GITHUB_TOKEN)
126+
127+
## Resources
128+
129+
- [GitHub Actions Documentation](https://docs.github.com/en/actions)
130+
- [TypeScript Documentation](https://www.typescriptlang.org/)
131+
- [Jest Documentation](https://jestjs.io/)
132+
- [Action Repository](https://github.com/JamesIves/github-pages-deploy-action)

0 commit comments

Comments
 (0)