Skip to content

Commit 585653e

Browse files
authored
Add Copilot custom instructions (#20)
This pull request introduces comprehensive Copilot and language-specific instructions for Azure Cosmos DB samples, standardizing conventions across the repository for structure, authentication, code style, and CI workflows. The changes clarify product naming, enforce folder and file patterns, and provide detailed guidelines for .NET, Python, Go, TypeScript, and workflow files to ensure consistency and maintainability. **Copilot and repository-wide conventions:** * Added `.github/copilot-instructions.md` with detailed guidelines for product naming, folder structure, sample numbering, shared data model, authentication, package versioning, README conventions, testing/CI, and anti-patterns. **Language-specific sample conventions:** * Added `.github/instructions/dotnet.instructions.md` outlining .NET sample structure, package management, authentication, and code style (e.g., use of `.cs` scripts, `#:package`, top-level statements, and `record` types). * Added `.github/instructions/python.instructions.md` detailing Python sample file structure, dependency management, authentication, and code style (e.g., single `app.py`, `os.environ` for config, dict literals for data). * Added `.github/instructions/go.instructions.md` specifying Go sample structure, module naming, authentication, and code style (e.g., single `main.go`, `go.mod`, JSON struct tags, error handling helpers). * Added `.github/instructions/typescript.instructions.md` defining TypeScript sample structure, dependency management, authentication, and code style (e.g., `tsx` usage, caret version ranges, ES modules, `interface` for types). **CI workflow conventions:** * Added `.github/instructions/workflows.instructions.md` to standardize CI workflow structure, validation jobs, per-language build/test rules, emulator testing, and language-specific build/test instructions.
1 parent 8fc3a0b commit 585653e

6 files changed

Lines changed: 232 additions & 0 deletions

File tree

.github/copilot-instructions.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Azure Cosmos DB Samples — Copilot Instructions
2+
3+
## Product naming
4+
5+
- Always say **Azure Cosmos DB** — never "Azure Cosmos DB for NoSQL"
6+
- The NoSQL API is the only API in this repository and is always inferred
7+
- Do not generate samples for MongoDB, Cassandra, Gremlin, or Table APIs
8+
9+
## Repository structure
10+
11+
- Root folders by language: `dotnet/`, `python/`, `go/`, `typescript/`
12+
- Sample folders use the pattern `NNN-kebab-case-name/` (regex: `^[0-9]{3}-[a-z0-9]+(-[a-z0-9]+)*$`)
13+
- Every sample folder **must** contain a `readme.md`
14+
- Each sample is self-contained and independently runnable
15+
16+
## Numbering standard
17+
18+
Sample numbers are **shared across languages** — the same number means the same concept in every language.
19+
20+
| Range | Category | Description |
21+
|-------|----------|-------------|
22+
| `000–099` | Connectivity | Client setup, authentication, emulator |
23+
| `100–199` | Quickstart | Hello-world style getting-started scenarios |
24+
| `200–299` | Features | Change feed, bulk, batch, patch, indexing |
25+
| `300–399` | Patterns | Multi-tenancy, pagination, retry, hierarchical partition keys |
26+
| `400–499` | Advanced | Vector search, AI integration, semantic cache |
27+
| `500–599` | Vertical | End-to-end apps (todo, IoT, e-commerce) |
28+
29+
## Shared data model
30+
31+
All samples use the same database, container, and item shape:
32+
33+
- **Database:** `cosmicworks`
34+
- **Container:** `products`
35+
- **Partition key:** `/category`
36+
- **Product shape:** `{ id, category, name, quantity, sale }`
37+
- **Canonical item:** id `70b63682-b93a-4c77-aad2-65501347265f`, category `gear-surf-surfboards`, name `Yamba Surfboard`, quantity `12`, sale `false`
38+
39+
## Authentication
40+
41+
- **00x range only** (connect samples): passwordless via `DefaultAzureCredential`
42+
- **All other samples**: key-based via `COSMOS_ENDPOINT` + `COSMOS_KEY` environment variables
43+
44+
## Package versions
45+
46+
Do **not** pin specific package versions. Use floating or major-version ranges:
47+
48+
- .NET: `Version="3.*"` in `Directory.Packages.props` or `#:package Foo@3.*` in script files
49+
- Python: `azure-cosmos>=4.9` in `requirements.txt`
50+
- Go: standard `go get` versioning
51+
- TypeScript: caret ranges (`^`) in `package.json`
52+
53+
## README conventions
54+
55+
- **Title pattern:** `{Operation} with Azure Cosmos DB ({Language})`
56+
- **Sections:** Prerequisites, Run (with macOS/Linux + Windows PowerShell blocks), What this sample does
57+
- **Environment variable callout:** use `> [!IMPORTANT]` note
58+
- **Connect samples (00x):** only read account metadata — no CRUD operations
59+
- Do not include `.env.example` files — put env var instructions inline in the readme
60+
61+
## Testing and CI
62+
63+
- Samples are validated on **every push to `main`** and on **every pull request**
64+
- Samples should be runnable against the **Azure Cosmos DB emulator**
65+
- The CI workflow (`.github/workflows/validate.yml`) runs per-language build jobs independently
66+
- Structure validation enforces the naming regex and readme presence
67+
68+
## Anti-patterns
69+
70+
- Do not say "for NoSQL" — just "Azure Cosmos DB"
71+
- Do not add `.env.example` files
72+
- Do not use `python-dotenv` — use `os.environ` directly
73+
- Do not pin exact package versions
74+
- Do not mix CRUD operations into connect samples
75+
- Do not use `matrix` strategy in CI with single versions (causes version-suffixed check names)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
applyTo: "dotnet/**"
3+
---
4+
5+
# .NET sample conventions
6+
7+
## File-based apps
8+
9+
- Use `.cs` script files with `#:package` directives — do **not** create `.csproj` files
10+
- Run samples with `dotnet run {filename}.cs`
11+
- Use `#:property` for per-file MSBuild properties when needed
12+
13+
## Package management
14+
15+
- **`Directory.Packages.props`** (central): only packages used by **2+ samples** (e.g., `Microsoft.Azure.Cosmos`, `Newtonsoft.Json`). Use floating major versions (`Version="3.*"`).
16+
- **`#:package` in the `.cs` file**: packages used by **only one sample** (e.g., `Azure.Identity` is only in `001-connect-passwordless`). Use `#:package Foo@3.*` syntax.
17+
- When a second sample needs a previously single-use package, promote it to `Directory.Packages.props`.
18+
19+
## Build properties
20+
21+
- `Directory.Build.props` holds shared properties like `UserSecretsId`
22+
- `.editorconfig` enforces code style — do not remove or override it
23+
24+
## Authentication
25+
26+
- **00x connect samples**: `DefaultAzureCredential` via `Azure.Identity`. Store endpoint in user secrets (`dotnet user-secrets set --file {file}.cs "COSMOS_ENDPOINT" "..."`)
27+
- **All other samples**: key-based via `COSMOS_ENDPOINT` + `COSMOS_KEY` user secrets
28+
29+
## Code style
30+
31+
- Top-level statements (no `Main` method, no namespace)
32+
- Use `record` types for the `Product` data model
33+
- Use `var` where the type is obvious
34+
- Suffix async calls with `Async` — use `await` directly in top-level code
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
applyTo: "go/**"
3+
---
4+
5+
# Go sample conventions
6+
7+
## File structure
8+
9+
- Single `main.go` as the entry point
10+
- `go.mod` with module path `github.com/AzureCosmosDB/samples/go/{sample-name}`
11+
- Use standard `go get` versioning — do not pin exact versions
12+
13+
## Authentication
14+
15+
- Key-based: `COSMOS_ENDPOINT` + `COSMOS_KEY` environment variables
16+
- Use `azcosmos.NewKeyCredential(key)` and `azcosmos.NewClientWithKey(endpoint, cred, nil)`
17+
- Validate env vars at startup with `log.Fatalf(...)` if missing
18+
19+
## Code style
20+
21+
- Use a `Product` struct with JSON tags (`json:"id"`, etc.)
22+
- Use `json.Marshal` / `json.Unmarshal` for item serialization
23+
- Handle 409 Conflict errors with an `isConflict()` helper function:
24+
```go
25+
func isConflict(err error) bool {
26+
var responseErr *azcore.ResponseError
27+
return errors.As(err, &responseErr) && responseErr.StatusCode == http.StatusConflict
28+
}
29+
```
30+
- Use `context.Background()` for all Cosmos DB operations
31+
- Use `log.Fatalf` for fatal errors, `fmt.Printf` for output
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
applyTo: "python/**"
3+
---
4+
5+
# Python sample conventions
6+
7+
## File structure
8+
9+
- Single `app.py` as the entry point
10+
- `requirements.txt` for dependencies — use floating versions (e.g., `azure-cosmos>=4.9`)
11+
- Do **not** use `python-dotenv` — read config with `os.environ` directly
12+
13+
## Authentication
14+
15+
- Key-based: `COSMOS_ENDPOINT` + `COSMOS_KEY` environment variables
16+
- Validate env vars at startup with `raise ValueError(...)` if missing
17+
18+
## Code style
19+
20+
- Use `dict` literals for item data (no dataclasses or Pydantic models)
21+
- Use `PartitionKey` from `azure.cosmos` for container creation
22+
- Use parameterized queries with `@parameter` syntax for SQL queries
23+
- Print operations and results to stdout for verification
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
applyTo: "typescript/**"
3+
---
4+
5+
# TypeScript sample conventions
6+
7+
## File structure
8+
9+
- `package.json` with dependencies and scripts (`start`, `build`, `test`)
10+
- `tsconfig.json` with ES2022 target, Node module resolution, strict mode
11+
- Source `.ts` file as entry point
12+
- Use `tsx` for direct TypeScript execution (no compile step to run)
13+
- `.gitignore` for `node_modules/`, `dist/`, `.env`
14+
15+
## Dependencies
16+
17+
- Use caret ranges (`^`) in `package.json` — do not pin exact versions
18+
- Primary SDK: `@azure/cosmos`
19+
- Node.js 20+
20+
21+
## Authentication
22+
23+
- Key-based: `COSMOS_ENDPOINT` + `COSMOS_KEY` environment variables
24+
- Read with `process.env.COSMOS_ENDPOINT` — throw if missing
25+
- Do **not** use `dotenv` — put env var setup instructions in the readme
26+
27+
## Code style
28+
29+
- Use `interface` for the `Product` type (not `type` alias or `class`)
30+
- Use `async`/`await` throughout
31+
- Use ES module syntax (`import`/`export`)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
applyTo: ".github/workflows/**"
3+
---
4+
5+
# CI workflow conventions
6+
7+
## Workflow structure
8+
9+
- Single workflow file: `validate.yml` — do not split into per-language workflows
10+
- Trigger on both `push` to `main` AND `pull_request` to `main`
11+
- Set `permissions: contents: read` at the workflow level
12+
- Use `concurrency` group with `cancel-in-progress: true`
13+
14+
## Structure validation job
15+
16+
- Scan all language folders: `python`, `javascript`, `typescript`, `java`, `dotnet`, `go`
17+
- Enforce naming regex: `^[0-9]{3}-[a-z0-9]+(-[a-z0-9]+)*$`
18+
- Check for `readme.md` using **case-insensitive** find: `find "${sample}" -maxdepth 1 -type f -iname "readme.md"`
19+
- Do **not** use exact filename match (e.g., `[ -f "README.md" ]`) — this breaks on case variations
20+
21+
## Per-language build jobs
22+
23+
- Each language job runs independently and only scans its own folder
24+
- Exit cleanly (`exit 0`) if the language folder doesn't exist
25+
- Do **not** use `matrix` strategy with single versions — hardcode versions in `with:` to avoid version-suffixed check names
26+
- Use latest major action versions (`actions/checkout@v6`, `actions/setup-node@v6`, etc.)
27+
28+
## Language-specific rules
29+
30+
- **.NET**: handle both `.csproj`/`.sln` projects AND file-based `.cs` apps. Do **not** use `-q` quiet flag on `dotnet build` (it suppresses errors)
31+
- **Python**: `pip install -r requirements.txt` then `py_compile` or `pytest`
32+
- **Go**: `go build ./...` and `go test ./...`
33+
- **JavaScript/TypeScript**: scan both `javascript/` and `typescript/` folders. `npm install` + `npm test --if-present`
34+
35+
## Emulator testing
36+
37+
- Samples should be testable against the Azure Cosmos DB emulator
38+
- Do not require a live Azure account for CI validation

0 commit comments

Comments
 (0)