Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ci.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MAX_PR_COMMITS=100
25 changes: 18 additions & 7 deletions .github/scripts/pr_comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

// @ts-check

const { getMergeableState, listOpenPulls } = require("./util");
const { getPullDetail, listOpenPulls } = require("./util");

const COMMENT_TAG = "<!-- pr-status-bot -->";
const MAX_COMMITS = Number.parseInt(process.env.MAX_PR_COMMITS, 10);
if (!Number.isFinite(MAX_COMMITS) || MAX_COMMITS <= 0) {
throw new Error(`MAX_PR_COMMITS must be a positive integer (got: ${process.env.MAX_PR_COMMITS})`);
}

/**
* @param {{ github: import("@actions/github").getOctokit, context: import("@actions/github").context }} params
Expand Down Expand Up @@ -53,8 +57,8 @@ async function buildFileCache({ github, owner, repo, pulls }) {
* @returns {Promise<string>}
*/
async function buildComment({ github, owner, repo, pr, pulls, fileCache }) {
const mergeableState = await getMergeableState({ github, owner, repo, prNumber: pr.number });
const isDirty = mergeableState === "dirty";
const detail = await getPullDetail({ github, owner, repo, prNumber: pr.number });
const isDirty = detail.mergeable_state === "dirty";

const ourFiles = new Set(fileCache.get(pr.number) || []);
const potentialConflicts = [];
Expand All @@ -70,14 +74,21 @@ async function buildComment({ github, owner, repo, pr, pulls, fileCache }) {
}
}

let banner;
let banner = "";
if (detail.commits > MAX_COMMITS) {
banner +=
"> [!CAUTION]\n" +
`> This pull request has more than ${MAX_COMMITS} commits. Large pull requests are difficult to review. Consider splitting\n` +
"> your changes into smaller pull requests. Some Action runners will terminate until this is resolved.\n\n";
}

if (isDirty) {
banner = "> [!CAUTION]\n> This pull request conflicts with the base branch. Please rebase and force-push.";
banner += "> [!CAUTION]\n> This pull request conflicts with the base branch. Please rebase and force-push.";
} else if (potentialConflicts.length > 0) {
banner =
banner +=
"> [!WARNING]\n> This pull request may have conflicts, please coordinate with the authors of these pull requests.";
} else {
banner = "> [!NOTE]\n> This pull request has no conflicts! 🎊 🎉 🎊";
banner += "> [!NOTE]\n> This pull request has no conflicts! 🎊 🎉 🎊";
}

let conflictSection = "";
Expand Down
8 changes: 4 additions & 4 deletions .github/scripts/pr_tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// @ts-check

const { getMergeableState, listOpenPulls } = require("./util");
const { getPullDetail, listOpenPulls } = require("./util");

const STALE_DAYS = 60;

Expand Down Expand Up @@ -56,13 +56,13 @@ module.exports = async ({ github, context }) => {
console.log(`PR #${pr.number}: removed stale`);
}

const mergeableState = await getMergeableState({ github, owner, repo, prNumber: pr.number });
const detail = await getPullDetail({ github, owner, repo, prNumber: pr.number });

if (mergeableState === "unknown") {
if (detail.mergeable_state === "unknown") {
continue;
}

const hasConflicts = mergeableState === "dirty";
const hasConflicts = detail.mergeable_state === "dirty";
const hasRebaseLabel = labels.includes(Labels.NEEDS_REBASE);

if (hasConflicts && !hasRebaseLabel) {
Expand Down
12 changes: 7 additions & 5 deletions .github/scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ async function listOpenPulls({ github, owner, repo }) {

/**
* @param {{ github: any, owner: string, repo: string, prNumber: number }} params
* @returns {Promise<string>}
* @returns {Promise<{ mergeable_state: string, commits: number }>}
*/
async function getMergeableState({ github, owner, repo, prNumber }) {
async function getPullDetail({ github, owner, repo, prNumber }) {
let commits = 0;
for (let i = 0; i < MERGEABLE_RETRIES; i++) {
const { data: detail } = await github.rest.pulls.get({
owner,
repo,
pull_number: prNumber,
});
commits = detail.commits;
if (detail.mergeable_state !== "unknown") {
return detail.mergeable_state;
return { mergeable_state: detail.mergeable_state, commits };
}
await sleep(MERGEABLE_DELAY_MS);
}
return "unknown";
return { mergeable_state: "unknown", commits };
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

module.exports = { BASE_BRANCH, getMergeableState, listOpenPulls, sleep };
module.exports = { BASE_BRANCH, getPullDetail, listOpenPulls, sleep };
62 changes: 45 additions & 17 deletions .github/workflows/build_msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ jobs:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-depth: 100

- name: Run pull request checks
if: github.event_name == 'pull_request'
shell: bash
run: |
source .github/ci.env
commits=${{ github.event.pull_request.commits }}
if [ "${commits}" -gt "${MAX_PR_COMMITS}" ]; then
echo "::error::PR has ${commits} commits (limit: ${MAX_PR_COMMITS})"
exit 1
fi

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.85.0
Expand Down Expand Up @@ -57,27 +68,23 @@ jobs:
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-deps-

- name: Restore CodeQL caches
id: codeql-cache
- name: Restore build artifacts
uses: actions/cache/restore@v5
with:
path: |
contrib/codeql/.cache
~/.codeql
key: codeql-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pkgs/**/*.rs', 'contrib/codeql/**/*.ql', 'contrib/codeql/**/*.qll', 'Cargo.lock') }}
path: target
key: cargo-build-msrv-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }}
restore-keys: |
cargo-build-msrv-${{ runner.os }}-${{ runner.arch }}-

- name: Manage CodeQL packs
uses: actions/cache@v5
with:
path: ~/.codeql
key: codeql-packs-${{ hashFiles('contrib/codeql/codeql-pack.lock.yml') }}

- name: Run linters
run: python3 contrib/lint/all_lint.py

- name: Save CodeQL caches
if: success() && steps.codeql-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: |
contrib/codeql/.cache
~/.codeql
key: codeql-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pkgs/**/*.rs', 'contrib/codeql/**/*.ql', 'contrib/codeql/**/*.qll', 'Cargo.lock') }}

- name: Check PR commit messages
if: github.event_name == 'pull_request'
run: >
Expand All @@ -86,11 +93,24 @@ jobs:

build:
name: Build and test
runs-on: ubuntu-24.04
runs-on: ubuntu-24.04-arm

steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1

- name: Run pull request checks
if: github.event_name == 'pull_request'
shell: bash
run: |
source .github/ci.env
commits=${{ github.event.pull_request.commits }}
if [ "${commits}" -gt "${MAX_PR_COMMITS}" ]; then
echo "::error::PR has ${commits} commits (limit: ${MAX_PR_COMMITS})"
exit 1
fi

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.85.0
Expand All @@ -104,6 +124,14 @@ jobs:
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-deps-

- name: Manage build artifacts
uses: actions/cache@v5
with:
path: target
key: cargo-build-msrv-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }}
restore-keys: |
cargo-build-msrv-${{ runner.os }}-${{ runner.arch }}-

- name: Build workspace
run: cargo build --workspace --features full,_internal

Expand Down
26 changes: 14 additions & 12 deletions .github/workflows/build_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ jobs:
with:
fetch-depth: 1

- name: Run pull request checks
if: github.event_name == 'pull_request'
shell: bash
run: |
source .github/ci.env
commits=${{ github.event.pull_request.commits }}
if [ "${commits}" -gt "${MAX_PR_COMMITS}" ]; then
echo "::error::PR has ${commits} commits (limit: ${MAX_PR_COMMITS})"
exit 1
fi

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
Expand All @@ -43,16 +54,16 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Restore cargo registry
uses: actions/cache/restore@v5
- name: Manage cargo registry
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-deps-

- name: Restore build artifacts
- name: Manage build artifacts
uses: actions/cache@v5
with:
path: target
Expand Down Expand Up @@ -88,12 +99,3 @@ jobs:

- name: Sanity check benchmarks
run: cargo bench -p ${{ inputs.package }} --features ${{ inputs.features }} --no-run

- name: Save cargo registry
if: always()
uses: actions/cache/save@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
26 changes: 14 additions & 12 deletions .github/workflows/build_stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,30 @@ jobs:
with:
fetch-depth: 1

- name: Run pull request checks
if: github.event_name == 'pull_request'
shell: bash
run: |
source .github/ci.env
commits=${{ github.event.pull_request.commits }}
if [ "${commits}" -gt "${MAX_PR_COMMITS}" ]; then
echo "::error::PR has ${commits} commits (limit: ${MAX_PR_COMMITS})"
exit 1
fi
Comment thread
coderabbitai[bot] marked this conversation as resolved.

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Restore cargo registry
uses: actions/cache/restore@v5
- name: Manage cargo registry
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-deps-

- name: Restore build artifacts
- name: Manage build artifacts
uses: actions/cache@v5
with:
path: target
Expand All @@ -67,12 +78,3 @@ jobs:

- name: Test package
run: cargo test -p ${{ inputs.package }} --features ${{ inputs.features }}

- name: Save cargo registry
if: always()
uses: actions/cache/save@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
7 changes: 5 additions & 2 deletions .github/workflows/pr_comment.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Comment on PRs

on:
push:
branches: [develop]
pull_request_target:
types: [synchronize, opened, reopened, closed]
schedule:
- cron: "0 6 * * 1"

concurrency:
group: ${{ github.workflow }}
Expand All @@ -24,6 +24,9 @@ jobs:
with:
fetch-depth: 0

- name: Read environment
run: cat .github/ci.env >> "$GITHUB_ENV"

- name: Update PR comments
uses: actions/github-script@v8
with:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/pr_tag.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Tag PRs

on:
push:
branches: [develop]
pull_request_target:
types: [synchronize, opened, reopened]
types: [synchronize, opened, reopened, closed]
schedule:
- cron: "0 6 * * 1"

Expand Down
Loading
Loading