Skip to content

Commit 47e1b51

Browse files
authored
Dispatch PyTorch PR events on schedule (#32)
1 parent 477cb24 commit 47e1b51

File tree

5 files changed

+163
-7
lines changed

5 files changed

+163
-7
lines changed

.github/actions/list-pr/action.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: 'List Pull Requests'
2+
description: 'list and put output pull requests'
3+
inputs:
4+
owner:
5+
description: 'The repository owner'
6+
required: true
7+
repository:
8+
description: 'The repository name'
9+
required: true
10+
token:
11+
description: 'The GitHub token used to create an authenticated client'
12+
default: ${{ github.token }}
13+
required: false
14+
labels:
15+
description: 'The labels on pull requests'
16+
required: false
17+
default: ''
18+
hours:
19+
description: 'Pull requests created within this many hours will be listed'
20+
required: false
21+
default: '24'
22+
outputs:
23+
prs:
24+
description: 'Pull requests to be listed'
25+
value: ${{ steps.list-pr.outputs.result }}
26+
runs:
27+
using: "composite"
28+
steps:
29+
# See https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests
30+
- name: List PRs
31+
uses: actions/github-script@v7
32+
id: list-pr
33+
with:
34+
github-token: ${{ inputs.token }}
35+
result-encoding: string
36+
script: |
37+
const timeRange = parseInt("24") * 60 * 60 * 1000;
38+
const sinceTime = new Date(Date.now() - timeRange).toISOString();
39+
const input_labels = "";
40+
const labels = input_labels
41+
? input_labels.split(/[,\n]/).map(label => label.trim())
42+
: [];
43+
44+
const iterator = await github.paginate.iterator(github.rest.pulls.list, {
45+
owner: "pytorch",
46+
repo: "pytorch",
47+
state: "open",
48+
sort: "created",
49+
direction: "desc",
50+
per_page: 100,
51+
});
52+
53+
const prs = [];
54+
for await (const resp of iterator) {
55+
const filtered_prs = resp.data.filter(pr => {
56+
const hasLabel = labels.length === 0
57+
|| labels.every(label => pr.labels.some(prLabel => prLabel.name === label));
58+
59+
const createdAt = new Date(pr.created_at);
60+
const isWithinTimeRange = createdAt >= new Date(sinceTime);
61+
62+
return hasLabel && isWithinTimeRange;
63+
});
64+
65+
prs.push(...filtered_prs);
66+
}
67+
68+
if (prs.length > 0) {
69+
const pr_urls = prs.map(pr => pr.html_url);
70+
core.info(`prs: ${pr_urls.join("\n")}`);
71+
}
72+
73+
const result = prs.map(pr => ({
74+
pull_request: {
75+
number: pr.number,
76+
title: pr.title,
77+
state: pr.state,
78+
draft: pr.draft,
79+
created_at: pr.created_at,
80+
updated_at: pr.updated_at,
81+
closed_at: pr.closed_at,
82+
merged_at: pr.merged_at,
83+
html_url: pr.html_url,
84+
base: pr.base.ref,
85+
head: pr.head.ref,
86+
labels: pr.labels.map(label => label.name),
87+
}
88+
}));
89+
90+
return JSON.stringify(result);

.github/workflows/_ascend_npu_build_torch.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
required: true
1212
type: string
1313
description: 'The docker image which will be used to build'
14+
pr-number:
15+
required: false
16+
type: number
17+
description: 'The number of pull request'
1418
ref:
1519
required: false
1620
type: string
@@ -30,7 +34,7 @@ defaults:
3034

3135
jobs:
3236
build:
33-
name: build torch
37+
name: build torch for ${{ inputs.pr-number && format('#{0}', inputs.pr-numer) || inputs.ref }}
3438
runs-on: ${{ inputs.runner }}
3539
container:
3640
image: ${{ inputs.image }}

.github/workflows/ascend_npu_test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
- '.github/workflows/_ascend_npu_build_torch_npu.yml'
1111
- '.github/workflows/_ascend_npu_ut.yml'
1212
- '.github/workflows/_ascend_npu_benchmark.yml'
13-
- '.github/actions/**'
1413
- '.ci/**'
1514
- 'ascend_npu/**'
1615
- 'src/**'
@@ -24,7 +23,6 @@ on:
2423
- '.github/workflows/_ascend_npu_build_torch_npu.yml'
2524
- '.github/workflows/_ascend_npu_ut.yml'
2625
- '.github/workflows/_ascend_npu_benchmark.yml'
27-
- '.github/actions/**'
2826
- '.ci/**'
2927
- 'ascend_npu/**'
3028
- 'src/**'
@@ -71,10 +69,10 @@ on:
7169
default: '/dev/davinci5'
7270
description: 'The device selected to run on'
7371

74-
# Only cancel the previous runs when triggered by a pull_request event or a repository_dispatch event
72+
# Only cancel the previous runs when triggered by a pull_request event
7573
concurrency:
7674
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
77-
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'repository_dispatch' }}
75+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
7876

7977
jobs:
8078
prepare:
@@ -98,6 +96,7 @@ jobs:
9896
id: list-ref
9997
if: ${{ github.event_name == 'repository_dispatch' }}
10098
run: |
99+
echo "pr_number=${{ github.event.client_payload.pull_request.number }}" >> $GITHUB_OUTPUT
101100
echo "ref=refs/pull/${{ github.event.client_payload.pull_request.number }}/merge" >> $GITHUB_OUTPUT
102101
103102
build-torch:
@@ -110,6 +109,7 @@ jobs:
110109
runner: ${{ needs.prepare.outputs.runner }}
111110
image: ${{ needs.prepare.outputs.image }}
112111
ref: ${{ needs.prepare.outputs.ref }}
112+
pr-number: ${{ needs.prepare.outputs.pr-number }}
113113

114114
build:
115115
name: Build torch_npu

.github/workflows/dispatch-event.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: 'Dispatch PyTorch events'
2+
3+
on:
4+
schedule:
5+
- cron: '0 12 * * *'
6+
7+
workflow_dispatch:
8+
inputs:
9+
labels:
10+
required: false
11+
type: string
12+
default: ''
13+
description: 'The labels on pull requests'
14+
hours:
15+
required: false
16+
type: number
17+
default: 24
18+
description: 'Pull requests created within this many hours will be listed'
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
list-pr:
26+
name: List PyTorch pull requests
27+
runs-on: ubuntu-latest
28+
outputs:
29+
prs: ${{ steps.list-pr.outputs.prs }}
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
# List PRs created in the past 24 hours
35+
- name: List PyTorch PRs
36+
id: list-pr
37+
uses: ./.github/actions/list-pr
38+
with:
39+
token: ${{ secrets.COSDT_BOT_TOKEN }}
40+
owner: pytorch
41+
repository: pytorch
42+
labels: ${{ github.event.inputs.labels || '' }}
43+
hours: ${{ github.event.inputs.hours || '24' }}
44+
45+
dispatch-pr:
46+
name: 'Dispatch PR event - #${{ matrix.data.pull_request.number }}'
47+
runs-on: ubuntu-latest
48+
needs:
49+
- list-pr
50+
strategy:
51+
fail-fast: false
52+
max-parallel: 1
53+
matrix:
54+
data: ${{ fromJson(needs.list-pr.outputs.prs) }}
55+
steps:
56+
- name: Dispatch PR events to be out-of-tree test infra
57+
uses: peter-evans/repository-dispatch@v3
58+
with:
59+
token: ${{ secrets.COSDT_BOT_TOKEN }}
60+
repository: cosdt/pytorch-integration-tests
61+
event-type: pytorch-pr-event
62+
client-payload: ${{ toJson(matrix.data) }}

.github/workflows/handle-pytorch-event.yml renamed to .github/workflows/redispatch-event.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Handle events from PyTorch
1+
name: 'Redispatch PyTorch events'
22

33
on:
44
repository_dispatch:
55
types: [pytorch-pr-event]
66

77
jobs:
88
redispatch-pr-event:
9-
name: Redispatch PyTorch event
9+
name: Redispatch PyTorch events
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout

0 commit comments

Comments
 (0)