Skip to content

Commit 99aa2a7

Browse files
djslyCopilot
andauthored
docs: update copilot instructions with shell script best practices (#8482)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 38f52b5 commit 99aa2a7

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

.github/copilot-instructions.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ The operational goals of this project are:
5353

5454
When making changes, reason whether the file is used in VHD building stage, or provision stage, or both. Make sure the changes are valid in its life stage. as an example, [windows-vhd-configuration.ps1](./vhdbuilder/packer/windows/windows-vhd-configuration.ps1) defines container images to be cached in VHD, while [configure-windows-vhd.ps1](./vhdbuilder/packer/windows/configure-windows-vhd.ps1) executes commands at provision time.
5555

56+
VHD cleanup steps in `cleanup-vhd.sh` must not silently ignore failures. Verify removal of security-sensitive components and fail the build if expected state is not achieved.
57+
5658
One way to debug / explore / just for fun is to run [e2e](./e2e/) tests. To run locally, follow the readme file under that folder.
5759

5860
The SRE guidelines ground other coding guidelines and practices.
@@ -68,12 +70,16 @@ The SRE guidelines ground other coding guidelines and practices.
6870

6971
### ShellScripts Guidelines
7072

71-
- use shellcheck for sanity checking
72-
- use ShellSpec for testing
73+
- use shellcheck for sanity checking**all shell scripts must pass the CI shellcheck gate** (`make validate-shell`). This enforces POSIX compliance even in `#!/bin/bash` scripts (e.g., use `[ ]` not `[[ ]]`, use `=` not `==` for string comparison). Use `# shellcheck disable=SCXXXX` inline comments only when necessary and with justification.
74+
- use ShellSpec for testing — all shell script changes should have corresponding tests in `spec/parts/linux/`
7375
- the shell scripts are used on both azure linux/mariner and ubuntu and cross platform portability is critical.
7476
- when using functions defined in other files, ensure it is sourced properly.
77+
- for scriptless provisioning compatibility, security hotfix functions must be defined in `cse_main.sh` (not sourced from other scripts) so they work standalone.
78+
- prefer simple single-purpose functions with positional args over complex data-driven designs with associative arrays or encoded strings.
79+
- use `isUbuntu()`, `isMarinerOrAzureLinux()`, and `isACL()` helper functions for OS detection instead of raw string comparisons.
7580
- use local variables rather than constants when their scoping allows for it.
7681
- avoid using variables declared inside another function, even they are visible. It is hard to reason and might introduce subtle bugs.
82+
- define functions at top-level scope, not nested inside other functions.
7783

7884
## Pull Request Review Guidelines
7985

0 commit comments

Comments
 (0)