Skip to content

Commit 5a5b569

Browse files
committed
add pr-cancel
1 parent a19812a commit 5a5b569

9 files changed

Lines changed: 84 additions & 20 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ jobs:
3636
uses: github/codeql-action/init@v4
3737
with:
3838
languages: ${{ matrix.language }}
39+
build-mode: manual
3940

40-
- name: Autobuild
41-
uses: github/codeql-action/autobuild@v4
41+
- name: Set up JDK 8
42+
uses: actions/setup-java@v5
43+
with:
44+
java-version: '8'
45+
distribution: 'temurin'
46+
47+
- name: Build
48+
run: ./gradlew build -x test --no-daemon
4249

4350
- name: Perform CodeQL Analysis
4451
uses: github/codeql-action/analyze@v4

.github/workflows/coverage-gen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
run: ./gradlew jacocoTestReport --no-daemon --no-build-cache
4545

4646
- name: Upload JaCoCo artifact
47-
uses: actions/upload-artifact@v5
47+
uses: actions/upload-artifact@v6
4848
with:
4949
name: jacoco-coverage
5050
path: |

.github/workflows/coverage-update-baseline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
run: ./gradlew jacocoTestReport --no-daemon --no-build-cache
4747

4848
- name: Upload coverage artifacts
49-
uses: actions/upload-artifact@v5
49+
uses: actions/upload-artifact@v6
5050
with:
5151
name: base-jacoco-xml
5252
path: |
@@ -72,7 +72,7 @@ jobs:
7272
fetch-depth: 0
7373

7474
- name: Download coverage artifacts
75-
uses: actions/download-artifact@v5
75+
uses: actions/download-artifact@v7
7676
with:
7777
name: base-jacoco-xml
7878
path: coverage-artifacts

.github/workflows/coverage-upload.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
persist-credentials: false
3131

3232
- name: Download coverage artifact
33-
uses: actions/download-artifact@v5
33+
uses: actions/download-artifact@v7
3434
with:
3535
name: jacoco-coverage
3636
path: coverage
@@ -48,17 +48,17 @@ jobs:
4848
const { data: pulls } = await github.rest.pulls.list({
4949
owner: context.repo.owner,
5050
repo: context.repo.repo,
51-
state: 'open',
52-
head: `${headOwner}:${headBranch}`
51+
state: 'all',
52+
head: `${headOwner}:${headBranch}`,
5353
});
54-
if (pulls.length > 0) {
55-
const pr = pulls[0];
54+
const pr = pulls.find((p) => p.head.sha === headSha);
55+
if (pr) {
5656
core.setOutput('pr_number', pr.number);
5757
core.setOutput('pr_sha', headSha);
5858
core.setOutput('pr_branch', headBranch);
5959
core.setOutput('base_sha', pr.base.sha);
6060
} else {
61-
core.setFailed(`No open pull request found for ${headOwner}:${headBranch}`);
61+
core.setFailed(`No pull request found for commit ${headSha}`);
6262
}
6363
6464
- name: Upload to Codecov

.github/workflows/math-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
5656
- name: Upload findings
5757
if: steps.check-math.outputs.math_found == 'true'
58-
uses: actions/upload-artifact@v5
58+
uses: actions/upload-artifact@v6
5959
with:
6060
name: math-usage-report
6161
path: math_usage.txt

.github/workflows/pr-build.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ on:
44
pull_request:
55
branches: [ 'master','develop', 'release_**' ]
66
types: [ opened, synchronize, reopened ]
7+
workflow_dispatch:
8+
inputs:
9+
job:
10+
description: 'Job to run: all / macos / ubuntu / rockylinux / debian11'
11+
required: false
12+
default: 'all'
713

814
concurrency:
9-
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1016
cancel-in-progress: true
1117

1218
jobs:
1319

1420
build-macos:
1521
name: Build macos26 (JDK ${{ matrix.java }} / ${{ matrix.arch }})
16-
#if: github.event.action != 'edited' && !failure() && !cancelled()
22+
if: ${{ github.event_name == 'pull_request' || inputs.job == 'all' || inputs.job == 'macos' }}
1723
runs-on: ${{ matrix.runner }}
1824
timeout-minutes: 60
1925
strategy:
@@ -50,7 +56,7 @@ jobs:
5056

5157
build-ubuntu:
5258
name: Build ubuntu24 (JDK 17 / aarch64)
53-
#if: github.event.action != 'edited' && !failure() && !cancelled()
59+
if: ${{ github.event_name == 'pull_request' || inputs.job == 'all' || inputs.job == 'ubuntu' }}
5460
runs-on: ubuntu-24.04-arm
5561
timeout-minutes: 60
5662

@@ -80,7 +86,7 @@ jobs:
8086

8187
docker-build-rockylinux:
8288
name: Build rockylinux (JDK 8 / x86_64)
83-
#if: github.event.action != 'edited' && !failure() && !cancelled()
89+
if: ${{ github.event_name == 'pull_request' || inputs.job == 'all' || inputs.job == 'rockylinux' }}
8490
runs-on: ubuntu-latest
8591
timeout-minutes: 60
8692

@@ -123,7 +129,7 @@ jobs:
123129

124130
docker-build-debian11:
125131
name: Build debian11 (JDK 8 / x86_64)
126-
#if: github.event.action != 'edited' && !failure() && !cancelled()
132+
if: ${{ github.event_name == 'pull_request' || inputs.job == 'all' || inputs.job == 'debian11' }}
127133
runs-on: ubuntu-latest
128134
timeout-minutes: 60
129135

.github/workflows/pr-cancel.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Cancel PR Workflows on Close
2+
3+
on:
4+
pull_request:
5+
types: [ closed ]
6+
7+
permissions:
8+
actions: write
9+
10+
jobs:
11+
cancel:
12+
name: Cancel In-Progress Workflows
13+
if: github.event.pull_request.merged == false
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Cancel PR Build and System Test
17+
uses: actions/github-script@v8
18+
with:
19+
script: |
20+
const workflows = ['pr-build.yml', 'system-test.yml', 'codeql.yml', 'coverage-waiting.yml'];
21+
const headSha = context.payload.pull_request.head.sha;
22+
const prNumber = context.payload.pull_request.number;
23+
24+
for (const workflowId of workflows) {
25+
for (const status of ['in_progress', 'queued']) {
26+
const runs = await github.paginate(
27+
github.rest.actions.listWorkflowRuns,
28+
{
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
workflow_id: workflowId,
32+
status,
33+
event: 'pull_request',
34+
per_page: 100,
35+
},
36+
(response) => response.data.workflow_runs
37+
);
38+
39+
for (const run of runs) {
40+
const isTargetPr = !run.pull_requests?.length || run.pull_requests.some((pr) => pr.number === prNumber);
41+
if (run.head_sha === headSha && isTargetPr) {
42+
await github.rest.actions.cancelWorkflowRun({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
run_id: run.id,
46+
});
47+
console.log(`Cancelled ${workflowId} run #${run.id} (${status})`);
48+
}
49+
}
50+
}
51+
}

.github/workflows/pr-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123

124124
- name: Upload Checkstyle reports
125125
if: failure()
126-
uses: actions/upload-artifact@v5
126+
uses: actions/upload-artifact@v6
127127
with:
128128
name: checkstyle-reports
129129
path: |

.github/workflows/system-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
types: [ opened, synchronize, reopened ]
99

1010
concurrency:
11-
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1212
cancel-in-progress: true
1313

1414
jobs:
@@ -85,7 +85,7 @@ jobs:
8585
8686
- name: Upload FullNode log
8787
if: always()
88-
uses: actions/upload-artifact@v5
88+
uses: actions/upload-artifact@v6
8989
with:
9090
name: fullnode-log
9191
path: java-tron/fullnode.log

0 commit comments

Comments
 (0)