Skip to content

Commit f63ad68

Browse files
Copilotdata-douser
andcommitted
Add Copilot compatibility setup with instruction files and dependency workflow
Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent 49f19e5 commit f63ad68

File tree

4 files changed

+232
-0
lines changed

4 files changed

+232
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# C# Code Instructions for CodeQL Development Toolkit
2+
3+
## Code Style and Conventions
4+
5+
- Use nullable reference types consistently. Declare properties as nullable (`string?`) when they can be null, or ensure non-nullable properties are initialized.
6+
- Follow existing namespace patterns: `CodeQLToolkit.Features.*`, `CodeQLToolkit.Shared.*`, `CodeQLToolkit.Core.*`
7+
- Use the existing logging pattern: `Log<ClassName>.G().LogInformation()` for logging
8+
- Prefer `Path.Combine()` for file path construction instead of string concatenation
9+
10+
## Architecture Patterns
11+
12+
- **Feature Pattern**: Features are organized under `CodeQLToolkit.Features` with main registration classes like `QueryFeatureMain`, `TestFeatureMain`, etc.
13+
- **Command Pattern**: Use `System.CommandLine` for CLI command implementation with proper option handling
14+
- **Template Pattern**: Lifecycle targets inherit from `BaseLifecycleTarget` and implement specific automation workflows
15+
- **Dependency Injection**: Use constructor injection and register services appropriately
16+
17+
## Key Classes and Patterns
18+
19+
- `BaseLifecycleTarget`: Abstract base for lifecycle automation targets (Actions, Local, etc.)
20+
- `ILifecycleTarget`: Interface for lifecycle operations with `Run()` method
21+
- `TemplateUtil`: Use for rendering Liquid templates with `TemplateFromFile()` and `RawTemplateFromFile()`
22+
- `QLTConfig`: Configuration management with JSON serialization using Newtonsoft.Json
23+
- `Query`: Utility class for managing CodeQL query file paths and structure
24+
25+
## File Organization
26+
27+
- Keep automation-specific logic in separate targets under `Lifecycle/Targets/Actions/`, `Lifecycle/Targets/Local/`
28+
- Templates should be organized by feature: `Templates/Query/`, `Templates/Test/`, `Templates/Bundle/`
29+
- Shared utilities go in `CodeQLToolkit.Shared/Utils/`
30+
31+
## Error Handling
32+
33+
- Use proper exception handling and meaningful error messages
34+
- Log important operations and errors using the established logging framework
35+
- Validate file paths and directory existence before operations
36+
37+
## Testing
38+
39+
- Follow the existing test structure in `test/CodeQLToolkit.*.Tests/`
40+
- Use NUnit testing framework consistently with the existing patterns
41+
- Consider using constraint model: `Assert.That(actual, Is.EqualTo(expected))` instead of classic model
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Liquid Template Instructions for CodeQL Development Toolkit
2+
3+
## Template Purpose and Structure
4+
5+
Liquid templates in this project generate CodeQL-related files, GitHub Actions workflows, and project configuration files. They are organized by feature area and automation type.
6+
7+
## Template Organization
8+
9+
- **Query Templates**: `Templates/Query/` - Generate CodeQL query files, qlpack.yml, test files
10+
- **Test Templates**: `Templates/Test/Actions/` - Generate GitHub Actions for testing workflows
11+
- **Bundle Templates**: `Templates/Bundle/Actions/` - Generate bundle integration test workflows
12+
- **Validation Templates**: `Templates/Validation/Actions/` - Generate validation workflows
13+
14+
## Variable Naming Conventions
15+
16+
Use snake_case for template variables to match existing patterns:
17+
- `query_name`, `query_pack_name`, `language`, `description`
18+
- `num_threads`, `use_runner`, `dev_mode`, `branch`
19+
- `codeql_args`, `extra_args`, `automation_type`
20+
21+
## Common Template Patterns
22+
23+
### CodeQL Query Headers
24+
Always include proper metadata headers for CodeQL queries:
25+
```liquid
26+
/**
27+
* @id {{language}}/{{query_pack_name}}/{{query_name}}
28+
* @name {{query_name}}
29+
* @description {{description}}
30+
* @kind problem
31+
* @precision medium
32+
* @problem.severity error
33+
* @tags {{query_pack_name}}
34+
*/
35+
```
36+
37+
### GitHub Actions Structure
38+
For workflow templates:
39+
- Use descriptive names and descriptions
40+
- Include proper input/output definitions
41+
- Use composite actions pattern with shell steps
42+
- Include debug logging: `echo "::debug::message"`
43+
44+
### File Path Construction
45+
Use consistent path patterns:
46+
- CodeQL queries: `{{language}}/{{query_pack_name}}/src/{{query_name}}/{{query_name}}.ql`
47+
- Test files: `{{language}}/{{query_pack_name}}/test/{{query_name}}/{{query_name}}.{{language_extension}}`
48+
49+
## Template Rendering Context
50+
51+
Templates are rendered using Scriban engine with:
52+
- `TemplateUtil.TemplateFromFile()` for parsing and rendering
53+
- Variables passed as anonymous objects in C# code
54+
- Access to language-specific helpers through utility classes
55+
56+
## Best Practices
57+
58+
- Keep templates focused on single responsibility
59+
- Use meaningful variable names that reflect the generated content purpose
60+
- Include appropriate comments in generated files
61+
- Ensure generated files follow CodeQL and GitHub Actions best practices
62+
- Use conditional logic sparingly - prefer multiple specialized templates
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# CodeQL Development Toolkit Repository Instructions
2+
3+
## Project Overview
4+
5+
The CodeQL Development Toolkit (QLT) is a command-line tool for CodeQL query development, testing, and automation. It provides scaffolding, lifecycle management, and CI/CD integration for CodeQL projects.
6+
7+
## Repository Structure
8+
9+
- `src/CodeQLToolkit.Core/` - Main CLI application entry point
10+
- `src/CodeQLToolkit.Features/` - Feature implementations (Query, Test, Bundle, Validation)
11+
- `src/CodeQLToolkit.Shared/` - Shared utilities, configuration, and base classes
12+
- `test/` - Unit tests for each component
13+
- `.github/workflows/` - CI/CD workflows for building and testing
14+
- `.github/actions/` - Reusable actions for CodeQL and QLT installation
15+
16+
## Key Dependencies
17+
18+
- **.NET 6.0+**: Primary development framework
19+
- **System.CommandLine**: CLI framework for command parsing
20+
- **Scriban**: Liquid template engine for code generation
21+
- **Newtonsoft.Json**: JSON serialization for configuration
22+
- **NUnit**: Testing framework
23+
24+
## Development Workflow
25+
26+
1. **Building**: Use `dotnet build` and `dotnet restore`
27+
2. **Testing**: Use `dotnet test` for unit tests
28+
3. **CLI Usage**: The main executable is `qlt` with features: query, test, bundle, validation, pack, codeql
29+
30+
## Feature Architecture
31+
32+
Each feature follows a consistent pattern:
33+
- `*FeatureMain.cs` - Feature registration and command setup
34+
- `Commands/` - Command implementations
35+
- `Lifecycle/` - Automation lifecycle targets
36+
- `Templates/` - Liquid templates for file generation
37+
38+
## Automation Types
39+
40+
The toolkit supports multiple automation platforms:
41+
- **Actions**: GitHub Actions integration
42+
- **Local**: Local development workflows
43+
44+
## Configuration
45+
46+
- `qlt.conf.json` - Project configuration file
47+
- Environment variables and CLI options for runtime configuration
48+
- Template-based configuration file generation
49+
50+
## Contributing Guidelines
51+
52+
- Follow existing code patterns and conventions
53+
- Add unit tests for new functionality
54+
- Update documentation for user-facing changes
55+
- Ensure compatibility with existing workflows
56+
- Test changes against sample CodeQL projects
57+
58+
## CLI Command Structure
59+
60+
```
61+
qlt <feature> <action> [options]
62+
```
63+
64+
Features: query, test, bundle, validation, pack, codeql
65+
Common actions: init, create, validate, run
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Copilot Setup Steps
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
copilot-setup-steps:
12+
name: Pre-install Dependencies for Copilot Environment
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Setup .NET 6.0.x
20+
uses: actions/setup-dotnet@v4
21+
with:
22+
dotnet-version: 6.0.x
23+
24+
- name: Verify .NET installation
25+
run: |
26+
dotnet --version
27+
echo "✅ .NET 6.0.x installed successfully"
28+
29+
- name: Setup GitHub CLI (for QLT installation)
30+
run: |
31+
# GitHub CLI is typically pre-installed on GitHub runners
32+
gh --version
33+
echo "✅ GitHub CLI available"
34+
35+
- name: Install QLT CLI dependencies
36+
run: |
37+
# Install dependencies required for QLT to run
38+
sudo apt-get update
39+
sudo apt-get install -y unzip curl
40+
echo "✅ Required system dependencies installed"
41+
42+
- name: Restore .NET dependencies
43+
run: |
44+
dotnet restore
45+
echo "✅ .NET dependencies restored"
46+
47+
- name: Build project to verify setup
48+
run: |
49+
dotnet build -c Release --no-restore
50+
echo "✅ Project builds successfully"
51+
52+
- name: Test QLT CLI availability
53+
run: |
54+
# Build and test that the qlt CLI can be executed
55+
dotnet run --project src/CodeQLToolkit.Core -- version
56+
echo "✅ QLT CLI is functional"
57+
58+
- name: Verify Copilot environment readiness
59+
run: |
60+
echo "🤖 Copilot environment setup complete!"
61+
echo "✅ .NET 6.0.x: $(dotnet --version)"
62+
echo "✅ GitHub CLI: $(gh --version | head -n1)"
63+
echo "✅ System tools: unzip, curl available"
64+
echo "✅ QLT CLI: Ready for CodeQL development tasks"

0 commit comments

Comments
 (0)