mirror of
https://github.com/actions/runner-images.git
synced 2025-12-11 03:27:05 +00:00
Merge pull request #13329 from actions/gitpaulo/copilot-instructions
Add copilot instructions and update CONTRIBUTING.md with code style
This commit is contained in:
39
.github/copilot-instructions.md
vendored
Normal file
39
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# GitHub Copilot Instructions for Actions Runner Images Repository
|
||||
|
||||
## Scope and goals
|
||||
|
||||
- This repository serves as the source for building GitHub Actions runner and Azure DevOps agent images for Windows, Ubuntu, and macOS. You can find exact versions in the [Available Images](../README.md#available-images) section of README.md. Windows and Ubuntu images build on Azure infrastructure using Packer; macOS images use Anka virtualization.
|
||||
- Emphasize best practices for contributing to open-source projects, including code style, commit messages, and pull request etiquette.
|
||||
- Prefer clarity and correctness over creativity. If information is missing, ask clarifying questions or insert TODOs instead of guessing.
|
||||
|
||||
## Code and command instructions
|
||||
|
||||
- Follow the code style guide in [CONTRIBUTING.md](../CONTRIBUTING.md#code-style-guide) for Bash and PowerShell scripts, including naming conventions, file structure, and indentation rules.
|
||||
- Focus on re-using helpers when writing scripts. Windows, Linux and Ubuntu scripts have helper functions available to simplify installation and validation.
|
||||
- Always confirm versions and installation paths against existing toolset files and installation scripts.
|
||||
|
||||
## Output format
|
||||
|
||||
- Use GitHub Flavored Markdown only. Avoid raw HTML unless necessary.
|
||||
- One H1 (`#`) per page, followed by logical, sequential headings (`##`, `###`, …).
|
||||
- Use fenced code blocks with language identifiers (` ```bash `, ` ```json `, ` ```yaml `, etc.).
|
||||
- Use blockquote callouts for notes:
|
||||
> [!NOTE] Context or nuance
|
||||
> [!TIP] Helpful hint
|
||||
> [!WARNING] Risks or breaking changes
|
||||
> [!IMPORTANT] Critical requirement for functionality
|
||||
|
||||
## Style and tone
|
||||
|
||||
- Audience: Open-source contributors, GitHub Actions maintainers, and developers building custom runner images. Assume familiarity with CI/CD concepts, Packer, and basic infrastructure provisioning, but explain platform-specific details (Azure for Windows/Ubuntu, Anka for macOS) when relevant.
|
||||
- Voice: Second person ("you"), active voice, imperative for operational steps.
|
||||
- Be concise: short paragraphs and sentences. Prefer lists and step-by-steps, especially for operational procedures and troubleshooting.
|
||||
- Use inclusive, accessible language. Avoid idioms, sarcasm, and culturally specific references.
|
||||
- English: en-US (spelling, punctuation, and units).
|
||||
|
||||
## Safety and integrity
|
||||
|
||||
- Do not expose sensitive credentials (API tokens, Azure subscription IDs, etc.) in code examples.
|
||||
- Do not fabricate tool versions, installation paths, or software availability without verifying against toolset files or actual installation scripts.
|
||||
- Always call out assumptions and limitations explicitly, especially for changes affecting runner image behavior or software availability.
|
||||
- If ambiguous requests are made about image modifications, ask clarifying questions about target OS, tool versions, and compatibility requirements before proceeding.
|
||||
190
CONTRIBUTING.md
190
CONTRIBUTING.md
@@ -10,11 +10,18 @@ Contributions to this project are [released](https://help.github.com/articles/gi
|
||||
|
||||
Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project, you agree to abide by its terms.
|
||||
|
||||
## Contents
|
||||
|
||||
- [Submitting a pull request](#submitting-a-pull-request)
|
||||
- [Adding a new tool to an image](#adding-a-new-tool-to-an-image)
|
||||
- [Code style guide](#code-style-guide)
|
||||
|
||||
|
||||
## Submitting a pull request
|
||||
|
||||
1. [Fork][fork] and clone the repository.
|
||||
1. Create a new branch: `git checkout -b my-branch-name`.
|
||||
1. Make your changes, ensuring that they include steps to install, validate post-install, and update the software report (please see [How to add a new tool](CONTRIBUTING.md#how-to-add-a-new-tool) for details).
|
||||
1. Make your changes, ensuring that they include steps to install, validate post-install, and update the software report (please see [Adding a new tool to an image](#adding-a-new-tool-to-an-image) for details).
|
||||
1. Test your changes by [creating an image and deploying a VM](docs/create-image-and-azure-resources.md).
|
||||
1. Push to your fork and [submit a pull request][pr].
|
||||
|
||||
@@ -28,7 +35,7 @@ Here are a few things you can do that will increase the likelihood of your pull
|
||||
- Make sure that the tool satisfies the [Software Guidelines](README.md#software-guidelines).
|
||||
- Create an issue and get approval from us to add this tool to the image before creating the pull request.
|
||||
|
||||
## How to add a new tool
|
||||
## Adding a new tool to an image
|
||||
|
||||
### General rules
|
||||
|
||||
@@ -60,6 +67,185 @@ Use existing scripts such as [github-cli.sh](images/ubuntu/scripts/build/github-
|
||||
The macOS source lives in this repository and is available for everyone. However, the macOS image-generation CI doesn't support external contributions yet, so we are not able to accept pull requests for now.
|
||||
We are in the process of preparing the macOS CI to accept contributions. Until then, we appreciate your patience and ask that you continue to make tool requests by filing issues.
|
||||
|
||||
## Code style guide
|
||||
|
||||
The principles of clean code apply to all languages. The main points are:
|
||||
|
||||
- Use meaningful names for variables, functions, files, etc.
|
||||
- Keep functions short and simple.
|
||||
- Use comments to explain what the code does.
|
||||
- Use a consistent code style, naming convention, and file structure.
|
||||
|
||||
### File structure
|
||||
|
||||
- Each file should have a header with a title and a short description of the file.
|
||||
- Each file should have a newline at the end.
|
||||
- Use blank lines to separate logical blocks of code, but don't abuse blank lines:
|
||||
- Don't add a blank line in the beginning and end of a block or function.
|
||||
- Don't add blank lines between logically connected statements.
|
||||
- Avoid trailing whitespace.
|
||||
|
||||
### Bash scripts
|
||||
|
||||
#### Naming convention for bash scripts
|
||||
|
||||
- Use lowercase letters for variable names.
|
||||
- Use uppercase letters for constants.
|
||||
- Use underscores to separate words in variable names.
|
||||
|
||||
#### Bash script structure
|
||||
|
||||
Each script should start with the following shebang:
|
||||
|
||||
```bash
|
||||
#!/bin/bash -e
|
||||
```
|
||||
|
||||
> TODO: do we need to set pipefail?
|
||||
|
||||
This will make the script exit if any command fails.
|
||||
|
||||
After the shebang, add a header with the following format:
|
||||
|
||||
```bash
|
||||
################################################################################
|
||||
## File: <filename>
|
||||
## Desc: <short description of what the script does>
|
||||
################################################################################
|
||||
```
|
||||
|
||||
Then import helpers that are used in the script.
|
||||
|
||||
For Linux:
|
||||
|
||||
```bash
|
||||
source $HELPER_SCRIPTS/os.sh
|
||||
source $HELPER_SCRIPTS/install.sh
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
```
|
||||
|
||||
For macOS:
|
||||
|
||||
```bash
|
||||
source ~/utils/utils.sh
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> You don't need to import all helpers, only the ones that are used in the script.
|
||||
|
||||
After that, add the script code.
|
||||
|
||||
### Indentations and line breaks in bash scripts
|
||||
|
||||
- Use 4 spaces for indentation.
|
||||
- Use 1 space between `if`/`for`/`while` and `[[` and between `[[` and the condition.
|
||||
- Place `then`/`do` on the new line.
|
||||
- For short `if`/`for`/`while` statements, use the one-line format.
|
||||
- Break long pipelines using `\`.
|
||||
|
||||
### Other recommendations for bash scripts
|
||||
|
||||
- For command substitution, use `$()` instead of backticks.
|
||||
- Use `[[` instead of `[` for conditional expressions.
|
||||
- Prefer using long options instead of short keys, but there are exceptions, e.g.:
|
||||
- `tar -xzf`
|
||||
- `apt-get -yqq`
|
||||
- `curl -sSLf`
|
||||
- `wget -qO-`
|
||||
|
||||
### PowerShell scripts
|
||||
|
||||
#### Naming convention for PowerShell scripts
|
||||
|
||||
- Use camelCase for variable names.
|
||||
- Use uppercase letters for constants.
|
||||
- Use `Verb-Noun` and PascalCase for function names.
|
||||
|
||||
### PowerShell script structure
|
||||
|
||||
Each script should start with the following header:
|
||||
|
||||
```powershell
|
||||
################################################################################
|
||||
## File: <filename>
|
||||
## Desc: <short description of what the script does>
|
||||
################################################################################
|
||||
```
|
||||
|
||||
Then declare functions that are used in the script.
|
||||
|
||||
> TODO: do we need to set the error action preference and progress preference?
|
||||
>
|
||||
> ```powershell
|
||||
> $ErrorActionPreference = "Stop"
|
||||
> $ProgressPreference = "SilentlyContinue"
|
||||
> ```
|
||||
|
||||
For Linux and macOS, import helpers that are used in the script:
|
||||
|
||||
For Linux:
|
||||
|
||||
```powershell
|
||||
Import-Module "$env:HELPER_SCRIPTS/Tests.Helpers.psm1" -DisableNameChecking
|
||||
```
|
||||
|
||||
For macOS:
|
||||
|
||||
```powershell
|
||||
Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1"
|
||||
Import-Module "$env:HOME/image-generation/helpers/Xcode.Helpers.psm1" -DisableNameChecking
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> You don't need to import all helpers, only the ones that are used in the script.
|
||||
|
||||
After that, add the script code.
|
||||
|
||||
### Indentations and line breaks in PowerShell scripts
|
||||
|
||||
- Use 4 spaces for indentation.
|
||||
- Use 1 space between `if`/`elseif`/`foreach` and `(` but not between `(` and the condition.
|
||||
- Add a space before and after pipe `|` and redirection `>` operators.
|
||||
- Align properties in hash tables.
|
||||
- Use [1TBS](https://en.wikipedia.org/wiki/Indentation_style#Variant:_1TBS_(OTBS)) style for curly braces:
|
||||
- If block of statement is long, then place it on the new line, indent it, and add a closing curly brace on the new line.
|
||||
- If block of statement is short, then place it on the same line as the statement.
|
||||
|
||||
```powershell
|
||||
function Show-Example1 {
|
||||
$exampleVariable = Get-ChildItem $env:TEMP
|
||||
$exampleVariable | ForEach-Object {
|
||||
$itemName = $_.Name
|
||||
$itemPath = $_.FullName
|
||||
}
|
||||
}
|
||||
|
||||
$Example2 | Some-Function -Arguments @{Parameter1 = "Disabled"}
|
||||
```
|
||||
|
||||
- Avoid using aliases.
|
||||
- Break long pipelines using backticks or use [splatting](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.3):
|
||||
|
||||
```powershell
|
||||
# Instead of this
|
||||
Copy-Item -Path "test.txt" -Destination "test2.txt" -WhatIf
|
||||
|
||||
# you can use this
|
||||
$HashArguments = @{
|
||||
Path = "test.txt"
|
||||
Destination = "test2.txt"
|
||||
WhatIf = $true
|
||||
}
|
||||
Copy-Item @HashArguments
|
||||
```
|
||||
|
||||
When using backticks be extra careful with trailing whitespace as they can cause errors.
|
||||
|
||||
### Other recommendations for PowerShell scripts
|
||||
|
||||
- Verify exit codes of commands.
|
||||
- When writing a function, provide a docstring that describes what the function does.
|
||||
|
||||
## Resources
|
||||
|
||||
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
|
||||
|
||||
Reference in New Issue
Block a user