-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Github][Docs] Add CI Best Practices Docs #129462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
boomanaiden154
merged 2 commits into
llvm:main
from
boomanaiden154:ci-best-practices-doc
Mar 3, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| ====================== | ||
| LLVM CI Best Practices | ||
| ====================== | ||
|
|
||
| Overview | ||
| ======== | ||
|
|
||
| This document contains a list of guidelines and best practices to use when | ||
| working on LLVM's CI systems. These are intended to keep our actions reliable, | ||
| consistent, and secure. | ||
|
|
||
| Github Actions Best Practices | ||
| ============================= | ||
|
|
||
| This section contains information on best practices/guidelines when working on | ||
| LLVM's github actions workflows. | ||
|
|
||
| Disabling Jobs In Forks | ||
| ----------------------- | ||
|
|
||
| There are many LLVM forks that exist, and we currently default to preventing | ||
| actions from running outside of the LLVM organization to prevent them from | ||
| running in forks. We default to this as actions running in forks are usually | ||
| not desired and only run by accident. In addition, many of our workflows | ||
| assume that they are operating within the main LLVM repository and break | ||
| otherwise. | ||
|
|
||
| Adhering to this best practice looks like adding the following to each of the | ||
| jobs specified within a workflow: | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| jobs: | ||
| <job name>: | ||
| if: github.repository_owner == 'llvm' | ||
|
|
||
| We choose to use ``github.repository_owner`` rather than ``github.repository`` | ||
| to enable these workflows to run in forks inside the LLVM organization such as | ||
| the ClangIR fork. | ||
|
|
||
| There are some exceptions to this rule where ``github.repository`` might be | ||
| used when it makes sense to limit a workflow to only running in the main | ||
| monorepo repository. These include things like the issue subscriber and | ||
| release tasks, which should not run anywhere else. | ||
|
|
||
| Hash Pinning Dependencies | ||
boomanaiden154 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ------------------------- | ||
|
|
||
| Github Actions allows the use of actions from other repositories as steps in | ||
| jobs. We take advantage of various actions for a variety of different tasks, | ||
| but especially tasks like checking out the repository, and | ||
| downloading/uploading build caches. These actions are typically versioned with | ||
| just a release, which looks like the following: | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| steps: | ||
| - name: Checkout LLVM | ||
| uses: actions/checkout@v4 | ||
|
|
||
| However, it is best practice to specify an exact commit SHA from which to pull | ||
| the action from, noting the version in a comment: | ||
|
|
||
| We plan on revisting this reccomendation once Github's immutable actions have | ||
| been rolled out as GA. | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| steps: | ||
| - name: Checkout LLVM | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
|
|
||
| This is beneficial for two reasons: reliability and security. Specifying an | ||
| exact SHA rather than just a major version ensures we end up running the same | ||
| action originally specified when the workflow as authored and/or updated, | ||
| and that no breaking changes sneak in from new versions of a workflow being | ||
| released. However, this effect could also be achieved by specifying an exact | ||
| dot release. The biggest reason to prefer hash pinned dependencies is security. | ||
| Release assets on Github are mutable, allowing an attacker to change the code | ||
| within a specific version of an action after the fact, potentially stealing | ||
| sensitive tokens and credentials. Hash pinning the dependencies prevents this | ||
| as the hash would change with the code. | ||
|
|
||
| Using Versioned Runner Images | ||
| ----------------------------- | ||
|
|
||
| Github actions allows the use of either specifically versioned runner images | ||
| (e.g., ``ubuntu-22.04``), or just the latest runner image | ||
| (e.g., ``ubuntu-latest``). It is best practice to use explicitly versioned | ||
| runner images. This prevents breakages when Github rolls the latest runner | ||
| image to a new version with potentially breaking changes, instead allowing us | ||
| to explicitly opt-in to using the new image when we have done sufficient | ||
| testing to ensure that our existing workflows work as expected in the new | ||
| environment. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.