Skip to content
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

Generate CI matrix at runtime #428

Merged
merged 1 commit into from
Dec 18, 2024
Merged

Generate CI matrix at runtime #428

merged 1 commit into from
Dec 18, 2024

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Dec 17, 2024

Generates the CI matrix dynamically so we can run subsets on pull requests.

  • Moves the matrix definition out of GitHub workflows into a ci-targets.yaml file
  • Adds a ci-matrix.py script which parses the ci-targets.yaml file and outputs a JSON matrix
  • Updates the GitHub Actions workflows to use the script to generate a matrix dynamically
  • Uses the labels on the pull request to allow subsetting of the matrix

For example, you can run the matrix generator locally to see the label subsetting in action:

uv run ci-matrix.py --label arch:x86_64,platform:linux,libc:gnu,build:freethreaded,build:lto | jq
Reading inline script metadata from `ci-matrix.py`
{
  "include": [
    {
      "arch": "x86_64",
      "target_triple": "x86_64-unknown-linux-gnu",
      "platform": "linux",
      "libc": "gnu",
      "run": "true",
      "python": "3.13",
      "build_options": "freethreaded+pgo+lto"
    },
    {
      "arch": "x86_64",
      "target_triple": "x86_64_v2-unknown-linux-gnu",
      "platform": "linux",
      "arch_variant": "v2",
      "libc": "gnu",
      "run": "true",
      "python": "3.13",
      "build_options": "freethreaded+pgo+lto"
    },
    {
      "arch": "x86_64",
      "target_triple": "x86_64_v3-unknown-linux-gnu",
      "platform": "linux",
      "arch_variant": "v3",
      "libc": "gnu",
      "run": "true",
      "python": "3.13",
      "build_options": "freethreaded+pgo+lto"
    },
    {
      "arch": "x86_64",
      "target_triple": "x86_64_v4-unknown-linux-gnu",
      "platform": "linux",
      "arch_variant": "v4",
      "libc": "gnu",
      "python": "3.13",
      "build_options": "freethreaded+lto"
    }
  ]
}

I'll add labels for

  • platform:darwin
  • platform:linux
  • platform:windows
  • python:3.9
  • python:3.10
  • python:3.11
  • python:3.12
  • python:3.13
  • build:debug
  • build:pgo
  • build:lto
  • build:noopt
  • build:freethreaded
  • arch:x86_64
  • arch:aarch64
  • arch:armv7
  • arch:s390x
  • arch:ppc64le
  • arch:x86
  • libc:gnu
  • libc:musl

In a follow-up, I'll update this to use different runners in forks as noted in #426

@zanieb zanieb force-pushed the zb/gen-matrix-origin branch from 3ff0476 to 8047f17 Compare December 17, 2024 22:50
ci-matrix.py Outdated Show resolved Hide resolved
- pythonbuild
runs-on: depot-macos-14
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not realize this magic was possible. Otherwise I would have done this months ago.

Copy link
Member Author

@zanieb zanieb Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fairly new (though at least a year old). I'm glad you're into it!

@zanieb
Copy link
Member Author

zanieb commented Dec 18, 2024

Another note for the future, we could roll these into a single workflow. I don't know if it's worth it though. We can also use this to automatically split the matrix if we exceed the matrix job limit again (i.e., when adding new variants).

@zanieb zanieb marked this pull request as ready for review December 18, 2024 02:17
@zanieb
Copy link
Member Author

zanieb commented Dec 18, 2024

I want to validate that all the expected artifacts are here before merging, seems like a bit of a pain but I don't want to drop something?

edit: I validated these manually, oof.

@zanieb zanieb force-pushed the zb/gen-matrix-origin branch from 8047f17 to 0c9fee4 Compare December 18, 2024 02:48
@zanieb zanieb force-pushed the zb/gen-matrix-origin branch from 0c9fee4 to 9ed69cd Compare December 18, 2024 02:53
@zanieb zanieb merged commit f91adf9 into main Dec 18, 2024
42 checks passed
@zanieb zanieb deleted the zb/gen-matrix-origin branch December 18, 2024 02:56
@zanieb zanieb mentioned this pull request Dec 18, 2024
3 tasks
- name: Generate build matrix
id: set-matrix
run: |
uv run ci-matrix.py --platform darwin --labels "${{ steps.get-labels.outputs.labels }}" > matrix.json && echo "matrix=$(cat matrix.json)" >> $GITHUB_OUTPUT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need single quotes here to avoid shell injection/escape?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in, via the labels? I don't think people can create arbitrary labels in the organization, and I don't think commits on main could be targeted — but I'm happy to switch to single quotes to make it more robust anyway.

zanieb added a commit that referenced this pull request Dec 19, 2024
I noticed I accidentally reverted #426 in #428 😮‍💨
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants