Skip to content

Commit 4a1b68e

Browse files
authored
sdk%fix(ci): narrow CodeQL cache, place 100 commit limit per PR, update codecov scope, restore MSRV artifact caching, try to fix false-fail due to concurrent runs (#9)
2 parents eb4f7e9 + b8a9eda commit 4a1b68e

11 files changed

Lines changed: 142 additions & 85 deletions

File tree

‎.github/ci.env‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MAX_PR_COMMITS=100

‎.github/scripts/pr_comment.js‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
// @ts-check
88

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

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

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

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

73-
let banner;
77+
let banner = "";
78+
if (detail.commits > MAX_COMMITS) {
79+
banner +=
80+
"> [!CAUTION]\n" +
81+
`> This pull request has more than ${MAX_COMMITS} commits. Large pull requests are difficult to review. Consider splitting\n` +
82+
"> your changes into smaller pull requests. Some Action runners will terminate until this is resolved.\n\n";
83+
}
84+
7485
if (isDirty) {
75-
banner = "> [!CAUTION]\n> This pull request conflicts with the base branch. Please rebase and force-push.";
86+
banner += "> [!CAUTION]\n> This pull request conflicts with the base branch. Please rebase and force-push.";
7687
} else if (potentialConflicts.length > 0) {
77-
banner =
88+
banner +=
7889
"> [!WARNING]\n> This pull request may have conflicts, please coordinate with the authors of these pull requests.";
7990
} else {
80-
banner = "> [!NOTE]\n> This pull request has no conflicts! 🎊 🎉 🎊";
91+
banner += "> [!NOTE]\n> This pull request has no conflicts! 🎊 🎉 🎊";
8192
}
8293

8394
let conflictSection = "";

‎.github/scripts/pr_tag.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// @ts-check
88

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

1111
const STALE_DAYS = 60;
1212

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

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

61-
if (mergeableState === "unknown") {
61+
if (detail.mergeable_state === "unknown") {
6262
continue;
6363
}
6464

65-
const hasConflicts = mergeableState === "dirty";
65+
const hasConflicts = detail.mergeable_state === "dirty";
6666
const hasRebaseLabel = labels.includes(Labels.NEEDS_REBASE);
6767

6868
if (hasConflicts && !hasRebaseLabel) {

‎.github/scripts/util.js‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,23 @@ async function listOpenPulls({ github, owner, repo }) {
3737

3838
/**
3939
* @param {{ github: any, owner: string, repo: string, prNumber: number }} params
40-
* @returns {Promise<string>}
40+
* @returns {Promise<{ mergeable_state: string, commits: number }>}
4141
*/
42-
async function getMergeableState({ github, owner, repo, prNumber }) {
42+
async function getPullDetail({ github, owner, repo, prNumber }) {
43+
let commits = 0;
4344
for (let i = 0; i < MERGEABLE_RETRIES; i++) {
4445
const { data: detail } = await github.rest.pulls.get({
4546
owner,
4647
repo,
4748
pull_number: prNumber,
4849
});
50+
commits = detail.commits;
4951
if (detail.mergeable_state !== "unknown") {
50-
return detail.mergeable_state;
52+
return { mergeable_state: detail.mergeable_state, commits };
5153
}
5254
await sleep(MERGEABLE_DELAY_MS);
5355
}
54-
return "unknown";
56+
return { mergeable_state: "unknown", commits };
5557
}
5658

57-
module.exports = { BASE_BRANCH, getMergeableState, listOpenPulls, sleep };
59+
module.exports = { BASE_BRANCH, getPullDetail, listOpenPulls, sleep };

‎.github/workflows/build_msrv.yml‎

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ jobs:
2121
- name: Checkout
2222
uses: actions/checkout@v6
2323
with:
24-
fetch-depth: 0
24+
fetch-depth: 100
25+
26+
- name: Run pull request checks
27+
if: github.event_name == 'pull_request'
28+
shell: bash
29+
run: |
30+
source .github/ci.env
31+
commits=${{ github.event.pull_request.commits }}
32+
if [ "${commits}" -gt "${MAX_PR_COMMITS}" ]; then
33+
echo "::error::PR has ${commits} commits (limit: ${MAX_PR_COMMITS})"
34+
exit 1
35+
fi
2536
2637
- name: Install Rust toolchain
2738
uses: dtolnay/rust-toolchain@1.85.0
@@ -57,27 +68,23 @@ jobs:
5768
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
5869
restore-keys: cargo-deps-
5970

60-
- name: Restore CodeQL caches
61-
id: codeql-cache
71+
- name: Restore build artifacts
6272
uses: actions/cache/restore@v5
6373
with:
64-
path: |
65-
contrib/codeql/.cache
66-
~/.codeql
67-
key: codeql-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pkgs/**/*.rs', 'contrib/codeql/**/*.ql', 'contrib/codeql/**/*.qll', 'Cargo.lock') }}
74+
path: target
75+
key: cargo-build-msrv-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }}
76+
restore-keys: |
77+
cargo-build-msrv-${{ runner.os }}-${{ runner.arch }}-
78+
79+
- name: Manage CodeQL packs
80+
uses: actions/cache@v5
81+
with:
82+
path: ~/.codeql
83+
key: codeql-packs-${{ hashFiles('contrib/codeql/codeql-pack.lock.yml') }}
6884

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

72-
- name: Save CodeQL caches
73-
if: success() && steps.codeql-cache.outputs.cache-hit != 'true'
74-
uses: actions/cache/save@v5
75-
with:
76-
path: |
77-
contrib/codeql/.cache
78-
~/.codeql
79-
key: codeql-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pkgs/**/*.rs', 'contrib/codeql/**/*.ql', 'contrib/codeql/**/*.qll', 'Cargo.lock') }}
80-
8188
- name: Check PR commit messages
8289
if: github.event_name == 'pull_request'
8390
run: >
@@ -86,11 +93,24 @@ jobs:
8693
8794
build:
8895
name: Build and test
89-
runs-on: ubuntu-24.04
96+
runs-on: ubuntu-24.04-arm
9097

9198
steps:
9299
- name: Checkout
93100
uses: actions/checkout@v6
101+
with:
102+
fetch-depth: 1
103+
104+
- name: Run pull request checks
105+
if: github.event_name == 'pull_request'
106+
shell: bash
107+
run: |
108+
source .github/ci.env
109+
commits=${{ github.event.pull_request.commits }}
110+
if [ "${commits}" -gt "${MAX_PR_COMMITS}" ]; then
111+
echo "::error::PR has ${commits} commits (limit: ${MAX_PR_COMMITS})"
112+
exit 1
113+
fi
94114
95115
- name: Install Rust toolchain
96116
uses: dtolnay/rust-toolchain@1.85.0
@@ -104,6 +124,14 @@ jobs:
104124
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
105125
restore-keys: cargo-deps-
106126

127+
- name: Manage build artifacts
128+
uses: actions/cache@v5
129+
with:
130+
path: target
131+
key: cargo-build-msrv-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }}
132+
restore-keys: |
133+
cargo-build-msrv-${{ runner.os }}-${{ runner.arch }}-
134+
107135
- name: Build workspace
108136
run: cargo build --workspace --features full,_internal
109137

‎.github/workflows/build_nightly.yml‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ jobs:
3434
with:
3535
fetch-depth: 1
3636

37+
- name: Run pull request checks
38+
if: github.event_name == 'pull_request'
39+
shell: bash
40+
run: |
41+
source .github/ci.env
42+
commits=${{ github.event.pull_request.commits }}
43+
if [ "${commits}" -gt "${MAX_PR_COMMITS}" ]; then
44+
echo "::error::PR has ${commits} commits (limit: ${MAX_PR_COMMITS})"
45+
exit 1
46+
fi
47+
3748
- name: Install Rust toolchain
3849
uses: dtolnay/rust-toolchain@master
3950
with:
@@ -43,16 +54,16 @@ jobs:
4354
- name: Install cargo-llvm-cov
4455
uses: taiki-e/install-action@cargo-llvm-cov
4556

46-
- name: Restore cargo registry
47-
uses: actions/cache/restore@v5
57+
- name: Manage cargo registry
58+
uses: actions/cache@v5
4859
with:
4960
path: |
5061
~/.cargo/registry
5162
~/.cargo/git
5263
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
5364
restore-keys: cargo-deps-
5465

55-
- name: Restore build artifacts
66+
- name: Manage build artifacts
5667
uses: actions/cache@v5
5768
with:
5869
path: target
@@ -88,12 +99,3 @@ jobs:
8899

89100
- name: Sanity check benchmarks
90101
run: cargo bench -p ${{ inputs.package }} --features ${{ inputs.features }} --no-run
91-
92-
- name: Save cargo registry
93-
if: always()
94-
uses: actions/cache/save@v5
95-
with:
96-
path: |
97-
~/.cargo/registry
98-
~/.cargo/git
99-
key: cargo-deps-${{ hashFiles('Cargo.lock') }}

‎.github/workflows/build_stable.yml‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,30 @@ jobs:
4242
with:
4343
fetch-depth: 1
4444

45+
- name: Run pull request checks
46+
if: github.event_name == 'pull_request'
47+
shell: bash
48+
run: |
49+
source .github/ci.env
50+
commits=${{ github.event.pull_request.commits }}
51+
if [ "${commits}" -gt "${MAX_PR_COMMITS}" ]; then
52+
echo "::error::PR has ${commits} commits (limit: ${MAX_PR_COMMITS})"
53+
exit 1
54+
fi
55+
4556
- name: Install Rust toolchain
4657
uses: dtolnay/rust-toolchain@stable
4758

48-
- name: Restore cargo registry
49-
uses: actions/cache/restore@v5
59+
- name: Manage cargo registry
60+
uses: actions/cache@v5
5061
with:
5162
path: |
5263
~/.cargo/registry
5364
~/.cargo/git
5465
key: cargo-deps-${{ hashFiles('Cargo.lock') }}
5566
restore-keys: cargo-deps-
5667

57-
- name: Restore build artifacts
68+
- name: Manage build artifacts
5869
uses: actions/cache@v5
5970
with:
6071
path: target
@@ -67,12 +78,3 @@ jobs:
6778

6879
- name: Test package
6980
run: cargo test -p ${{ inputs.package }} --features ${{ inputs.features }}
70-
71-
- name: Save cargo registry
72-
if: always()
73-
uses: actions/cache/save@v5
74-
with:
75-
path: |
76-
~/.cargo/registry
77-
~/.cargo/git
78-
key: cargo-deps-${{ hashFiles('Cargo.lock') }}

‎.github/workflows/pr_comment.yml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: Comment on PRs
22

33
on:
4-
push:
5-
branches: [develop]
64
pull_request_target:
75
types: [synchronize, opened, reopened, closed]
6+
schedule:
7+
- cron: "0 6 * * 1"
88

99
concurrency:
1010
group: ${{ github.workflow }}
@@ -24,6 +24,9 @@ jobs:
2424
with:
2525
fetch-depth: 0
2626

27+
- name: Read environment
28+
run: cat .github/ci.env >> "$GITHUB_ENV"
29+
2730
- name: Update PR comments
2831
uses: actions/github-script@v8
2932
with:

‎.github/workflows/pr_tag.yml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
name: Tag PRs
22

33
on:
4-
push:
5-
branches: [develop]
64
pull_request_target:
7-
types: [synchronize, opened, reopened]
5+
types: [synchronize, opened, reopened, closed]
86
schedule:
97
- cron: "0 6 * * 1"
108

0 commit comments

Comments
 (0)