Skip to content

Commit 5c4c356

Browse files
CopilothectahertzfrancineluccaCopilot
authored
Add comprehensive GitHub Copilot instructions for primer/react repository (#6521)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: hectahertz <[email protected]> Co-authored-by: Marie Lucca <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent c2a66ec commit 5c4c356

File tree

1 file changed

+154
-9
lines changed

1 file changed

+154
-9
lines changed

.github/copilot-instructions.md

Lines changed: 154 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,159 @@
1-
# Copilot instructions
1+
# Primer React Copilot Instructions
2+
3+
**ALWAYS reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.**
24

35
## Repository Organization
46

5-
The project is the React implementation of a design system (Primer) and is authored as a monorepo where code is organized into separate npm workspaces.
6-
The primary workspace is `packages/react` which contains the `@primer/react` package. This package distributes the React components for the design system.
7+
The project is the React implementation of GitHub's Primer Design System authored as a monorepo with separate npm workspaces.
8+
The primary workspace is `packages/react` which contains the `@primer/react` package that distributes React components for the design system.
9+
10+
**Key Directory Structure:**
11+
12+
- `e2e/`: End-to-end tests running Visual Regression Tests (@vrt) and Accessibility Verification Tests (@avt) using Playwright
13+
- `examples/`: Example applications (nextjs, theming, codesandbox) demonstrating design system usage
14+
- `packages/react/`: Primary package containing all React components and main development workspace
15+
- `packages/mcp/`: Model Context Protocol server for AI tools integration
16+
- `packages/styled-react/`: Legacy styled-components package (being migrated from)
17+
- `script/`: Repository-wide build and utility scripts
18+
- `contributor-docs/`: Contributing guidelines, testing docs, and Architecture Decision Records (ADRs)
19+
20+
## Working Effectively
21+
22+
**Bootstrap and build the repository:**
23+
24+
- Dependencies: Node.js (check with `node --version`), npm (check with `npm --version`)
25+
- `npm install` -- installs dependencies. ~5 seconds with cache, ~2 minutes for clean install. Set timeout to 180+ seconds.
26+
- `npm run build` -- builds all packages. NEVER CANCEL. Takes 90 seconds without turbo cache, ~1 second with cache. Set timeout to 120+ minutes.
27+
- `npx turbo build` -- builds all packages including example applications. Takes ~33 seconds.
28+
29+
**Run tests:**
30+
31+
- `npm test` -- runs unit tests. NEVER CANCEL. Takes 75 seconds. Set timeout to 90+ minutes. Runs 1500+ tests using Vitest in both node and chromium environments.
32+
- `npm run type-check` -- runs TypeScript type checking across all packages. Takes 42 seconds. Set timeout to 60+ minutes.
33+
34+
**Development workflow:**
35+
36+
- `npm start` -- starts Storybook dev server on http://localhost:6006. Takes ~3 seconds to start.
37+
- Main component development happens in `packages/react/src/[ComponentName]/`
38+
- Stories are in component directories as `ComponentName.stories.tsx`
39+
40+
**Visual Regression and Accessibility Testing:**
41+
42+
- Install Playwright: `npx playwright install --with-deps` -- takes ~3 seconds
43+
- Start Storybook first: `npm start` (must be running on port 6006)
44+
- Run VRT: `script/test-e2e --grep @vrt` -- runs visual regression tests against Storybook components
45+
- Run AVT: `script/test-e2e --grep @avt` -- runs accessibility verification tests using axe
46+
- **WARNING**: E2E tests require Storybook running and can take 15+ minutes. NEVER CANCEL. Set timeout to 30+ minutes.
47+
48+
**Linting and formatting:**
49+
50+
- `npm run lint` -- lints JavaScript/TypeScript/Markdown. Takes 73 seconds.
51+
- `npm run lint:fix` -- auto-fixes linting issues where possible
52+
- `npm run lint:css` -- lints CSS files using Stylelint. Takes 6 seconds.
53+
- `npm run lint:css:fix` -- auto-fixes CSS linting issues
54+
- `npm run format` -- formats code using Prettier
55+
- `npm run format:diff` -- checks for unformatted files. Takes 2 seconds.
56+
57+
## Validation Scenarios
58+
59+
**Always validate your changes by:**
60+
61+
1. Building the project: `npm run build` (ensures TypeScript compilation succeeds)
62+
2. Running unit tests: `npm test` (ensures component behavior works correctly)
63+
3. Type checking: `npm run type-check` (ensures TypeScript types are correct)
64+
4. Linting: `npm run lint` and `npm run lint:css` (ensures code style compliance)
65+
5. Formatting: `npm run format:diff` (ensures consistent code formatting)
66+
67+
**For component changes:**
68+
69+
1. Start Storybook: `npm start`
70+
2. Navigate to your component story to visually verify changes
71+
3. Run accessibility tests: `script/test-e2e --grep @avt` if accessibility is impacted
72+
4. Run visual regression tests: `script/test-e2e --grep @vrt` if visual appearance changed
73+
74+
**Before committing:**
75+
76+
- Always run `npm run format` before committing or CI will fail
77+
- Run `npm run lint:fix` to auto-fix linting issues
78+
- Ensure `npm run build` succeeds without errors
79+
80+
## Component Development Guide
81+
82+
**File Structure (packages/react/src/):**
83+
Components follow this pattern:
84+
85+
```
86+
ComponentName/
87+
├── index.ts // Re-exports
88+
├── ComponentName.tsx // Main component
89+
├── ComponentName.stories.tsx // Storybook stories
90+
├── ComponentName.test.tsx // Unit tests
91+
├── ComponentName.docs.json // Documentation metadata
92+
└── __snapshots__/ // Test snapshots (being migrated to VRT)
93+
```
94+
95+
**Common File Patterns:**
96+
97+
- `*.module.css` -- CSS Modules for component styling
98+
- `*.test.tsx` -- Unit tests using Vitest and Testing Library
99+
- `*.stories.tsx` -- Storybook stories for documentation and testing
100+
- `*.docs.json` -- Component metadata for documentation generation
101+
102+
## CI/CD and Workflows
103+
104+
**Key GitHub Actions:**
105+
106+
- `.github/workflows/ci.yml` -- Main CI pipeline (format, lint, test, type-check, build)
107+
- `.github/workflows/vrt.yml` -- Visual regression testing
108+
- `.github/workflows/storybook-tests.yml` -- Storybook interaction tests
109+
110+
**The CI will fail if:**
111+
112+
- Code is not formatted (`npm run format` fixes this)
113+
- Linting errors exist (`npm run lint:fix` auto-fixes many)
114+
- TypeScript compilation fails
115+
- Unit tests fail
116+
- Build fails
117+
118+
## Quick Start Commands Summary
119+
120+
For agents working on this repository for the first time:
121+
122+
```bash
123+
# 1. Check prerequisites
124+
node --version
125+
npm --version
126+
127+
# 2. Install and build (NEVER CANCEL - takes ~2-3 minutes total)
128+
npm install # ~5 seconds (or ~2 minutes clean)
129+
npm run build # ~90 seconds without cache
130+
131+
# 3. Start development
132+
npm start # Starts Storybook on http://localhost:6006
133+
134+
# 4. Run tests and checks
135+
npm test # ~75 seconds - unit tests
136+
npm run type-check # ~42 seconds - TypeScript validation
137+
npm run lint # ~73 seconds - code linting
138+
npm run format:diff # ~2 seconds - format checking
139+
140+
# 5. Before committing
141+
npm run format # Fix formatting
142+
npm run lint:fix # Auto-fix linting issues
143+
```
144+
145+
## Known Issues and Workarounds
146+
147+
**Timing Expectations:**
7148

8-
The overall structure of the project is:
149+
- Fresh install: ~5 seconds (clean install: ~2 minutes)
150+
- Full clean build: ~90 seconds (with turbo cache: ~1 second)
151+
- Build all including examples: ~33 seconds
152+
- Unit tests: ~75 seconds
153+
- Type checking: ~42 seconds
154+
- Linting: ~73 seconds
155+
- CSS linting: ~6 seconds
156+
- Format checking: ~2 seconds
157+
- Storybook startup: ~3 seconds
9158

10-
- `e2e`: contains the end to end tests that run Visual Regression Tests and automated accessibility tests on components
11-
- `examples`: contains multiple example applications that use the design system
12-
- `packages`: contain multiple npm workspaces that are used to deliver the `@primer/react` package that is defined in `packages/react`
13-
- `script`: contains scripts that are used to build and run the project, npm workspaces may also contain their own scripts
14-
- `contributor-docs`: contains the documentation for contributing to the project
159+
**CRITICAL**: NEVER CANCEL builds, tests, or long-running commands. They may take significantly longer in CI environments. Always set appropriate timeouts (90+ minutes for builds/tests).

0 commit comments

Comments
 (0)