diff --git a/.github/actions/list-pr/action.yml b/.github/actions/list-pr/action.yml new file mode 100644 index 0000000..a3fe0c5 --- /dev/null +++ b/.github/actions/list-pr/action.yml @@ -0,0 +1,90 @@ +name: 'List Pull Requests' +description: 'list and put output pull requests' +inputs: + owner: + description: 'The repository owner' + required: true + repository: + description: 'The repository name' + required: true + token: + description: 'The GitHub token used to create an authenticated client' + default: ${{ github.token }} + required: false + labels: + description: 'The labels on pull requests' + required: false + default: '' + hours: + description: 'Pull requests created within this many hours will be listed' + required: false + default: '24' +outputs: + prs: + description: 'Pull requests to be listed' + value: ${{ steps.list-pr.outputs.result }} +runs: + using: "composite" + steps: + # See https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests + - name: List PRs + uses: actions/github-script@v7 + id: list-pr + with: + github-token: ${{ inputs.token }} + result-encoding: string + script: | + const timeRange = parseInt("24") * 60 * 60 * 1000; + const sinceTime = new Date(Date.now() - timeRange).toISOString(); + const input_labels = ""; + const labels = input_labels + ? input_labels.split(/[,\n]/).map(label => label.trim()) + : []; + + const iterator = await github.paginate.iterator(github.rest.pulls.list, { + owner: "pytorch", + repo: "pytorch", + state: "open", + sort: "created", + direction: "desc", + per_page: 100, + }); + + const prs = []; + for await (const resp of iterator) { + const filtered_prs = resp.data.filter(pr => { + const hasLabel = labels.length === 0 + || labels.every(label => pr.labels.some(prLabel => prLabel.name === label)); + + const createdAt = new Date(pr.created_at); + const isWithinTimeRange = createdAt >= new Date(sinceTime); + + return hasLabel && isWithinTimeRange; + }); + + prs.push(...filtered_prs); + } + + if (prs.length > 0) { + const pr_urls = prs.map(pr => pr.html_url); + core.info(`prs: ${pr_urls.join("\n")}`); + } + + const result = prs.map(pr => ({ + pull_request: { + number: pr.number, + title: pr.title, + state: pr.state, + draft: pr.draft, + created_at: pr.created_at, + updated_at: pr.updated_at, + closed_at: pr.closed_at, + merged_at: pr.merged_at, + html_url: pr.html_url, + base: pr.base.ref, + head: pr.head.ref, + labels: pr.labels.map(label => label.name), + } + })); + + return JSON.stringify(result); diff --git a/.github/workflows/_ascend_npu_build_torch.yml b/.github/workflows/_ascend_npu_build_torch.yml index 53e3975..d9a367f 100644 --- a/.github/workflows/_ascend_npu_build_torch.yml +++ b/.github/workflows/_ascend_npu_build_torch.yml @@ -11,6 +11,10 @@ on: required: true type: string description: 'The docker image which will be used to build' + pr-number: + required: false + type: number + description: 'The number of pull request' ref: required: false type: string @@ -30,7 +34,7 @@ defaults: jobs: build: - name: build torch + name: build torch for ${{ inputs.pr-number && format('#{0}', inputs.pr-numer) || inputs.ref }} runs-on: ${{ inputs.runner }} container: image: ${{ inputs.image }} diff --git a/.github/workflows/ascend_npu_test.yml b/.github/workflows/ascend_npu_test.yml index db9b1f9..7721896 100644 --- a/.github/workflows/ascend_npu_test.yml +++ b/.github/workflows/ascend_npu_test.yml @@ -10,7 +10,6 @@ on: - '.github/workflows/_ascend_npu_build_torch_npu.yml' - '.github/workflows/_ascend_npu_ut.yml' - '.github/workflows/_ascend_npu_benchmark.yml' - - '.github/actions/**' - '.ci/**' - 'ascend_npu/**' - 'src/**' @@ -24,7 +23,6 @@ on: - '.github/workflows/_ascend_npu_build_torch_npu.yml' - '.github/workflows/_ascend_npu_ut.yml' - '.github/workflows/_ascend_npu_benchmark.yml' - - '.github/actions/**' - '.ci/**' - 'ascend_npu/**' - 'src/**' @@ -71,10 +69,10 @@ on: default: '/dev/davinci5' description: 'The device selected to run on' -# Only cancel the previous runs when triggered by a pull_request event or a repository_dispatch event +# Only cancel the previous runs when triggered by a pull_request event concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'repository_dispatch' }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: prepare: @@ -98,6 +96,7 @@ jobs: id: list-ref if: ${{ github.event_name == 'repository_dispatch' }} run: | + echo "pr_number=${{ github.event.client_payload.pull_request.number }}" >> $GITHUB_OUTPUT echo "ref=refs/pull/${{ github.event.client_payload.pull_request.number }}/merge" >> $GITHUB_OUTPUT build-torch: @@ -110,6 +109,7 @@ jobs: runner: ${{ needs.prepare.outputs.runner }} image: ${{ needs.prepare.outputs.image }} ref: ${{ needs.prepare.outputs.ref }} + pr-number: ${{ needs.prepare.outputs.pr-number }} build: name: Build torch_npu diff --git a/.github/workflows/dispatch-event.yml b/.github/workflows/dispatch-event.yml new file mode 100644 index 0000000..323babd --- /dev/null +++ b/.github/workflows/dispatch-event.yml @@ -0,0 +1,62 @@ +name: 'Dispatch PyTorch events' + +on: + schedule: + - cron: '0 12 * * *' + + workflow_dispatch: + inputs: + labels: + required: false + type: string + default: '' + description: 'The labels on pull requests' + hours: + required: false + type: number + default: 24 + description: 'Pull requests created within this many hours will be listed' + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + list-pr: + name: List PyTorch pull requests + runs-on: ubuntu-latest + outputs: + prs: ${{ steps.list-pr.outputs.prs }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + # List PRs created in the past 24 hours + - name: List PyTorch PRs + id: list-pr + uses: ./.github/actions/list-pr + with: + token: ${{ secrets.COSDT_BOT_TOKEN }} + owner: pytorch + repository: pytorch + labels: ${{ github.event.inputs.labels || '' }} + hours: ${{ github.event.inputs.hours || '24' }} + + dispatch-pr: + name: 'Dispatch PR event - #${{ matrix.data.pull_request.number }}' + runs-on: ubuntu-latest + needs: + - list-pr + strategy: + fail-fast: false + max-parallel: 1 + matrix: + data: ${{ fromJson(needs.list-pr.outputs.prs) }} + steps: + - name: Dispatch PR events to be out-of-tree test infra + uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ secrets.COSDT_BOT_TOKEN }} + repository: cosdt/pytorch-integration-tests + event-type: pytorch-pr-event + client-payload: ${{ toJson(matrix.data) }} diff --git a/.github/workflows/handle-pytorch-event.yml b/.github/workflows/redispatch-event.yml similarity index 92% rename from .github/workflows/handle-pytorch-event.yml rename to .github/workflows/redispatch-event.yml index 3b6e0ac..d3453c5 100644 --- a/.github/workflows/handle-pytorch-event.yml +++ b/.github/workflows/redispatch-event.yml @@ -1,4 +1,4 @@ -name: Handle events from PyTorch +name: 'Redispatch PyTorch events' on: repository_dispatch: @@ -6,7 +6,7 @@ on: jobs: redispatch-pr-event: - name: Redispatch PyTorch event + name: Redispatch PyTorch events runs-on: ubuntu-latest steps: - name: Checkout