forked from cloud-hypervisor/cloud-hypervisor
-
Notifications
You must be signed in to change notification settings - Fork 4
Implementation of flake bump auto approve and merge #154
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
Closed
pkr4711
wants to merge
13
commits into
cyberus-technology:gardenlinux-v51
from
pkr4711:auto-flake-bump
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0350f6a
ci: implementation of flake bump auto approve and merge
pkr4711 2a6fe8e
virtio-devices: introduce ActivationContext for device activation
posk-io 779ee4f
virtio-devices: switch driver_status to Arc<AtomicU8>
posk-io c2bbbcb
virtio-devices: wire driver_status to EpollHandler
posk-io 4bcb6a1
virtio-devices: net: handle corrupted requests with NEEDS_RESET
posk-io 2a11aba
virtio-devices: block: handle corrupted requests with NEEDS_RESET
posk-io 44f3360
virtio-devices: block: reject duplicate in-flight head_index
dgreid a2ca250
virtio-devices: block: track non-batch inflight reqs immediately
dgreid 1f9cc99
block: AlignedOperation owns its bounce buffer via Drop
dgreid b2e64bc
block: raw_async: reject batch atomically when SQ lacks capacity
dgreid ff770cc
build: Release v51.2
likebreath 738e153
vmm: clear restore snapshot after device creation
phip1611 91666d4
ci: implementation of flake bump auto approve and merge
pkr4711 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: Flake bump auto approve | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'flake.lock' | ||
| branches: | ||
| - gardenlinux | ||
|
|
||
| jobs: | ||
| gitlint: | ||
| name: Flake bump auto approve | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| fetch-depth: 0 | ||
| - name: Set up Python 3.11 | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.11" | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install --upgrade gitlint | ||
| # this rule checks the prerequisits and write the exit code in its output | ||
| - name: Lint git commit messages | ||
| id: gitlint | ||
| run: | | ||
| set +e | ||
| gitlint --commits origin/$GITHUB_BASE_REF.. -C .gitlint_auto_approve | ||
| code=$? | ||
| if [ $code -eq 0 ]; then | ||
| echo "this merge request is eligible for a flake bump auto approve and merge" | ||
| else | ||
| echo "this merge request will not be automatically approved." | ||
| fi | ||
| echo "exit_code=$code" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| # the following steps only run if gitlint run successful | ||
| - name: Create variables | ||
| if: steps.gitlint.outputs.exit_code == '0' | ||
| id: create_variable | ||
| run: | | ||
| REPO=$(echo ${GITHUB_REPOSITORY} | cut -f 2 -d '/') | ||
| OWNER=$(echo ${GITHUB_REPOSITORY} | cut -f 1 -d '/') | ||
| echo "repo=$REPO" >> "$GITHUB_OUTPUT" | ||
| echo "owner=$OWNER" >> "$GITHUB_OUTPUT" | ||
| - name: Generate token | ||
| if: steps.gitlint.outputs.exit_code == '0' && steps.create_variable.outputs.repo != '' | ||
| id: generate_token | ||
| uses: actions/create-github-app-token@v2 | ||
| with: | ||
| app-id: ${{ secrets.GH_AUTO_APPROVE_APP_ID }} | ||
| private-key: ${{ secrets.GH_AUTO_APPROVE_APP_PRIVATE_KEY }} | ||
| owner: ${{ steps.create_variable.outputs.owner }} | ||
| repositories: ${{ steps.create_variable.outputs.repo }} | ||
| - name: Merge Pull request | ||
| if: steps.gitlint.outputs.exit_code == '0' && steps.generate_token.outputs.token != '' | ||
| shell: bash | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | ||
| run: | | ||
| # GitHub CLI api | ||
| # https://cli.github.com/manual/gh_api | ||
| gh api \ | ||
| --method PUT \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "X-GitHub-Api-Version: 2026-03-10" \ | ||
| /repos/${GITHUB_REPOSITORY}/pulls/${{ github.event.number }}/merge \ | ||
| -f 'merge_method=rebase' | ||
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,15 @@ | ||
| [general] | ||
| extra-path=ci/gitlint/rules_auto_approve | ||
| regex-style-search=true | ||
| ignore=body-is-missing,body-max-line-length | ||
|
|
||
| # default 72 | ||
| [title-max-length] | ||
| line-length=72 | ||
|
|
||
| # Empty bodies are fine | ||
| [body-min-length] | ||
| min-length=0 | ||
|
|
||
| [UC-flake] | ||
| filepath=flake.lock |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,90 @@ | ||
| // Copyright (c) 2026 Meta Platforms, Inc. and affiliates. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause | ||
|
|
||
| use std::alloc::{Layout, alloc_zeroed, dealloc}; | ||
| use std::io; | ||
|
|
||
| use vm_memory::GuestAddress; | ||
|
|
||
| /// Owns an aligned bounce buffer used when a guest descriptor's host VA | ||
| /// does not meet the disk backend's alignment requirement. | ||
| #[derive(Debug)] | ||
| pub struct AlignedOperation { | ||
| data_addr: GuestAddress, | ||
| aligned_ptr: *mut u8, | ||
| size: usize, | ||
| layout: Layout, | ||
| } | ||
|
|
||
| impl AlignedOperation { | ||
| /// Allocate a zero-initialized buffer of `size` bytes aligned to | ||
| /// `alignment`. Returns `InvalidInput` if `size` is zero; | ||
| /// `alignment` must be a power of two and not exceed `isize::MAX` | ||
| /// after rounding up. | ||
| pub fn new(data_addr: GuestAddress, size: usize, alignment: usize) -> io::Result<Self> { | ||
| if size == 0 { | ||
| return Err(io::Error::new( | ||
| io::ErrorKind::InvalidInput, | ||
| "AlignedOperation requires a non-zero size", | ||
| )); | ||
| } | ||
| let layout = Layout::from_size_align(size, alignment) | ||
| .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?; | ||
| // SAFETY: size is non-zero (checked above) and Layout::from_size_align | ||
| // rejects alignments that are not a power of two or that overflow. | ||
| let aligned_ptr = unsafe { alloc_zeroed(layout) }; | ||
| if aligned_ptr.is_null() { | ||
| return Err(io::Error::last_os_error()); | ||
| } | ||
| Ok(Self { | ||
| data_addr, | ||
| aligned_ptr, | ||
| size, | ||
| layout, | ||
| }) | ||
| } | ||
|
|
||
| /// Gets the raw pointer to the aligned buffer. | ||
| pub fn as_mut_ptr(&mut self) -> *mut u8 { | ||
| self.aligned_ptr | ||
| } | ||
|
|
||
| /// Returns the aligned buffer as a slice. | ||
| pub fn as_bytes(&self) -> &[u8] { | ||
| // SAFETY: `new` allocates `size` bytes via alloc_zeroed (so they | ||
| // are initialized) and AlignedOperation owns the buffer | ||
| // exclusively. | ||
| unsafe { std::slice::from_raw_parts(self.aligned_ptr, self.size) } | ||
| } | ||
|
|
||
| /// Returns the aligned buffer as a mutable slice. | ||
| pub fn as_bytes_mut(&mut self) -> &mut [u8] { | ||
| // SAFETY: same invariant as as_bytes; &mut self rules out other | ||
| // simultaneous borrows. | ||
| unsafe { std::slice::from_raw_parts_mut(self.aligned_ptr, self.size) } | ||
| } | ||
|
|
||
| /// Returns the guest address for this op. | ||
| pub fn data_addr(&self) -> GuestAddress { | ||
| self.data_addr | ||
| } | ||
| } | ||
|
|
||
| impl Drop for AlignedOperation { | ||
| fn drop(&mut self) { | ||
| // SAFETY: `new` is the only constructor, and it stores a pointer | ||
| // returned by `alloc_zeroed` paired with the exact `layout` used | ||
| // for that allocation. Ownership has not escaped (the type is | ||
| // neither `Clone` nor `Copy`). | ||
| unsafe { | ||
| dealloc(self.aligned_ptr, self.layout); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // SAFETY: AlignedOperation owns its heap allocation exclusively (no Clone/ | ||
| // Copy, no shared aliases) and the allocation's lifetime is tied to the | ||
| // value's. Moving an AlignedOperation between threads transfers that | ||
| // ownership; the same rationale Box<T> uses for its Send impl. | ||
| unsafe impl Send for AlignedOperation {} |
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,43 @@ | ||
| # Flake bump auto approve | ||
|
|
||
| ## Description | ||
|
|
||
| We add a github workflow `Flake bump`. | ||
| First job of this workflow checks if a merge request contains only one commit which updates the `flake.lock` file. | ||
| If this condition is met the second job approve this merge request and automatically merge it. | ||
| The approval is done with a dedicated GitHubApp. | ||
|
|
||
| ## Install | ||
|
|
||
| * Follow this guide: https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app | ||
| * Create a GitHub app `auto-approve-app` in your GH organization | ||
| * github.com/github-organization/ -> Settings -> Developer Settings -> GitHub Apps -> New GitHub App | ||
| * Add a name and Homepage URL | ||
| * Add Repository Permissions | ||
| * Actions: RO | ||
| * Contents: RW | ||
| * Metadata: RO | ||
| * Pull Requests: RW | ||
| * Workflows: RW | ||
|
|
||
| * Install this app into your organization | ||
| * github.com/github-organization/ -> Settings -> Developer Settings -> GitHub Apps -> Select `auto-approve-app` -> Install App | ||
| * Only select repositories: | ||
| * repository-name | ||
|
|
||
| * Find app_id | ||
| * github.com/github-organization/ -> Settings -> Developer Settings -> GitHub Apps -> Select `auto-approve-app` | ||
| * you find the app_id in the `General` section | ||
|
|
||
| * Create app client secret | ||
| * github.com/github-organization/ -> Settings -> Developer Settings -> GitHub Apps -> Select `auto-approve-app` -> Client secrets | ||
| * The private key will be downloaded using your browser | ||
| * Save it in 1Password or vault | ||
|
|
||
| * Create two organization secrets: | ||
| * GH_AUTO_APPROVE_APP_ID | ||
| * GH_AUTO_APPROVE_APP_PRIVATE_KEY | ||
|
|
||
| * Add Github App `auto-approve-app` to your branch ruleset. | ||
| * github.com/github-organization/repository -> Settings -> Rules -> Rulesets -> rule name -> Bypass list -> Add bypass | ||
| * This allows the Github App `auto-approve-app` to merge the MRs even if other conditions of the ruleset are not met. |
Oops, something went wrong.
Oops, something went wrong.
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.
Just a general question. Is all of this needed? In another repository, I can auto-approve all PRs automatically with much less boilerplate:
https://github.com/phip1611/spectrum-analyzer/blob/1e93a225b066b06821d99fe042a87ef304bc7c1d/.github/workflows/dependabot-auto-merge.yml#L21
WDYT?
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.
No need to bikeshed here and perfectionize, just a general question.
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.
Any PR must be reviewed by 2 persons. If we want to auto approve & merge this PRs we need to define a bypass rule. This can be done with a dedicated GithubApp.
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.
Please look into the README.
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.
Perfect, thanks! :)
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.
I'll approve once rebased and when the PR targets the right branch again.