-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
CI: can filter jobs to run depending on modified files #22032
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
Open
mockersf
wants to merge
7
commits into
bevyengine:main
Choose a base branch
from
mockersf:next-gen-ci
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
01f5b03
add command to ci to list commands to run
mockersf 059b882
actions
mockersf da33741
linux dependencies
mockersf 2f0db57
run all jobs
mockersf e3fec47
lints
mockersf 2925698
some comments
mockersf a9182b6
more lints
mockersf 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,72 @@ | ||
| name: CI v2 | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| merge_group: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - release-* | ||
|
|
||
| env: | ||
| CARGO_TERM_COLOR: always | ||
| CARGO_INCREMENTAL: 0 | ||
| CARGO_PROFILE_TEST_DEBUG: 0 | ||
| CARGO_PROFILE_DEV_DEBUG: 0 | ||
| # If nightly is breaking CI, modify this variable to target a specific nightly version. | ||
| NIGHTLY_TOOLCHAIN: nightly | ||
| RUSTFLAGS: "-D warnings" | ||
|
|
||
| jobs: | ||
| # job to list the jobs to run on rust stable | ||
| stable-prepare: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| outputs: | ||
| jobs: ${{ steps.prepare.outputs.jobs }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| - name: Prepare CI jobs | ||
| id: prepare | ||
| run: | | ||
| echo "jobs=`cargo run -p ci -- what-to-run --trigger ${{ github.event_name }} --head ${{ github.head_ref }} --rust-version stable`" >> $GITHUB_OUTPUT | ||
|
|
||
| # run all the jobs on stable | ||
| stable-run: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| needs: [stable-prepare] | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| job: ${{ fromJson(needs.stable-prepare.outputs.jobs) }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/cache/restore@v4 | ||
| with: | ||
| key: ${{ runner.os }}-ci-runner--${{ hashFiles('tools/ci/Cargo.toml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-ci-runner--${{ hashFiles('tools/ci/Cargo.toml') }} | ||
| path: | | ||
| ~/.cargo/bin/ | ||
| ~/.cargo/registry/index/ | ||
| ~/.cargo/registry/cache/ | ||
| ~/.cargo/git/db/ | ||
| target/ | ||
| - name: Install Linux dependencies | ||
| uses: ./.github/actions/install-linux-deps | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| - name: Run CI job | ||
| run: | | ||
| ${{ matrix.job }} | ||
|
|
||
| # single job to report status, usable in branch protection rules | ||
| stable-status: | ||
| runs-on: ubuntu-latest | ||
| needs: [stable-run] | ||
| if: always() | ||
| steps: | ||
| - run: ${{!contains(needs.*.result, 'failure')}} |
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
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
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,86 @@ | ||
| use argh::{FromArgValue, FromArgs}; | ||
| use xshell::Shell; | ||
|
|
||
| use crate::args::Args; | ||
|
|
||
| /// Decides which jobs to run | ||
| #[derive(FromArgs)] | ||
| #[argh(subcommand, name = "what-to-run")] | ||
| pub struct WhatToRunCommand { | ||
| /// which event triggered this run | ||
| #[argh(option)] | ||
| trigger: Trigger, | ||
|
|
||
| /// which branch to diff against | ||
| #[argh(option)] | ||
| head: String, | ||
|
|
||
| /// select tasks for a specific version of rust | ||
| #[argh(option)] | ||
| #[expect(dead_code, reason = "todo")] | ||
| rust_version: RustVersion, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| enum RustVersion { | ||
| Stable, | ||
| Beta, | ||
| Nightly, | ||
| } | ||
|
|
||
| impl FromArgValue for RustVersion { | ||
| fn from_arg_value(value: &str) -> Result<Self, String> { | ||
| match value { | ||
| "stable" => Ok(RustVersion::Stable), | ||
| "beta" => Ok(RustVersion::Beta), | ||
| "nightly" => Ok(RustVersion::Nightly), | ||
| _ => Err(format!("Unknown rust version: {}", value)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| enum Trigger { | ||
| Schedule, | ||
| MergeQueue, | ||
| ChangeRequest, | ||
| PushToBranch, | ||
| } | ||
|
|
||
| impl FromArgValue for Trigger { | ||
| fn from_arg_value(value: &str) -> Result<Self, String> { | ||
| match value { | ||
| "schedule" => Ok(Trigger::Schedule), | ||
| "merge_group" => Ok(Trigger::MergeQueue), | ||
| "pull_request" => Ok(Trigger::ChangeRequest), | ||
| "push" => Ok(Trigger::PushToBranch), | ||
| _ => Err(format!("Unknown trigger: {}", value)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl WhatToRunCommand { | ||
| #[expect(clippy::print_stdout, reason = "goal is to print jobs to stdout")] | ||
| #[expect( | ||
| clippy::vec_init_then_push, | ||
| reason = "temp, will be better after the todo" | ||
| )] | ||
| pub fn run(&self, _sh: &Shell, _args: Args) { | ||
| let _diff = match self.trigger { | ||
| Trigger::Schedule | Trigger::PushToBranch => vec![], | ||
| Trigger::ChangeRequest | Trigger::MergeQueue => get_diff(&self.head), | ||
| }; | ||
|
|
||
| // TODO: filter jobs to run based on diff, trigger and rust version | ||
| let mut jobs = Vec::new(); | ||
| jobs.push(r#""cargo run -p ci -- test""#); | ||
| jobs.push(r#""cargo run -p ci -- lints""#); | ||
|
|
||
| println!("[{}]", jobs.join(", ")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit fragile. I assume this is so that there is no dependency on github ( |
||
| } | ||
| } | ||
|
|
||
| fn get_diff(_head: &str) -> Vec<String> { | ||
| // TODO: Implement diff logic between local state and head branch | ||
| vec![] | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit odd, maybe it's just temporary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could differentiate between shell and rust commands?