Skip to content

Commit 3c664f5

Browse files
committed
ci: 更新工作流配置以支持取消相同提交的开发工作流运行
1 parent 1932f24 commit 3c664f5

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

.github/workflows/dev.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ on:
55
push:
66
branches:
77
- main
8+
tags-ignore:
9+
- "v*"
810
paths:
911
- "**.go"
1012
- "go.mod"
1113
- "go.sum"
1214

1315
jobs:
1416
builder:
17+
if: ${{ github.ref_type != 'tag' }}
1518
runs-on: ubuntu-latest
1619
steps:
1720
- name: Checkout

.github/workflows/release.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
permissions:
88
contents: write
99
packages: write
10+
actions: write
1011

1112
jobs:
1213
release:
@@ -18,6 +19,41 @@ jobs:
1819
submodules: true
1920
fetch-depth: 0
2021

22+
- name: Cancel same-commit dev workflow runs
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
const owner = context.repo.owner;
27+
const repo = context.repo.repo;
28+
const sha = context.sha;
29+
30+
const runs = await github.paginate(github.rest.actions.listWorkflowRuns, {
31+
owner,
32+
repo,
33+
workflow_id: 'dev.yaml',
34+
event: 'push',
35+
per_page: 100,
36+
});
37+
38+
const targets = runs.filter((run) =>
39+
run.head_sha === sha &&
40+
['queued', 'in_progress', 'waiting', 'pending', 'requested'].includes(run.status)
41+
);
42+
43+
if (targets.length === 0) {
44+
core.info(`No running dev workflow found for commit ${sha}.`);
45+
return;
46+
}
47+
48+
for (const run of targets) {
49+
core.info(`Cancelling dev run #${run.run_number} (id=${run.id}, status=${run.status})`);
50+
await github.rest.actions.cancelWorkflowRun({
51+
owner,
52+
repo,
53+
run_id: run.id,
54+
});
55+
}
56+
2157
- name: Set up Go
2258
uses: actions/setup-go@v5
2359
with:

0 commit comments

Comments
 (0)