about summary refs log tree commit diff
path: root/src/ci/github-actions
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-15 21:28:25 +0000
committerbors <bors@rust-lang.org>2024-04-15 21:28:25 +0000
commitccfcd950b333fed046275dd8d54fe736ca498aa7 (patch)
tree78a1672bef04d3b93ff2d7b0c7f39890a91fce61 /src/ci/github-actions
parent3493a56529b3f972205f2cdda920132deef4b475 (diff)
parent72104e245bf2cc4ce3e29cf28ebee95b78bcd786 (diff)
downloadrust-ccfcd950b333fed046275dd8d54fe736ca498aa7.tar.gz
rust-ccfcd950b333fed046275dd8d54fe736ca498aa7.zip
Auto merge of #123451 - Kobzol:arbitrary-try-build, r=pietroalbini
CI: add a script for dynamically computing CI job matrix

It would be great if was easier to run specific CI workflows locally, and also to allow us to spawn a specific CI workflow by bors, to enable running arbitrary try builds. See discussion [here](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/CI.20workflows.20refactoring).

This PR is a first step in that direction.
- Moves the definition of CI runners and (for now) PR jobs into a separate `jobs.yml` file.
- Adds a simple Python script that reads the file, decides which jobs should be active for the current CI workflow, and prints them as JSON to their output.
- The PR job then reads this output and generates its job matrix based on it.

By moving the job definitions from `ci.yml` into a separate file, we can handle it programmatically, which should make it easier to both do local execution of CI jobs and also to do arbitrary try builds.
Diffstat (limited to 'src/ci/github-actions')
-rw-r--r--src/ci/github-actions/ci.yml29
-rw-r--r--src/ci/github-actions/jobs.yml50
2 files changed, 65 insertions, 14 deletions
diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml
index 9323bb093ad..de71b9f874f 100644
--- a/src/ci/github-actions/ci.yml
+++ b/src/ci/github-actions/ci.yml
@@ -341,9 +341,22 @@ concurrency:
   cancel-in-progress: true
 
 jobs:
+  # The job matrix for `calculate_matrix` is defined in src/ci/github-actions/jobs.yml.
+  calculate_matrix:
+    name: Calculate job matrix
+    runs-on: ubuntu-latest
+    outputs:
+      jobs: ${{ steps.jobs.outputs.jobs }}
+    steps:
+      - name: Checkout the source code
+        uses: actions/checkout@v4
+      - name: Calculate the CI job matrix
+        run: python3 src/ci/scripts/calculate-job-matrix.py >> $GITHUB_OUTPUT
+        id: jobs
   pr:
     <<: *base-ci-job
     name: PR - ${{ matrix.name }}
+    needs: [ calculate_matrix ]
     env:
       <<: [*shared-ci-variables, *public-variables]
       PR_CI_JOB: 1
@@ -351,20 +364,8 @@ jobs:
     continue-on-error: ${{ matrix.name == 'mingw-check-tidy' }}
     strategy:
       matrix:
-        include:
-          - name: mingw-check
-            <<: *job-linux-4c
-
-          - name: mingw-check-tidy
-            <<: *job-linux-4c
-
-          - name: x86_64-gnu-llvm-17
-            env:
-              ENABLE_GCC_CODEGEN: "1"
-            <<: *job-linux-16c
-
-          - name: x86_64-gnu-tools
-            <<: *job-linux-16c
+        # Check the `calculate_matrix` job to see how is the matrix defined.
+        include: ${{ fromJSON(needs.calculate_matrix.outputs.jobs) }}
 
   auto:
     <<: *base-ci-job
diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml
new file mode 100644
index 00000000000..7e89eef2670
--- /dev/null
+++ b/src/ci/github-actions/jobs.yml
@@ -0,0 +1,50 @@
+# This file contains definitions of CI job parameters that are loaded
+# dynamically in CI from ci.yml.
+# You *do not* need to re-run `src/tools/expand-yaml-anchors` when you
+# modify this file.
+shared_defs:
+  - &base-job
+    env: { }
+
+  - &job-linux-4c
+    os: ubuntu-20.04-4core-16gb
+    <<: *base-job
+
+  - &job-linux-8c
+    os: ubuntu-20.04-8core-32gb
+    <<: *base-job
+
+  - &job-linux-16c
+    os: ubuntu-20.04-16core-64gb
+    <<: *base-job
+
+  - &job-macos-xl
+    os: macos-13 # We use the standard runner for now
+    <<: *base-job
+
+  - &job-macos-m1
+    os: macos-14
+    <<: *base-job
+
+  - &job-windows-8c
+    os: windows-2019-8core-32gb
+    <<: *base-job
+
+  - &job-windows-16c
+    os: windows-2019-16core-64gb
+    <<: *base-job
+
+  - &job-aarch64-linux
+    os: [ self-hosted, ARM64, linux ]
+
+pr:
+  - name: mingw-check
+    <<: *job-linux-4c
+  - name: mingw-check-tidy
+    <<: *job-linux-4c
+  - name: x86_64-gnu-llvm-17
+    env:
+      ENABLE_GCC_CODEGEN: "1"
+    <<: *job-linux-16c
+  - name: x86_64-gnu-tools
+    <<: *job-linux-16c