Repository navigation
53 lines (48 loc) · 2.35 KB
/
Copy pathdev_pr.yml
File metadata and controls
53 lines (48 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
# SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
name: dev_pr
concurrency:
group: ${{ github.repository }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.event.workflow_run.id }}-${{ github.workflow }}
cancel-in-progress: true
on:
workflow_run: # zizmor: ignore[dangerous-triggers] no checkout, only adds a label from API data
workflows: [API changes]
types: [completed]
jobs:
label-api-change:
name: Label API changes
if: >-
github.event_name == 'workflow_run' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-slim
permissions:
actions: read
pull-requests: write
steps:
# Never check out PR code in this job: it has permission to add labels.
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const run = context.payload.workflow_run;
if (run.path !== '.github/workflows/api_change.yml' || !run.head_repository) return;
const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, {
...context.repo, run_id: run.id, filter: 'latest', per_page: 100,
});
if (!jobs.some(job => job.steps?.some(step =>
step.name === 'API changes detected' && step.conclusion === 'success'))) return;
// Fork PRs may be missing from workflow_run.pull_requests. Resolve
// them through the API and ignore runs for an outdated PR head.
const prs = await github.paginate(github.rest.pulls.list, {
...context.repo, state: 'open',
head: run.head_repository.owner.login + ':' + run.head_branch,
per_page: 100,
});
for (const pr of prs) {
if (pr.head.sha !== run.head_sha ||
pr.head.repo?.full_name !== run.head_repository.full_name) continue;
await github.rest.issues.addLabels({
...context.repo, issue_number: pr.number, labels: ['api-change'],
});
}