Skip to content

Commit 856dce6

Browse files
jason810496Ankurdeewan
authored andcommitted
Add Milestone Tag Assistant (apache#61626)
* Add Milestone Tag Assistant * Refactor the set-milestone utils to breeze ci_group * Improves milestone assignment and adds tests for PR tagging Refines the logic for auto-assigning GitHub milestones to merged PRs, prioritizing backport labels, version branches, and latest open milestones for main branch merges. Introduces user notification comments when no suitable milestone is found and prompts manual action. Adds comprehensive tests covering milestone detection, assignment, and notification flows to ensure robust behavior and edge case handling. * Refactor milestone comment generation and improve tests for mention handling * Add CLI testing fixtures and enhance milestone comment generation in tests * Fix test scenarios * Add check to skip setting milestone if already assigned in Breeze * Remove merging into main logic * Update Milestone Tag Assistant documentation to clarify triggering conditions and rules for milestone assignment * Fix mypy error
1 parent ddcc1b5 commit 856dce6

15 files changed

Lines changed: 1237 additions & 18 deletions
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
---
19+
name: Milestone Tag Assistant
20+
on: # yamllint disable-line rule:truthy
21+
push:
22+
branches:
23+
- main
24+
- v3-1-test
25+
26+
permissions:
27+
# Those permissions are only active for workflow dispatch (only committers can trigger it) and workflow call
28+
# Which is triggered automatically by "automatic-backport" push workflow (only when merging by committer)
29+
# Branch protection prevents from pushing to the "code" branches
30+
contents: write # zizmor: ignore[excessive-permissions]
31+
pull-requests: write # zizmor: ignore[excessive-permissions]
32+
33+
jobs:
34+
get-pr-info:
35+
name: "Get PR information"
36+
runs-on: ubuntu-latest
37+
outputs:
38+
should-run: ${{ steps.pr-info.outputs.should-run }}
39+
pr-number: ${{ steps.pr-info.outputs.pr-number }}
40+
pr-title: ${{ steps.pr-info.outputs.pr-title }}
41+
pr-labels: ${{ steps.pr-info.outputs.pr-labels }}
42+
base-branch: ${{ steps.pr-info.outputs.base-branch }}
43+
merged-by: ${{ steps.pr-info.outputs.merged-by }}
44+
steps:
45+
# Adding a slight delay to allow GitHub's API to associate the merge commit with the PR.
46+
# This is needed because GH has a consistency of 6-10+ seconds
47+
# to process the commit and PR association after a merge based on some of our past runs.
48+
- name: Add delay for GitHub to process PR merge
49+
run: sleep 15
50+
51+
- name: Find PR information
52+
id: pr-info
53+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
with:
57+
script: |
58+
const { data: pullRequests } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
commit_sha: process.env.GITHUB_SHA
62+
});
63+
64+
if (pullRequests.length === 0) {
65+
console.log('⚠️ No pull request found for this commit.');
66+
core.setOutput('should-run', 'false');
67+
return;
68+
}
69+
70+
const pr = pullRequests[0];
71+
72+
// Skip if PR already has a milestone
73+
if (pr.milestone !== null) {
74+
console.log(`PR #${pr.number} already has milestone: ${pr.milestone.title}`);
75+
core.setOutput('should-run', 'false');
76+
return;
77+
}
78+
79+
const labels = pr.labels.map(label => label.name);
80+
81+
console.log(`Commit ${process.env.GITHUB_SHA} is associated with PR #${pr.number}`);
82+
console.log(`Title: ${pr.title}`);
83+
console.log(`Labels: ${JSON.stringify(labels)}`);
84+
console.log(`Base branch: ${pr.base.ref}`);
85+
console.log(`Merged by: ${pr.merged_by?.login || 'unknown'}`);
86+
87+
core.setOutput('should-run', 'true');
88+
core.setOutput('pr-number', pr.number.toString());
89+
core.setOutput('pr-title', pr.title);
90+
core.setOutput('pr-labels', JSON.stringify(labels));
91+
core.setOutput('base-branch', pr.base.ref);
92+
core.setOutput('merged-by', pr.merged_by?.login || 'unknown');
93+
94+
set-milestone:
95+
name: "Set milestone on merged PR"
96+
runs-on: ubuntu-latest
97+
needs: get-pr-info
98+
if: ${{ needs.get-pr-info.outputs.should-run == 'true' }}
99+
100+
steps:
101+
- name: "Checkout repository"
102+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
103+
with:
104+
persist-credentials: false
105+
# Always checkout main to ensure Breeze with set-milestone command is available
106+
ref: main
107+
108+
- name: "Install Breeze"
109+
uses: ./.github/actions/breeze
110+
id: breeze
111+
112+
- name: Check criteria and set milestone
113+
env:
114+
GH_TOKEN: ${{ github.token }}
115+
GITHUB_REPOSITORY: ${{ github.repository }}
116+
PR_NUMBER: ${{ needs.get-pr-info.outputs.pr-number }}
117+
PR_TITLE: ${{ needs.get-pr-info.outputs.pr-title }}
118+
PR_LABELS: ${{ needs.get-pr-info.outputs.pr-labels }}
119+
BASE_BRANCH: ${{ needs.get-pr-info.outputs.base-branch }}
120+
MERGED_BY: ${{ needs.get-pr-info.outputs.merged-by }}
121+
run: |
122+
breeze ci set-milestone

dev/README_AIRFLOW3_DEV.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Do not treat PR approval (Green V) as exclusion approval.
9595

9696
## Merging PRs targeted for Airflow 3.X
9797

98-
The committer who merges the PR is responsible for backporting the PRs that are 3.1 bug fixes (generally speaking)
98+
The committer who merges the PR **is responsible for backporting the PRs that are 3.1 bug fixes (generally speaking)**
9999
to `v3-1-test` (latest active branch we release bugfixes from). See next chapter to see what kind of changes we cherry-pick.
100100

101101
It means that they should create a new PR where the original commit from main is cherry-picked and take care for resolving conflicts.
@@ -105,7 +105,7 @@ Note: tracking that the PRs merged as expected is the responsibility of committe
105105
Committer may also request from PR author to raise 2 PRs one against `main` branch and one against `v3-1-test` prior to accepting the code change.
106106

107107
Mistakes happen, and such backport PR work might fall through cracks. Therefore, if the committer thinks
108-
that certain PRs should be backported, they should set 3.1.x milestone for them.
108+
that certain PRs should be backported, they **should set 3.1.x milestone for them.**
109109

110110
This way release manager can verify (as usual) if all the "expected" PRs have
111111
been backported and cherry-pick remaining PRS.

dev/breeze/doc/08_ci_tasks.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,24 @@ These are all available flags of ``get-workflow-info`` command:
132132
:width: 100%
133133
:alt: Breeze ci get-workflow-info
134134

135+
Milestone Tag Assistant
136+
-----------------------
137+
138+
The bot will only be triggered when a new push event occurs on the ``main`` or ``v3-1-test`` branches. It will leave a comment in the corresponding PR (similar to how the current ``automatic-backport`` bot behaves) and set the milestone if it matches the rules below, and it will skip if the PRs that already have a milestone set.
139+
140+
There are two cases for the current rules:
141+
- **CI-related**: no need to set milestone
142+
- **Patch release**: default to the **latest patch-release milestone**
143+
- has a label like ``backport-to-v3-1-test``
144+
- is merged to ``v3-1-test`` version branch
145+
146+
If it cannot determine which milestone should be added, it also adds a comment to remind the committer who merged the PR to add the corresponding milestone. This automation ensures that all PRs that should be included in the patch release are properly tagged, making the release manager's life easier.
147+
148+
.. image:: ./images/output_ci_set-milestone.svg
149+
:target: https://raw.githubusercontent.com/apache/airflow/main/dev/breeze/images/output_milestone-tag-assistant.svg
150+
:width: 100%
151+
:alt: Milestone Tag Assistant
152+
135153
-----
136154

137155
Next step: Follow the `Release management tasks <09_release_management_tasks.rst>`_ guide to learn how

dev/breeze/doc/images/output_ci.svg

Lines changed: 12 additions & 4 deletions
Loading
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3444c2578188542be84b14f53be8fa42
1+
99f967b52c1e9d1e9ec92dbd4a30fe92

0 commit comments

Comments
 (0)