Skip to content

Commit 982c5fe

Browse files
authored
Merge pull request #300 from chef/nikhil/copilot-instructions
Add GitHub Copilot instructions for chef-cli
2 parents 14c9f11 + 48c4285 commit 982c5fe

File tree

2 files changed

+408
-0
lines changed

2 files changed

+408
-0
lines changed

.github/copilot-instructions.md

Lines changed: 398 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,398 @@
1+
# GitHub Copilot Instructions for chef-cli
2+
3+
---
4+
5+
## 1. Repository Analysis & Structure
6+
7+
### Project Purpose
8+
**chef-cli** is a Ruby gem that provides a command line interface for Chef Infra practitioners. It is a streamlined development and deployment workflow tool for the Chef platform, offering everything needed to be successful using Chef Infra, Chef InSpec, and Chef Habitat. The tool builds Chef Infra Policyfiles to provide an awesome experience that encourages quick iteration and testing.
9+
10+
### Folder Structure Diagram
11+
```
12+
chef-cli/
13+
├── .buildkite/ # Buildkite CI configuration
14+
├── .expeditor/ # Expeditor build automation config
15+
├── .github/ # GitHub workflows, CODEOWNERS, Copilot instructions
16+
├── .ruby-lsp/ # Ruby LSP configuration
17+
├── bin/ # Executable scripts (chef-cli CLI)
18+
├── coverage/ # Test coverage reports
19+
├── dev-doc/ # Development documentation
20+
├── habitat/ # Habitat packaging and test scripts
21+
│ ├── plan.ps1 # Windows Habitat plan
22+
│ ├── plan.sh # Linux Habitat plan
23+
│ └── tests/ # Habitat test scripts
24+
├── lib/ # Main Ruby library code
25+
│ ├── chef-cli.rb # Main entry point
26+
│ ├── chef-cli/ # Core gem logic
27+
│ │ ├── command/ # CLI command implementations
28+
│ │ ├── completions/ # Shell completion scripts
29+
│ │ ├── cookbook_profiler/ # Cookbook analysis tools
30+
│ │ ├── licensing/ # License management
31+
│ │ ├── policyfile/ # Policyfile-related services
32+
│ │ ├── policyfile_services/ # Policyfile operations
33+
│ │ ├── service_exception_inspectors/ # Error handling
34+
│ │ └── skeletons/ # Code generation templates
35+
│ └── kitchen/ # Test Kitchen integration
36+
├── spec/ # RSpec unit tests
37+
│ ├── shared/ # Shared test contexts
38+
│ ├── unit/ # Unit test specifications
39+
│ └── test_helpers.rb # Test helper utilities
40+
├── .gitignore # Git ignore patterns
41+
├── .rspec # RSpec configuration
42+
├── .rubocop.yml # RuboCop configuration
43+
├── CHANGELOG.md # Version history
44+
├── chef-cli.gemspec # Gem specification
45+
├── CODE_OF_CONDUCT.md # Code of conduct
46+
├── CONTRIBUTING.md # Contribution guidelines
47+
├── Gemfile # Ruby gem dependencies
48+
├── Gemfile.lock # Locked gem versions
49+
├── Guardfile # Guard automation config
50+
├── LICENSE # Apache 2.0 License
51+
├── post-bundle-install.rb # Post-bundle installation script
52+
├── Rakefile # Rake build/test tasks
53+
├── README.md # Main documentation
54+
├── report.spdx.json # SPDX license report
55+
├── sonar-project.properties # SonarQube configuration
56+
└── VERSION # Gem version
57+
```
58+
59+
### Technologies Used
60+
- **Languages:** Ruby (>= 3.1)
61+
- **Frameworks:** Chef Infra, RSpec, Test Kitchen
62+
- **Build/Automation:** Rake, Bundler, Expeditor, Habitat, Buildkite
63+
- **Linting:** Chefstyle, RuboCop, Cookstyle
64+
- **CI/CD:** Buildkite, Expeditor, SonarQube
65+
- **Package Management:** Habitat, Omnibus
66+
67+
### File Modification Guidelines
68+
- **Safe to Modify:**
69+
- `lib/`, `spec/`, `dev-doc/`, `habitat/`, `README.md`, `CHANGELOG.md`, `Rakefile`, `Gemfile`, `Gemfile.lock`, `.github/`, `.buildkite/`
70+
- **Prohibited/Generated:**
71+
- `coverage/`, `vendor/`, files in `.expeditor/` (except by automation), `VERSION` (bump only via release process), `Gemfile.lock` (modify via bundle commands only)
72+
- **Never Modify:**
73+
- License headers, copyright blocks, and files marked as auto-generated
74+
75+
### Code Generation Patterns
76+
- Do not modify files generated by Rake, Bundler, or Expeditor directly.
77+
- Do not edit files in `coverage/`, `vendor/`, or auto-generated directories.
78+
79+
---
80+
81+
## 2. Development Workflow Integration
82+
83+
### Jira Integration (atlassian-mcp-server)
84+
- When a Jira ID is provided, fetch the issue using the atlassian-mcp-server MCP server.
85+
- Read the story, analyze requirements, and plan implementation before coding.
86+
87+
### Workflow Phases
88+
#### **Phase 1: Initial Setup & Analysis**
89+
- Prompt: "Jira ID provided: `<JIRA_ID>`. Fetching issue details and analyzing requirements."
90+
- Analyze repository structure and dependencies.
91+
- Plan implementation and confirm with user.
92+
- **Approval Gate:** "Ready to proceed with implementation. Continue?"
93+
94+
#### **Phase 2: Implementation Phase**
95+
- Implement code changes and update documentation.
96+
- Prompt: "Implementation complete. Ready for testing. Continue?"
97+
- **Approval Gate:** Confirm before moving to testing.
98+
99+
#### **Phase 3: Testing Phase**
100+
- Create/modify unit tests (RSpec for Ruby).
101+
- Run all tests and ensure >80% coverage (CRITICAL REQUIREMENT).
102+
- Prompt: "Testing complete. Coverage: XX%. Ready to create PR?"
103+
- **Approval Gate:** Confirm before PR creation.
104+
105+
#### **Phase 4: Pull Request Creation**
106+
- Use Jira ID as branch name (e.g., `PROJ-123`).
107+
- Use GH CLI for all git operations (no profile-based auth).
108+
- Prompt: "PR created. Review and merge when ready."
109+
110+
---
111+
112+
## 3. Testing Requirements (Critical)
113+
**ALL code changes MUST include comprehensive unit tests.**
114+
- **>80% test coverage is a HARD REQUIREMENT.**
115+
- Use RSpec for unit tests (`spec/`).
116+
- Run tests with:
117+
- `bundle exec rspec spec/`
118+
- `bundle exec rake style:chefstyle`
119+
- `bundle exec rake style:cookstyle`
120+
- Coverage report: `coverage/index.html` (generated by SimpleCov)
121+
- Test both positive/negative, edge cases, and error conditions.
122+
- Use mocks for external dependencies.
123+
- Tests must be independent and order-agnostic.
124+
- **Verify coverage:**
125+
- `open coverage/index.html` (macOS)
126+
- Ensure SimpleCov reports >80%.
127+
- **Emphasize:** No PR will be accepted without >80% coverage.
128+
129+
#### Example RSpec Test Structure
130+
```ruby
131+
require 'spec_helper'
132+
describe ChefCLI::Command::Install do
133+
it 'installs a policyfile' do
134+
# ... test code ...
135+
end
136+
end
137+
```
138+
139+
#### Example Test with Mocking
140+
```ruby
141+
require 'spec_helper'
142+
describe ChefCLI::PolicyfileServices::Install do
143+
let(:policyfile_lock) { instance_double(ChefCLI::PolicyfileLock) }
144+
145+
it 'validates the policyfile lock' do
146+
expect(service).to receive(:validate_lockfile)
147+
service.run
148+
end
149+
end
150+
```
151+
152+
---
153+
154+
## 4. Pull Request Creation Process
155+
- **Branch name:** Use Jira ID (e.g., `PROJ-123`)
156+
- **Commands:**
157+
- Branch: `git checkout -b <JIRA_ID>`
158+
- Stage/commit: `git add . && git commit --signoff -m "<JIRA_ID>: description"`
159+
- Amend signoff: `git commit --amend --signoff --no-edit`
160+
- Push: `git push origin <JIRA_ID>`
161+
- Create PR: `gh pr create --base main --head <JIRA_ID> --title "<JIRA_ID>: <summary>" --body-file pr_description.html --label "Type: Enhancement"`
162+
- **PR Description (HTML):**
163+
- Summary of changes
164+
- Link to Jira ticket: `<a href="https://jira.example.com/browse/<JIRA_ID>">Jira Ticket</a>`
165+
- List of changes
166+
- Testing performed and coverage results
167+
- List of files modified
168+
- Screenshots/examples if applicable
169+
170+
---
171+
172+
## 5. DCO (Developer Certificate of Origin) Compliance
173+
- **ALL commits MUST use `--signoff`**
174+
- Example: `git commit --signoff -m "<JIRA_ID>: description"`
175+
- To amend: `git commit --amend --signoff --no-edit`
176+
- **Builds will fail without DCO signoff.**
177+
- All commit examples in this guide include `--signoff`.
178+
179+
---
180+
181+
## 6. Build System Integration Analysis
182+
- **Expeditor:**
183+
- Config: `.expeditor/config.yml`
184+
- Skip labels: `Expeditor: Skip All`, `Expeditor: Skip Version Bump`, `Expeditor: Skip Changelog`, `Expeditor: Skip Habitat`, `Expeditor: Skip Omnibus`
185+
- Use skip labels for docs/test-only changes to avoid unnecessary builds.
186+
- Build channels: `main` (see config)
187+
- Automation: version bump, changelog, gem build, habitat pipeline
188+
- **Rake:**
189+
- `rake`: Default task (runs tests and style checks)
190+
- `bundle exec rspec spec/`: Run unit tests
191+
- `bundle exec rake style:chefstyle`: Run Ruby style checks
192+
- `bundle exec rake style:cookstyle`: Run cookbook style checks
193+
- **Bundler:**
194+
- `bundle install`: Install dependencies
195+
- `bundle exec`: Run commands with correct gem environment
196+
- **SonarQube:**
197+
- Config: `sonar-project.properties`
198+
- Coverage: SimpleCov, RSpec
199+
- **Habitat:**
200+
- Linux plan: `habitat/plan.sh`
201+
- Windows plan: `habitat/plan.ps1`
202+
- Tests: `habitat/tests/test.sh`, `habitat/tests/test.ps1`
203+
204+
---
205+
206+
## 7. Label Management System
207+
- **Actual labels:**
208+
- `Type: Bug`, `Type: Enhancement`, `Type: Regression`, `Aspect: Documentation`, `Aspect: Testing`, `Aspect: Security`, `Expeditor: Skip All`, `Expeditor: Skip Version Bump`, `Expeditor: Skip Changelog`, `Expeditor: Skip Habitat`, `Expeditor: Skip Omnibus`, `Priority: Critical/Medium/Low`, `Platform: <platform>`
209+
- **Docs/test-only:** Use `Aspect: Documentation`, `Aspect: Testing`, and Expeditor skip labels
210+
- **Feature:** `Type: Enhancement`
211+
- **Bug:** `Type: Bug`
212+
- **Test-only:** `Aspect: Testing`, `Expeditor: Skip Version Bump`
213+
- **Decision Matrix:**
214+
- Docs: `Aspect: Documentation`, `Expeditor: Skip All`
215+
- Test: `Aspect: Testing`, `Expeditor: Skip Version Bump`
216+
- Feature: `Type: Enhancement`
217+
- Bug: `Type: Bug`
218+
219+
---
220+
221+
## 8. Prompt-Based Execution Protocol
222+
- After each major step, summarize what was completed.
223+
- Before next step, state what will be done and ask: "Do you want me to continue with the next step?"
224+
- List remaining steps.
225+
- Wait for user approval before proceeding.
226+
- **Example:**
227+
- "Phase 1 complete: Jira analysis and planning. Next: Implementation. Continue?"
228+
- "Remaining: Implementation, Testing, PR Creation."
229+
230+
---
231+
232+
## 9. Repository-Specific Guidelines
233+
- **Build:** Use Rake tasks, Bundler, and Expeditor automation.
234+
- **Dependencies:** Managed via Bundler (`Gemfile`).
235+
- **Dev Environment:** Use native Ruby (>= 3.1), Habitat, or Chef Workstation.
236+
- **Prohibited:** Never edit files in `coverage/`, `vendor/`, or generated files.
237+
- **Platform:** macOS, Linux, Windows (see Habitat plans).
238+
- **Integration:** Chef ecosystem, Habitat, Expeditor, SonarQube, Buildkite.
239+
240+
---
241+
242+
## 10. Code Quality & Standards
243+
- **Style:** Chefstyle, RuboCop, Cookstyle (`bundle exec rake style:chefstyle`)
244+
- **Conventions:** Ruby best practices, Chef community standards
245+
- **Security:** No secrets in code, use Chef Vault for sensitive data
246+
- **License:** Apache 2.0 (see LICENSE)
247+
- **Performance:** Optimize for large cookbooks and policies
248+
- **Review:** CODEOWNERS: `@chef/chef-workstation-reviewers`, `@chef/chef-workstation-approvers`, `@chef/chef-workstation-owners` (all files); `@chef/docs-team` (`*.md`)
249+
250+
---
251+
252+
## 11. Security and Compliance Requirements
253+
- **CVE Awareness:** Monitor dependencies
254+
- **FIPS:** Ensure FIPS compliance if required
255+
- **License Headers:** Do not remove/modify
256+
- **Scanning:** Use SonarQube, RuboCop
257+
- **Authentication:** Chef server, policyfile operations
258+
259+
---
260+
261+
## 12. Build & Development Environment
262+
- **Setup:**
263+
- `bundle install`
264+
- Use Habitat (`habitat/`) for isolated environments
265+
- Ruby >= 3.1 required
266+
- **Build:**
267+
- `rake` (all tests and style)
268+
- `bundle exec rspec spec/` (unit tests)
269+
- `bundle exec rake style:chefstyle` (Ruby style)
270+
- `bundle exec rake style:cookstyle` (cookbook style)
271+
- **Troubleshooting:**
272+
- See `dev-doc/README.md` for development setup
273+
- For coverage: ensure SimpleCov is enabled in `spec_helper.rb`
274+
275+
---
276+
277+
## 13. Integration & Dependencies
278+
- **Ecosystem:** Chef Infra, Chef Workstation, Habitat, Expeditor, SonarQube
279+
- **External Services:** Chef server, Rubygems, Jira (via MCP)
280+
- **API:** Chef Infra API, Policyfile services, cookbook management
281+
282+
---
283+
284+
## 14. Release & CI/CD Awareness
285+
- **Pipelines:** Buildkite, Expeditor, Habitat
286+
- **Release:** Automated via Expeditor, Rubygems publish
287+
- **Channels:** `main` branch, see `.expeditor/config.yml`
288+
- **Notifications:** Slack: `chef-ws-notify`
289+
290+
---
291+
292+
## 15. Code Ownership & Review Process
293+
- **CODEOWNERS:**
294+
- All files: `@chef/chef-workstation-reviewers`, `@chef/chef-workstation-approvers`, `@chef/chef-workstation-owners`
295+
- Markdown: `@chef/docs-team`
296+
- **Review:** At least one approval from owners/approvers required
297+
298+
---
299+
300+
## 16. Important Development Notes
301+
- **Work locally**; do not edit files directly in remote or generated folders
302+
- **Ask for clarification** if requirements are unclear
303+
- **Never modify:** `coverage/`, `vendor/`, auto-generated files
304+
- **Troubleshooting:** See `dev-doc/README.md`, `README.md`, and coverage reports
305+
- **Build/Test Commands:**
306+
- `bundle install`
307+
- `bundle exec rspec spec/`
308+
- `bundle exec rake style:chefstyle`
309+
- `bundle exec rake style:cookstyle`
310+
- **CLI Commands:** `chef-cli generate`, `chef-cli install`, `chef-cli push`, `chef-cli update`, `chef-cli export`
311+
312+
---
313+
314+
## 17. Example Workflow Execution
315+
**Feature Implementation Example:**
316+
1. User: "Implement feature X for Jira ID PROJ-123"
317+
2. Copilot: "Phase 1: Fetching Jira PROJ-123, analyzing requirements...\nReady to proceed with implementation. Continue?\nRemaining: Implementation, Testing, PR Creation."
318+
3. User: "Continue"
319+
4. Copilot: "Phase 2: Implementing feature X...\nImplementation complete. Ready for testing. Continue?\nRemaining: Testing, PR Creation."
320+
5. User: "Continue"
321+
6. Copilot: "Phase 3: Running tests...\nCoverage: 92%. Ready to create PR?\nRemaining: PR Creation."
322+
7. User: "Continue"
323+
8. Copilot: "Phase 4: Creating PR...\nPR created. Review and merge when ready."
324+
325+
**Bug Fix Example:**
326+
- Use `Type: Bug` label, follow same workflow
327+
328+
**Docs Change Example:**
329+
- Use `Aspect: Documentation`, `Expeditor: Skip All` labels
330+
331+
---
332+
333+
## 18. Technology-Specific Guidelines
334+
### Ruby
335+
- **Bundler:** `bundle install`
336+
- **RSpec:** `bundle exec rspec spec/`
337+
- **Chefstyle:** `bundle exec rake style:chefstyle`
338+
- **Cookstyle:** `bundle exec rake style:cookstyle`
339+
- **Gem Management:** Use `Gemfile`, do not edit `Gemfile.lock` directly
340+
- **Testing:** Use mocks for Chef API/server, test all edge/error cases
341+
- **Coverage:** SimpleCov enabled in `spec_helper.rb`
342+
- **Ruby Version:** >= 3.1 required
343+
344+
### Chef Infra Integration
345+
- **Policyfiles:** Core functionality for cookbook management
346+
- **Chef Server API:** Authentication and communication
347+
- **Test Kitchen:** Integration testing support
348+
- **Cookbook Generation:** Template-based code generation
349+
350+
---
351+
352+
## 19. Advanced Configuration Management
353+
- **Config files:** `.expeditor/config.yml`, `sonar-project.properties`, `habitat/plan.sh`, `habitat/plan.ps1`, `.buildkite/`
354+
- **Env vars:** See Habitat plans and Buildkite configs for required variables
355+
- **Secrets:** Never commit secrets; use Chef Vault for secret management
356+
- **Database:** Not applicable
357+
- **MCP server:** For Jira integration, configure atlassian-mcp-server as needed
358+
359+
---
360+
361+
## 20. Key Commands & CLI Usage
362+
### chef-cli Command Reference
363+
- **Generate:** `chef-cli generate cookbook COOKBOOK_NAME`
364+
- **Install:** `chef-cli install [POLICYFILE]`
365+
- **Update:** `chef-cli update [POLICYFILE]`
366+
- **Push:** `chef-cli push POLICY_GROUP [POLICYFILE]`
367+
- **Export:** `chef-cli export [POLICYFILE] DESTINATION`
368+
- **Diff:** `chef-cli diff [POLICY_FILE] [POLICY_GROUP]`
369+
- **Shell Init:** `chef-cli shell-init SHELL_NAME`
370+
- **Gem:** `chef-cli gem COMMAND`
371+
- **Exec:** `chef-cli exec COMMAND`
372+
373+
### Development Commands
374+
- **Test:** `bundle exec rspec spec/`
375+
- **Style:** `bundle exec rake style:chefstyle`
376+
- **Coverage:** Open `coverage/index.html`
377+
- **Build Gem:** `gem build chef-cli.gemspec`
378+
- **Install Local:** `gem install chef-cli-*.gem`
379+
380+
---
381+
382+
## Validation Checklist
383+
- [x] Repository structure diagram
384+
- [x] DCO signoff requirements in all commit examples
385+
- [x] >80% test coverage requirement mentioned multiple times
386+
- [x] Actual repository labels (not generic ones)
387+
- [x] Build system integration (Expeditor, Rake, Bundler, Habitat)
388+
- [x] Prompt-based workflow examples
389+
- [x] Technology-specific testing patterns
390+
- [x] Complete Git workflow with proper commands
391+
- [x] Security and compliance requirements
392+
- [x] Troubleshooting section
393+
- [x] Example interaction patterns
394+
- [x] Chef-CLI specific commands and usage
395+
396+
---
397+
398+
*Generated for the chef-cli repository. For questions, see `README.md`, `CONTRIBUTING.md`, or contact the CODEOWNERS.*

0 commit comments

Comments
 (0)