Skip to content

Commit

Permalink
./github/scripts/auto-backport: align process to source available and…
Browse files Browse the repository at this point in the history
… more

Syncing a few changes that have already been implemented in scylla-pkg:

* remove condition for enterprise - since we are now running always from the `scylla-machine-image` repo
* run backport process from stable branch (which is `master`)
* improve conflict cases - by adding a comment to notify the PR owner
* pass label for each pull_request_target trigger

(cherry picked from commit 3d7c7b4)
  • Loading branch information
yaronkaikov committed Jan 5, 2025
1 parent 5233a3d commit ef5d05e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
26 changes: 17 additions & 9 deletions .github/scripts/auto-backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def parse_args():
parser.add_argument('--commits', default=None, type=str, help='Range of promoted commits.')
parser.add_argument('--pull-request', type=int, help='Pull request number to be backported')
parser.add_argument('--head-commit', type=str, required=is_pull_request(), help='The HEAD of target branch after the pull request specified by --pull-request is merged')
parser.add_argument('--label', type=str, required=is_pull_request(), help='Backport label name when --pull-request is defined')
return parser.parse_args()


Expand All @@ -47,7 +48,11 @@ def create_pull_request(repo, new_branch_name, base_branch_name, pr, backport_pr
)
logging.info(f"Pull request created: {backport_pr.html_url}")
backport_pr.add_to_assignees(pr.user)
backport_pr.add_to_labels("conflicts") if is_draft else None
if is_draft:
backport_pr.add_to_labels("conflicts")
pr_comment = f"@{pr.user.login} - This PR has conflicts, therefore it was moved to `draft` \n"
pr_comment += "Please resolve them and mark this PR as ready for review"
backport_pr.create_issue_comment(pr_comment)
logging.info(f"Assigned PR to original author: {pr.user}")
return backport_pr
except GithubException as e:
Expand Down Expand Up @@ -141,14 +146,17 @@ def main():
closed_prs = [pr]

for pr in closed_prs:
labels = [label.name for label in pr.labels]
backport_labels = [label for label in labels if backport_label_pattern.match(label)]
if promoted_label not in labels:
print(f'no {promoted_label} label: {pr.number}')
continue
if not backport_labels:
print(f'no backport label: {pr.number}')
continue
if args.pull_request:
backport_labels = [args.label]
else:
labels = [label.name for label in pr.labels]
backport_labels = [label for label in labels if backport_label_pattern.match(label)]
if promoted_label not in labels:
print(f'no {promoted_label} label: {pr.number}')
continue
if not backport_labels:
print(f'no backport label: {pr.number}')
continue
commits = get_pr_commits(repo, pr, stable_branch, start_commit)
logging.info(f"Found PR #{pr.number} with commit {commits} and the following labels: {backport_labels}")
for backport_label in backport_labels:
Expand Down
21 changes: 7 additions & 14 deletions .github/workflows/add-label-when-promoted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches:
- master
- next-*.*
- enterprise
pull_request_target:
types: [labeled]
branches: [master, next, enterprise]
branches: [master, next]

env:
DEFAULT_BRANCH: 'master'

jobs:
check-commit:
Expand All @@ -20,20 +22,11 @@ jobs:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Set Default Branch
id: set_branch
run: |
if [[ "${{ github.repository }}" == *enterprise* ]]; then
echo "stable_branch=enterprise" >> $GITHUB_OUTPUT
else
echo "stable_branch=master" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ env.stable_branch }}
ref: ${{ env.DEFAULT_BRANCH }}
token: ${{ secrets.AUTO_BACKPORT_TOKEN }}
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Set up Git identity
Expand All @@ -49,7 +42,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.AUTO_BACKPORT_TOKEN }}
run: python .github/scripts/search_commits.py --commits ${{ github.event.before }}..${{ github.sha }} --repository ${{ github.repository }} --ref ${{ github.ref }}
- name: Run auto-backport.py when promotion completed
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', steps.set_branch.outputs.stable_branch)
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', env.DEFAULT_BRANCH)
env:
GITHUB_TOKEN: ${{ secrets.AUTO_BACKPORT_TOKEN }}
run: python .github/scripts/auto-backport.py --repo ${{ github.repository }} --base-branch ${{ github.ref }} --commits ${{ github.event.before }}..${{ github.sha }}
Expand All @@ -68,4 +61,4 @@ jobs:
if: github.event_name == 'pull_request_target' && steps.check_label.outputs.backport_label == 'true' && github.event.pull_request.merged == true
env:
GITHUB_TOKEN: ${{ secrets.AUTO_BACKPORT_TOKEN }}
run: python .github/scripts/auto-backport.py --repo ${{ github.repository }} --base-branch ${{ github.ref }} --pull-request ${{ github.event.pull_request.number }} --head-commit ${{ github.event.pull_request.base.sha }}
run: python .github/scripts/auto-backport.py --repo ${{ github.repository }} --base-branch ${{ github.ref }} --pull-request ${{ github.event.pull_request.number }} --head-commit ${{ github.event.pull_request.base.sha }} --label ${{ github.event.label.name }}

0 comments on commit ef5d05e

Please sign in to comment.