Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/workflows/milestone-tag-assistant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
---
name: Milestone Tag Assistant
on: # yamllint disable-line rule:truthy
push:
branches:
- main
- v3-1-test

permissions:
# Those permissions are only active for workflow dispatch (only committers can trigger it) and workflow call
# Which is triggered automatically by "automatic-backport" push workflow (only when merging by committer)
# Branch protection prevents from pushing to the "code" branches
contents: write # zizmor: ignore[excessive-permissions]
pull-requests: write # zizmor: ignore[excessive-permissions]

jobs:
get-pr-info:
name: "Get PR information"
runs-on: ubuntu-latest
outputs:
should-run: ${{ steps.pr-info.outputs.should-run }}
pr-number: ${{ steps.pr-info.outputs.pr-number }}
pr-title: ${{ steps.pr-info.outputs.pr-title }}
pr-labels: ${{ steps.pr-info.outputs.pr-labels }}
base-branch: ${{ steps.pr-info.outputs.base-branch }}
merged-by: ${{ steps.pr-info.outputs.merged-by }}
steps:
# Adding a slight delay to allow GitHub's API to associate the merge commit with the PR.
# This is needed because GH has a consistency of 6-10+ seconds
# to process the commit and PR association after a merge based on some of our past runs.
- name: Add delay for GitHub to process PR merge
run: sleep 15

- name: Find PR information
id: pr-info
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { data: pullRequests } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: process.env.GITHUB_SHA
});

if (pullRequests.length === 0) {
console.log('⚠️ No pull request found for this commit.');
core.setOutput('should-run', 'false');
return;
}

const pr = pullRequests[0];

// Skip if PR already has a milestone
if (pr.milestone !== null) {
console.log(`PR #${pr.number} already has milestone: ${pr.milestone.title}`);
core.setOutput('should-run', 'false');
return;
}

const labels = pr.labels.map(label => label.name);

console.log(`Commit ${process.env.GITHUB_SHA} is associated with PR #${pr.number}`);
console.log(`Title: ${pr.title}`);
console.log(`Labels: ${JSON.stringify(labels)}`);
console.log(`Base branch: ${pr.base.ref}`);
console.log(`Merged by: ${pr.merged_by?.login || 'unknown'}`);

core.setOutput('should-run', 'true');
core.setOutput('pr-number', pr.number.toString());
core.setOutput('pr-title', pr.title);
core.setOutput('pr-labels', JSON.stringify(labels));
core.setOutput('base-branch', pr.base.ref);
core.setOutput('merged-by', pr.merged_by?.login || 'unknown');

set-milestone:
name: "Set milestone on merged PR"
runs-on: ubuntu-latest
needs: get-pr-info
if: ${{ needs.get-pr-info.outputs.should-run == 'true' }}

steps:
- name: "Checkout repository"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
# Always checkout main to ensure Breeze with set-milestone command is available
ref: main

- name: "Install Breeze"
uses: ./.github/actions/breeze
id: breeze

- name: Check criteria and set milestone
env:
GH_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ needs.get-pr-info.outputs.pr-number }}
PR_TITLE: ${{ needs.get-pr-info.outputs.pr-title }}
PR_LABELS: ${{ needs.get-pr-info.outputs.pr-labels }}
BASE_BRANCH: ${{ needs.get-pr-info.outputs.base-branch }}
MERGED_BY: ${{ needs.get-pr-info.outputs.merged-by }}
run: |
breeze ci set-milestone
4 changes: 2 additions & 2 deletions dev/README_AIRFLOW3_DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Do not treat PR approval (Green V) as exclusion approval.

## Merging PRs targeted for Airflow 3.X

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

It means that they should create a new PR where the original commit from main is cherry-picked and take care for resolving conflicts.
Expand All @@ -105,7 +105,7 @@ Note: tracking that the PRs merged as expected is the responsibility of committe
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.

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

This way release manager can verify (as usual) if all the "expected" PRs have
been backported and cherry-pick remaining PRS.
Expand Down
18 changes: 18 additions & 0 deletions dev/breeze/doc/08_ci_tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ These are all available flags of ``get-workflow-info`` command:
:width: 100%
:alt: Breeze ci get-workflow-info

Milestone Tag Assistant
-----------------------

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.

There are two cases for the current rules:
- **CI-related**: no need to set milestone
- **Patch release**: default to the **latest patch-release milestone**
- has a label like ``backport-to-v3-1-test``
- is merged to ``v3-1-test`` version branch

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.

.. image:: ./images/output_ci_set-milestone.svg
:target: https://raw.githubusercontent.com/apache/airflow/main/dev/breeze/images/output_milestone-tag-assistant.svg
:width: 100%
:alt: Milestone Tag Assistant

-----

Next step: Follow the `Release management tasks <09_release_management_tasks.rst>`_ guide to learn how
Expand Down
16 changes: 12 additions & 4 deletions dev/breeze/doc/images/output_ci.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_ci.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
74f8bcc9b81adac6a2af20bdccafa1fc
99f967b52c1e9d1e9ec92dbd4a30fe92
Loading
Loading