Skip to content

Commit

Permalink
Add details about cross-platform considerations
Browse files Browse the repository at this point in the history
And which commands we can assume are available in our agents for each type of script
  • Loading branch information
AliSoftware committed Feb 19, 2025
1 parent 2063c52 commit a9204a5
Showing 1 changed file with 84 additions and 17 deletions.
101 changes: 84 additions & 17 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# Shell Script Documentation and Standards

## Documentation Requirements

When editing or creating files in /bin:
- Every shell script must have comprehensive header documentation
- Documentation must include: description, usage, parameters, examples
- For complex logic, provide detailed examples of different use cases
- Document all return values and exit codes
- Keep documentation up to date with any changes

## Shell Script Standards
For all bash shell scripts:
- Ensure compatibility with bash 3.2.57
- Follow shellcheck recommendations
- Use proper error handling and input validation
- Document cross-platform considerations

## Documentation Template

```bash
#!/bin/bash

Expand Down Expand Up @@ -43,18 +38,17 @@ For all bash shell scripts:
# [Description of exit codes and their meanings]
```

## Bash 3.2 Compatibility
Avoid using:
- Associative arrays (declare -A)
- mapfile/readarray command
- coproc keyword
- &> redirection operator
- case fall-through ;& operator
- case continue ;;& operator
- {a..b..c} brace expansion with step
- case-modification operators in ${parameter^}, ${parameter,}
## Shell Script Standards

For all bash shell scripts:
- Ensure compatibility with bash 3.2.57
- Follow shellcheck recommendations
- Use proper error handling and input validation
- Document cross-platform considerations

## Best Practices

For all bash shell scripts:
- Use set -e to exit on error
- Use set -u to error on undefined variables
- Use set -o pipefail for proper error handling
Expand All @@ -63,3 +57,76 @@ Avoid using:
- Use local variables in functions
- Include proper error handling
- Document all dependencies and requirements

## Bash 3.2 Compatibility

For all bash shell scripts, avoid using:
- Associative arrays (declare -A)
- mapfile/readarray command
- coproc keyword
- &> redirection operator
- case fall-through ;& operator
- case continue ;;& operator
- {a..b..c} brace expansion with step
- case-modification operators in ${parameter^}, ${parameter,}

## Cross-Platform Considerations

### For all bash shell scripts

- Use POSIX-compliant syntax and commands.
- Ensure the script is at least compatible with macOS and Linux.
- Make your best effort to make the bash scripts also compatible with Windows if possible, in addition to macOS and Linux. If it's not possible, document that in the script's header documentation.

### For bash scripts compatible with macOS and Linux

You can assume the following external commands/programs will be available on the machine the script is intended to run:

- jq
- curl
- aws
- git
- awk
- sed
- grep
- sort
- tee
- uname
- which
- xargs
- buildkite-agent
- chmod
- ssh-add
- ssh-keyscan

### For bash scripts related to iOS tools and intended to be run on macOS systems

You can assume the following external commands/programs will be available on the machine where the script is run, as long as you document in the script's header documentation that the script assumes it will run on a Mac CI agent:

- bundle
- gem
- pod
- ruby

### For bash scripts related to Android tools and intended to be run on Linux systems

You can assume the following external commands/programs will be available on the machine where the script is run, as long as you document in the script's header documentation that the script assumes it will run on an Android CI agent:

- gradle
- java

### For bash scripts related to Node.js tools and intended to be run on Linux

You can assume the following external commands/programs will be available on the machine where the script is run, as long as you document in the script's header documentation that the script assumes it will run on a Linux CI agent and use the `automattic/nvm-buildkite-plugin` to install the correct version of Node.js:

- npm
- node

### For any bash script that needs to have external commands/programs available not listed above

Make sure to document the list of required commands in the script's header documentation, under a "Requirements" section, with a wording like "This script needs to run on a CI agent which has the following external commands installed:".

### For bash scripts that use `shasum` or `sha256sum` directly

Always suggest using our `hash_file` helper command from this repository instead of using `shasum` or `sha256sum` directly, to ensure cross-platform compatibility.
For scripts using `sha1sum`, suggest to switch the implementation to use checksums provided by `hash_file` instead.

0 comments on commit a9204a5

Please sign in to comment.