Skip to content

Commit 12285bc

Browse files
heathsRickWinter
andauthored
Add Copilot instructions (Azure#2401)
* Add Copilot instructions * Update test generation guidelines in documentation * Add GitHub Copilot support and update instructions - Added GitHub Copilot extension to devcontainer and VSCode recommendations. - Updated Copilot instructions for clarity and improved guidance. - Enhanced VSCode settings to include Copilot message generation instructions. * Improve instructions, add perf-test prompt Replaces Azure#2601 * Comment the link Need to comment the link because of link verification rules --------- Co-authored-by: Rick Winter <[email protected]>
1 parent 762c98a commit 12285bc

File tree

10 files changed

+170
-5
lines changed

10 files changed

+170
-5
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
},
2727
"vscode": {
2828
"extensions": [
29-
"tamasfe.even-better-toml",
3029
"editorconfig.editorconfig",
30+
"GitHub.copilot",
3131
"rust-lang.rust-analyzer",
3232
"streetsidesoftware.code-spell-checker",
33+
"tamasfe.even-better-toml",
3334
"vadimcn.vscode-lldb"
3435
]
3536
}

.github/copilot-instructions.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Instructions
2+
3+
You are an expert Rust programmer. You write safe, efficient, maintainable, and well-tested code.
4+
5+
- Use an informal tone.
6+
- Do not be overly apologetic and focus on clear guidance.
7+
- If you cannot confidently generate code or other content, do not generate anything and ask for clarification.
8+
9+
## Code Generation
10+
11+
Use these instructions for test generation as well.
12+
13+
- Write readable and well-documented code that follows Rust style conventions:
14+
- Type names and variants are PascalCase.
15+
- Constants and statics are UPPER_SNAKE_CASE.
16+
- Field and function names are snake_case.
17+
- Parameter names are snake_case.
18+
- Crate and module names are snake_case.
19+
- Prioritize safety, efficiency, and correctness.
20+
- Respect Rust's ownership and borrowing rules.
21+
- Use short, descriptive names for fields, functions, parameters, and variables.
22+
- Handle errors using Rust's `Result` type using the `?` operator when the parent function returns a `Result`.
23+
- Avoid declaring lifetime parameters in public types or functions except when necessary.
24+
- Manage dependencies using `cargo`:
25+
- Dependencies should be defined in the root workspace's `Cargo.toml` file.
26+
- Crates under the `sdk/` folder should inherit those dependencies using `workspace = true` in their own `Cargo.toml` files.
27+
- Document all public APIs using a concise summary, followed by a blank line, then concise details about the API.
28+
- Public API documentation should use Rust's document comment syntax denoted by `///` and using markdown.
29+
- Use `clippy` to validate that generated code does not contain lint errors.
30+
- If you have trouble generating safe, efficient, maintainable, and lint-free code, insert a `TODO` comment describing what should happen.
31+
- All imported types, constants, functions, modules, and macros should be imported explicitly. Never import `*`.
32+
33+
## Test Generation
34+
35+
- Tests should be generated in a `tests` module defined within the module file being tested.
36+
- The `tests` module should be defined at the bottom after all the existing code to test.
37+
- If the `tests` module already exists, only add test functions and merge imports as needed.
38+
- The `tests` module should be conditioned on `#[cfg(test)]`.
39+
- The `tests` module should always import APIs from `super`.
40+
- Do not begin test function names with "test" unless necessary to disambiguate from the function being tested.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
applyTo: "**/CHANGELOG.md"
3+
---
4+
5+
- Summarize each change to public APIs in a single line for clarity and brevity.
6+
- If there are no changes to public APIs, do not make any changes to `CHANGELOG.md` files.
7+
- Place each change under the appropriate existing category header (e.g., "Features Added", "Breaking Changes", "Bugs Fixed", "Other Changes", etc.) found under the top-level `##` section.
8+
- Do not create new category headers; use only those already present in the file.
9+
- Ensure all entries are concise, accurate, and relevant to the release.
10+
- Follow the existing formatting and style conventions of the file.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
mode: "agent"
3+
description: "Generate a new performance test"
4+
---
5+
6+
You will generate a new performance (perf) test under the `sdk/{service-directory}/{crate-name}/benches` directory named ${input:benchName:bench_name} where:
7+
8+
- `{service-directory}` is the directory under [sdk] directory for the current ${file} e.g., `sdk/core`.
9+
- `{crate-name}` is the directory under `{service-directory}` for the current ${file} e.g., `sdk/core/azure_core`.
10+
11+
## Set up
12+
13+
These instructions only need to be done once. If changes described are already present, do not make the changes again.
14+
15+
- Under the `{crate-name}` directory, in `Cargo.toml` add `criterion.workspace = true` to the `[dev-dependencies]` section.
16+
- Under the `{crate-name}` directory, in `Cargo.toml` add the following section:
17+
18+
```toml
19+
[[bench]]
20+
name = "benchmarks"
21+
harness = false
22+
```
23+
24+
- Under the `{crate-name}` directory, add a `benches/benchmarks.rs` file.
25+
- Under the `{crate-name}` directory, copy [sdk/core/perf.yml] and change _only_ the following contents:
26+
- Change `ServiceDirectory` to match the `{service-directory}`.
27+
- Under the `{crate-name}` directory, copy [sdk/core/perf-tests.yml] and change _only_ the following contents:
28+
- Change `Service` to match the `{service-directory}`.
29+
- Change `Project` to match the `{crate-name}`.
30+
- Change the `PackageVersions` to replace `azure_core` with the `{crate-name}`.
31+
32+
## Adding a new perf test
33+
34+
For each new perf test:
35+
36+
- In the `{crate-name}/benches/benchmarks.rs` file:
37+
- Add a new function named ${input:benchName}. It should take a single parameter `c: &mut Criterion` and return nothing.
38+
- Generate a benchmark using the currently selected function in ${file} or specified client method name, if any.
39+
- Use [sdk/keyvault/azure_security_keyvault_keys/benches/benchmarks.rs] as an example.
40+
- If credentials are needed, import the `azure_core_test` crate and use `azure_core_test::credentials::from_env(None)` to get a `TokenCredential` for the client's `new` function.
41+
- Separate client initialization from the client method being run in a benchmark.
42+
- If `criterion_group` already exists, add the new perf test function to the end of the list of parameters or to the `target` parameter, if present.
43+
- In the `{crate-name}/perf-tests.yml` file:
44+
45+
- Add a top-level `Tests:` property if it does not already exist.
46+
- Add the following YAML under the `Tests:` property as a separate YAML array object:
47+
48+
```yaml
49+
- Test: ${input:benchName}
50+
Class: ${input:benchName}
51+
Arguments:
52+
- --sync
53+
```
54+
55+
- Client constructors should already return a `Result<Arc<Self>>` so call `expect("expected new client")` on the return.
56+
- Always pass `None` for the options parameter on a client constructor.

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"recommendations": [
3-
"tamasfe.even-better-toml",
43
"editorconfig.editorconfig",
4+
"GitHub.copilot",
55
"rust-lang.rust-analyzer",
66
"streetsidesoftware.code-spell-checker",
7+
"tamasfe.even-better-toml",
78
"vadimcn.vscode-lldb"
89
]
910
}

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
"azure-pipelines.1ESPipelineTemplatesSchemaFile": true,
33
"cSpell.enabled": true,
44
"editor.formatOnSave": true,
5+
"github.copilot.chat.commitMessageGeneration.instructions": [
6+
{
7+
"file": "doc/git-commit-instructions.md"
8+
}
9+
],
10+
"github.copilot.chat.pullRequestDescriptionGeneration.instructions": [
11+
{
12+
"file": "doc/github-pullrequest-instructions.md"
13+
}
14+
],
515
"markdownlint.config": {
616
"MD024": false
717
},

CONTRIBUTING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@
1212

1313
If you'd like to contribute to the Azure SDK for Rust, we recommend looking for issues with the following labels:
1414

15-
1615
- [good first issue](https://github.com/Azure/azure-sdk-for-rust/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) - These issues are a good starting point for new contributors since they should be relatively straightforward to address.
1716

1817
- [help wanted](https://github.com/Azure/azure-sdk-for-rust/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) - These issues are areas where we're actively seeking community contributions.
1918

2019
Further discussion on or pull requests for these issues is highly valued, and we encourage you to participate in the discussions or take on the tasks described in these issues.
2120

21+
## Using Copilot
22+
23+
This repository is [configured](https://code.visualstudio.com/docs/copilot/copilot-customization) to facilitate Copilot.
24+
In addition to [general instructions]<!--(.github/copilot-instructions.md)-->, you can find additional prompts in [.github/prompts] or type `#prompt` in Copilot.
25+
26+
To generate a new performance test, for example, you might prompt with:
27+
28+
```text
29+
Using #perf-test.prompt.md generate a perf test for SecretClient::get_secret.
30+
```
31+
2232
## Generated code
2333

2434
If you want to contribute to a file that is generated (the file is located in a `generated` subdirectory), the best approach is to open a PR on the TypeSpec specification since we cannot replace generated code that will be replaced when regenerated.

doc/git-commit-instructions.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Instructions for Git Commits
2+
3+
- Git commits should follow the standard form:
4+
5+
```markdown
6+
title of no more than 50 characters
7+
8+
multi-line descriptions
9+
```
10+
11+
- Summarize changes for a title of no more than 50 characters ideally, with a hard stop at 80 characters.
12+
- Descriptions can be multiple lines or even paragraphs.
13+
- Descriptions may contain markdown.
14+
- Descriptions should not repeat a lot of content already found in the changed files.
15+
- Summarize changes for each file if no more than 10 files are changed.
16+
- If multiple files contain the same changes, group them together when summarizing changes.
17+
- Try to reason why changes were made and not about what was changed.
18+
- If any added comments in changed files reference fixing an issue like "Fixes #1234" include that same text in the description.
19+
- If the branch name includes an issue number like "issue1234" include "Fixes #1234" in the description.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Instructions for GitHub Pull Requests
2+
3+
- GitHub Pull Requests should follow the standard form for Git commits:
4+
5+
```markdown
6+
title of no more than 50 characters
7+
8+
multi-line descriptions
9+
```
10+
11+
- Summarize changes for a title of no more than 50 characters ideally, with a hard stop at 80 characters.
12+
- Descriptions can be multiple lines or even paragraphs using markdown.
13+
- Descriptions may contain markdown.
14+
- Descriptions should not repeat a lot of content already found in the changed files.
15+
- Summarize changes for each file if no more than 10 files are changed.
16+
- If multiple files contain the same changes, group them together when summarizing changes.
17+
- Try to reason why changes were made and not about what was changed.
18+
- If any added comments in changed files reference fixing an issue like "Fixes #1234" include that same text in the description.
19+
- If multiple issues are fixed or resolved, include that same text separately for each issue like "Fixes #1234 and fixes #5678".

sdk/core/azure_core/benches/benchmarks.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ fn http_transport_test(c: &mut Criterion) {
5757
criterion_group! {
5858
name = benchmarks;
5959
config = Criterion::default();
60-
targets =url_parsing_benchmark,
61-
http_transport_test
60+
targets = url_parsing_benchmark, http_transport_test
6261
}
6362
criterion_main!(benchmarks);

0 commit comments

Comments
 (0)