Skip to content

Commit 0f25dce

Browse files
[Github][Docs] Add CI Best Practices Docs
This is something that Tom and I have discussed briefly for a while now, a doc that lists out all of the best practices we want to adhere to surrounding CI things along with their associated motivations/any other relevant info. This patch adds that doc along with three best practices surrounding Github Workflows that we try and adhere to (although more work needs to be done to get 100% adherance).
1 parent b24e140 commit 0f25dce

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

llvm/docs/CIBestPractices.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
======================
2+
LLVM CI Best Practices
3+
======================
4+
5+
Overview
6+
========
7+
8+
This document contains a list of guidelines and best practices to use when
9+
working on LLVM's CI systems. These are intended to keep our actions reliable,
10+
consistent, and secure.
11+
12+
Github Actions Best Practices
13+
=============================
14+
15+
This section contains information on best practices/guidelines when working on
16+
LLVM's github actions workflows.
17+
18+
Disabling Jobs In Forks
19+
-----------------------
20+
21+
There are many LLVM forks that exist, and we currently default to preventing
22+
actions from running outside of the LLVM organization to prevent them from
23+
running in forks. We default to this as actions running in forks are usually
24+
not desired and only run by accident. In addition, many of our workflows
25+
assume that they are operating within the main LLVM repository and break
26+
otherwise.
27+
28+
Adhering to this best practice looks like adding the following to each of the
29+
jobs specified within a workflow:
30+
31+
.. code-block:: yaml
32+
33+
jobs:
34+
<job name>:
35+
if: github.repository_owner == 'llvm'
36+
37+
We choose to use ``github.repository_owner`` rather than ``github.repository``
38+
to enable these workflows to run in forks inside the LLVM organization such as
39+
the ClangIR fork.
40+
41+
Hash Pinning Dependencies
42+
-------------------------
43+
44+
Github Actions allows the use of actions from other repositories as steps in
45+
jobs. We take advantage of various actions for a variety of different tasks,
46+
but especially tasks like checking out the repository, and
47+
downloading/uploading build caches. These actions are typically versioned with
48+
just a release, which looks like the following:
49+
50+
.. code-block:: yaml
51+
52+
steps:
53+
- name: Checkout LLVM
54+
uses: actions/checkout@v4
55+
56+
However, it is best practice to specify an exact commit SHA from which to pull
57+
the action from, noting the version in a comment:
58+
59+
.. code-block:: yaml
60+
61+
steps:
62+
- name: Checkout LLVM
63+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
64+
65+
This is beneficial for two reasons: reliability and security. Specifying an
66+
exact SHA rather than just a major version ensures we end up running the same
67+
action originally specified when the workflow as authored and/or updated,
68+
and that no breaking changes sneak in from new versions of a workflow being
69+
released. However, this effect could also be achieved by specifying an exact
70+
dot release. The biggest reason to prefer hash pinned dependencies is security.
71+
Release assets on Github are mutable, allowing an attacker to change the code
72+
within a specific version of an action after the fact, potentially stealing
73+
sensitive tokens and credentials. Hash pinning the dependencies prevents this
74+
as the hash would change with the code.
75+
76+
Using Versioned Runner Images
77+
-----------------------------
78+
79+
Github actions allows the use of either specifically versioned runner images
80+
(e.g., ``ubuntu-22.04``), or just the latest runner image
81+
(e.g., ``ubuntu-latest``). It is best practice to use explicitly versioned
82+
runner images. This prevents breakages when Github rolls the latest runner
83+
image to a new version with potentially breaking changes, instead allowing us
84+
to explicitly opt-in to using the new image when we have done sufficient
85+
testing to ensure that our existing workflows work as expected in the new
86+
environment.

llvm/docs/Reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LLVM and API reference documentation.
1414
BlockFrequencyTerminology
1515
BranchWeightMetadata
1616
Bugpoint
17+
CIBestPractices
1718
CommandGuide/index
1819
ConvergenceAndUniformity
1920
ConvergentOperations

0 commit comments

Comments
 (0)