From 255c55647d3ea37094d2d065e937755010fc9e66 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 2 Jul 2025 19:31:30 +0530 Subject: [PATCH 01/94] Update auto_pr_creation_manifest.yml --- .../workflows/auto_pr_creation_manifest.yml | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/auto_pr_creation_manifest.yml b/.github/workflows/auto_pr_creation_manifest.yml index 4500e41..3d3cc15 100644 --- a/.github/workflows/auto_pr_creation_manifest.yml +++ b/.github/workflows/auto_pr_creation_manifest.yml @@ -19,41 +19,41 @@ jobs: ref: develop token: ${{ secrets.RDKCM_RDKE }} - - name: Checkout Manifest Repository - uses: actions/checkout@v4 - with: - repository: 'rdkcentral/rdke-middleware-generic-manifest' - path: 'manifest_repo' - token: ${{ secrets.RDKCM_RDKE }} + # - name: Checkout Manifest Repository + # uses: actions/checkout@v4 + # with: + # repository: 'rdkcentral/rdke-middleware-generic-manifest' + # path: 'manifest_repo' + # token: ${{ secrets.RDKCM_RDKE }} - - name: Update Git Config - env: - BOT_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} - run: | - cd manifest_repo - git config user.name "bot" - git config user.email "$BOT_EMAIL" - cd .. + # - name: Update Git Config + # env: + # BOT_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} + # run: | + # cd manifest_repo + # git config user.name "bot" + # git config user.email "$BOT_EMAIL" + # cd .. - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' + # - name: Set up Python + # uses: actions/setup-python@v4 + # with: + # python-version: '3.x' - - name: Install Python dependencies - run: | - python3 -m pip install --upgrade pip - pip install requests PyGithub GitPython + # - name: Install Python dependencies + # run: | + # python3 -m pip install --upgrade pip + # pip install requests PyGithub GitPython - - name: Run the update script - env: - GITHUB_TOKEN: ${{ secrets.RDKCM_RDKE }} - GITHUB_ORG: 'rdkcentral' - MANIFEST_REPO_PATH: ${{ github.workspace }}/manifest_repo - MANIFEST_REPO_NAME: 'rdkcentral/rdke-middleware-generic-manifest' - PR_NUMBER: ${{ github.event.pull_request.number }} - BASE_BRANCH: ${{ github.event.pull_request.base.ref }} - run: | - cd manifest_repo - python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_manifest.py - cd .. + # - name: Run the update script + # env: + # GITHUB_TOKEN: ${{ secrets.RDKCM_RDKE }} + # GITHUB_ORG: 'rdkcentral' + # MANIFEST_REPO_PATH: ${{ github.workspace }}/manifest_repo + # MANIFEST_REPO_NAME: 'rdkcentral/rdke-middleware-generic-manifest' + # PR_NUMBER: ${{ github.event.pull_request.number }} + # BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + # run: | + # cd manifest_repo + # python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_manifest.py + # cd .. From 696a266170814cd7aee95219a1779fcdb05635ad Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 09:27:42 +0530 Subject: [PATCH 02/94] Create auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 59 +++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/auto_pr_creation_meta.yml diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml new file mode 100644 index 0000000..0ad7b6c --- /dev/null +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -0,0 +1,59 @@ +name: Update Meta on Component Repo Merge + +on: + workflow_call: + secrets: + RDKCM_RDKE: + required: true + +jobs: + auto_pr_creation_manifest: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + steps: + - name: Checkout build_tools_workflows code + uses: actions/checkout@v4 + with: + repository: rdkcentral/build_tools_workflows + path: 'tools' + ref: develop + token: ${{ secrets.RDKCM_RDKE }} + + # - name: Checkout Manifest Repository + # uses: actions/checkout@v4 + # with: + # repository: 'rdkcentral/rdke-middleware-generic-manifest' + # path: 'manifest_repo' + # token: ${{ secrets.RDKCM_RDKE }} + + # - name: Update Git Config + # env: + # BOT_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} + # run: | + # cd manifest_repo + # git config user.name "bot" + # git config user.email "$BOT_EMAIL" + # cd .. + + # - name: Set up Python + # uses: actions/setup-python@v4 + # with: + # python-version: '3.x' + + # - name: Install Python dependencies + # run: | + # python3 -m pip install --upgrade pip + # pip install requests PyGithub GitPython + + # - name: Run the update script + # env: + # GITHUB_TOKEN: ${{ secrets.RDKCM_RDKE }} + # GITHUB_ORG: 'rdkcentral' + # MANIFEST_REPO_PATH: ${{ github.workspace }}/manifest_repo + # MANIFEST_REPO_NAME: 'rdkcentral/rdke-middleware-generic-manifest' + # PR_NUMBER: ${{ github.event.pull_request.number }} + # BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + # run: | + # cd manifest_repo + # python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_manifest.py + # cd .. From c5aaecc1f7a0bd9bfc256b14733c1ec288395e89 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 09:29:22 +0530 Subject: [PATCH 03/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 0ad7b6c..f33636c 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -9,14 +9,14 @@ on: jobs: auto_pr_creation_manifest: runs-on: ubuntu-latest - if: github.event.pull_request.merged == true + #if: github.event.pull_request.merged == true steps: - name: Checkout build_tools_workflows code uses: actions/checkout@v4 with: repository: rdkcentral/build_tools_workflows path: 'tools' - ref: develop + ref: RDKEMW-4778 token: ${{ secrets.RDKCM_RDKE }} # - name: Checkout Manifest Repository From b4e64369bb8b0d2d45593618241967833da8002b Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 10:26:45 +0530 Subject: [PATCH 04/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index f33636c..2453f9a 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -19,12 +19,13 @@ jobs: ref: RDKEMW-4778 token: ${{ secrets.RDKCM_RDKE }} - # - name: Checkout Manifest Repository - # uses: actions/checkout@v4 - # with: - # repository: 'rdkcentral/rdke-middleware-generic-manifest' - # path: 'manifest_repo' - # token: ${{ secrets.RDKCM_RDKE }} + - name: Checkout Manifest Repository + uses: actions/checkout@v4 + with: + repository: 'rdkcentral/meta-rdk-video' + path: 'maeta_repo' + ref: RDKEMW-4778 + token: ${{ secrets.RDKCM_RDKE }} # - name: Update Git Config # env: From 39765dfc7c75d6954be5ac532368b812ab2ae6b0 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 10:29:41 +0530 Subject: [PATCH 05/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 38 ++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 2453f9a..e9854f0 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -7,7 +7,7 @@ on: required: true jobs: - auto_pr_creation_manifest: + auto_pr_creation_meta: runs-on: ubuntu-latest #if: github.event.pull_request.merged == true steps: @@ -19,32 +19,32 @@ jobs: ref: RDKEMW-4778 token: ${{ secrets.RDKCM_RDKE }} - - name: Checkout Manifest Repository + - name: Checkout Meta Repository uses: actions/checkout@v4 with: repository: 'rdkcentral/meta-rdk-video' - path: 'maeta_repo' + path: 'meta_repo' ref: RDKEMW-4778 token: ${{ secrets.RDKCM_RDKE }} - # - name: Update Git Config - # env: - # BOT_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} - # run: | - # cd manifest_repo - # git config user.name "bot" - # git config user.email "$BOT_EMAIL" - # cd .. + - name: Update Git Config + env: + BOT_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} + run: | + cd meta_repo + git config user.name "bot" + git config user.email "$BOT_EMAIL" + cd .. - # - name: Set up Python - # uses: actions/setup-python@v4 - # with: - # python-version: '3.x' + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' - # - name: Install Python dependencies - # run: | - # python3 -m pip install --upgrade pip - # pip install requests PyGithub GitPython + - name: Install Python dependencies + run: | + python3 -m pip install --upgrade pip + pip install requests PyGithub GitPython # - name: Run the update script # env: From f47b6470102299aabcc79643824c94ec135edc24 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 10:52:12 +0530 Subject: [PATCH 06/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index e9854f0..61b01d9 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -46,15 +46,15 @@ jobs: python3 -m pip install --upgrade pip pip install requests PyGithub GitPython - # - name: Run the update script - # env: - # GITHUB_TOKEN: ${{ secrets.RDKCM_RDKE }} - # GITHUB_ORG: 'rdkcentral' - # MANIFEST_REPO_PATH: ${{ github.workspace }}/manifest_repo - # MANIFEST_REPO_NAME: 'rdkcentral/rdke-middleware-generic-manifest' - # PR_NUMBER: ${{ github.event.pull_request.number }} - # BASE_BRANCH: ${{ github.event.pull_request.base.ref }} - # run: | - # cd manifest_repo - # python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_manifest.py - # cd .. + - name: Run the update script + env: + GITHUB_TOKEN: ${{ secrets.RDKCM_RDKE }} + GITHUB_ORG: 'rdkcentral' + META_REPO_PATH: ${{ github.workspace }}/meta_repo + META_REPO_NAME: 'rdkcentral/meta-rdk-video' + PR_NUMBER: 173 + BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + run: | + cd meta_repo + python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_meta.py + cd .. From cbb8a789044d58d03a16c343aa46c9b228cc0fdd Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 10:53:21 +0530 Subject: [PATCH 07/94] Create auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 288 ++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 build_health_check_workflow_scripts/auto_pr_generation_meta.py diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py new file mode 100644 index 0000000..8e01f51 --- /dev/null +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -0,0 +1,288 @@ +import os +import requests +import github +from github import Github +import xml.etree.ElementTree as ET +from git import Repo +import re +from git import GitCommandError +import sys +import time + + +#Fetch all merged PRs linked to a specific issue. +def fetch_merge_commits(owner, repo, pr_number, github_token): + + url = 'https://api.github.com/graphql' + repo_without_org = repo.split('/')[-1] + headers = {'Authorization': 'Bearer {}'.format(github_token)} + query = """ + query($repoOwner: String!, $repoName: String!, $prNumber: Int!) { + repository(owner: $repoOwner, name: $repoName) { + nameWithOwner + pullRequest(number: $prNumber) { + merged + mergeCommit { + oid + } + repository { + nameWithOwner + } + timelineItems(last: 100, itemTypes: [CONNECTED_EVENT]) { + nodes { + ... on ConnectedEvent { + subject { + __typename + ... on Issue { + number + title + repository { + nameWithOwner + } + timelineItems(last: 100, itemTypes: [CONNECTED_EVENT]) { + nodes { + ... on ConnectedEvent { + subject { + __typename + ... on PullRequest { + number + merged + mergeCommit { + oid + } + repository { + nameWithOwner + } + } + } + } + } + } + } + } + } + } + } + } + } + } + """ + variables = { + 'repoOwner': owner, + 'repoName': repo_without_org, + 'prNumber': pr_number + } + response = requests.post(url, json={'query': query, 'variables': variables}, headers=headers) + result = response.json() + print(result) + + prs = [] + main_pr_merge_commit = None + issue_number = None + issue_repo_name = None + + if response.status_code == 200: + data = result['data']['repository']['pullRequest'] + #print(data) + # Fetch the main PR merge commit + if data.get('merged') and data.get('mergeCommit'): + main_pr_merge_commit = { + 'repo': data['repository']['nameWithOwner'], + 'sha': data['mergeCommit']['oid'] + } + + # Find the linked issue number + for node in data['timelineItems']['nodes']: + subject = node.get('subject', {}) + if subject.get('__typename') == 'Issue': + issue_number = subject['number'] + issue_repo_name = subject['repository']['nameWithOwner'] + break + + # Extract all linked PRs' merge commits from the connected issue + for node in data['timelineItems']['nodes']: + subject = node.get('subject', {}) + if subject.get('__typename') == 'Issue': + issue_number = subject['number'] + issue_nodes = subject['timelineItems']['nodes'] + for issue_node in issue_nodes: + issue_pr = issue_node['subject'] + if issue_pr.get('__typename') == 'PullRequest' and issue_pr.get('merged') and issue_pr['mergeCommit']: + prs.append({ + 'repo': issue_pr['repository']['nameWithOwner'], + 'sha': issue_pr['mergeCommit']['oid'] + }) + + else: + print("Failed to fetch data:", result.get('errors')) + + # If no linked PRs are found, return only the input PR's merge commit + if not prs and main_pr_merge_commit: + prs.append(main_pr_merge_commit) + + if issue_number : + return prs, issue_repo_name, issue_number + else: + return prs, None, None + +#Extract the ticket number from the PR title +def extract_ticket_number(pr_title): + + ticket_pattern = r"[A-Z]+-[0-9]+" + match = re.search(ticket_pattern, pr_title) + return match.group(0) if match else "NO-TICKET" + +# function to write the xml file +def write_xml(element, file_path): + tree = ET.ElementTree(element) + tree.write(file_path, encoding='utf-8', xml_declaration=True) + +# function to update xml files +def update_xml_files(manifest_repo_path, updates): + + repo = Repo(manifest_repo_path) + xml_files = [f for f in os.listdir(manifest_repo_path) if f.endswith('.xml')] + changes_made = False # Flag to check if any changes are made + + for xml_file in xml_files: + xml_path = os.path.join(manifest_repo_path, xml_file) + tree = ET.parse(xml_path) + root = tree.getroot() + file_changed = False + + for project in root.findall('project'): + if project.get('name') in updates and project.get('revision') != updates[project.get('name')]: + print("Updating {}: {} from {} to {}".format(xml_file, project.get('name'), project.get('revision'), updates[project.get('name')])) + project.set('revision', updates[project.get('name')]) + file_changed = True + + if file_changed: + write_xml(root, xml_path) + print("Updated {}".format(xml_file)) + changes_made = True + + if changes_made: + repo.git.add(all=True) + else: + print("No changes were made to XML files.") + + return changes_made + +#Build the PR list description +def build_pr_list_description(prs): + + pr_list = "\n\nList of PRs and Repositories Involved:\n" + for pr in prs: + repo_name = pr['repo'] + sha = pr['sha'] + pr_list += "- Repository: {}, Merge Commit SHA: {}\n".format(repo_name, sha) + return pr_list + +#Commit the changes to the manifest files and push to the feature branch +def commit_and_push(manifest_repo_path, commit_message): + repo = Repo(manifest_repo_path) + if repo.is_dirty(): + repo.git.commit('-m', commit_message) + repo.git.push('origin', repo.active_branch.name) + else: + print("No changes to commit.") + +#Create a new PR for the updated manifest files +def create_pull_request(github_token, repo_name, head_branch, base_branch, title, description): + g = Github(github_token) + repo = g.get_repo(repo_name) + ensure_label_exists(repo, 'bhc-auto-merge', color='008672') + + try: + pr = repo.create_pull(title=title, body=description, base=base_branch, head=head_branch) + pr.add_to_labels('bhc-auto-merge') + print("PR Created and labeled:", pr.html_url) + return pr + except github.GithubException as e: + print("Failed to create PR:", str(e)) + return None + +#Ensure that the label exists in the repository +def ensure_label_exists(repo, label_name, color='FFFFFF'): + labels = repo.get_labels() + label_list = {label.name: label for label in labels} + if label_name not in label_list: + repo.create_label(name=label_name, color=color) + print("Label '{}' created.".format(label_name)) + else: + print("Label '{}' already exists.".format(label_name)) + +#Create or checkout the branch in the local manifest repository +def create_or_checkout_branch(repo, branch_name, base_branch): + + try: + # Fetch all branches from the remote + repo.git.fetch('origin') + + # Check if the branch exists in the remote repository + existing_branches = repo.git.branch('-r') + if 'origin/{}'.format(branch_name) in existing_branches: + print("Branch {} already exists remotely. Stopping further processing.".format(branch_name)) + sys.exit(1) # Exit with a non-zero code to signal that the branch already exists + else: + # Switch to 'base_branch' and pull the latest changes to ensure local repo is up-to-date + repo.git.checkout(base_branch) + repo.git.pull('origin', base_branch) + + # Create and check out the new branch locally + repo.git.checkout('-b', branch_name) + print("Created and checked out new branch: {}".format(branch_name)) + + # Push the newly created branch to the remote + repo.git.push('origin', branch_name) + + except GitCommandError as e: + print("Error checking out branch: {}".format(str(e))) + sys.exit(1) + +def main(): + github_token = os.getenv('GITHUB_TOKEN') + manifest_repo_path = os.getenv('META_REPO_PATH') + pr_number = os.getenv('PR_NUMBER') + manifest_repo_name = os.getenv('META_REPO_NAME') + repo_name = os.getenv('GITHUB_REPOSITORY') + repo_owner = os.getenv('GITHUB_ORG') + base_branch = os.getenv('BASE_BRANCH') + + g = Github(github_token) + repo = g.get_repo(repo_name) + meta_pr = repo.get_pull(int(pr_number)) + + # Extract ticket number + ticket_number = extract_ticket_number(meta_pr.title) + + prs, issue_repo_name, issue_number = fetch_merge_commits(repo_owner, repo_name, int(pr_number), github_token) + + if issue_number: + feature_branch = "feature_{}_issue_{}".format(issue_repo_name, issue_number) + pr_title = "Auto PR for {} {}".format(issue_repo_name, issue_number) + else: + feature_branch = "feature_{}_pr_{}".format(repo_name.split('/')[-1], pr_number) + pr_title = "Auto PR for {} {}".format(repo_name, pr_number) + + # Create or check out the branch in the local manifest repository + repo = Repo(manifest_repo_path) + create_or_checkout_branch(repo, feature_branch, base_branch) + time.sleep(5) + + # Set the new PR title and description + manifest_pr_title = "{} - {}".format(ticket_number, pr_title) + pr_list = build_pr_list_description(prs) + manifest_pr_description = "Details: {}\n{}".format(meta_pr.body, pr_list) + + updates = {pr['repo'].split('/')[-1]: pr['sha'] for pr in prs} + + print("Updates to be pushed to feature branch: {}".format(updates)) + + changes_made = update_xml_files(manifest_repo_path, updates) + if changes_made: + commit_and_push(manifest_repo_path, "Update manifest for {}".format(','.join(updates.keys()))) + create_pull_request(github_token, manifest_repo_name, feature_branch, base_branch, manifest_pr_title, manifest_pr_description) + +if __name__ == '__main__': + main() From 9af646455468d430bcd29dd3e2fc80646e9ef22c Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 10:57:02 +0530 Subject: [PATCH 08/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 61b01d9..05b4717 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -54,7 +54,7 @@ jobs: META_REPO_NAME: 'rdkcentral/meta-rdk-video' PR_NUMBER: 173 BASE_BRANCH: ${{ github.event.pull_request.base.ref }} - run: | - cd meta_repo - python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_meta.py - cd .. + run: | + cd meta_repo + python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_meta.py + cd .. From 6312d05ef9ee965e74ef456fcd33c71556e80b11 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 11:13:22 +0530 Subject: [PATCH 09/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 05b4717..014202d 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -52,7 +52,7 @@ jobs: GITHUB_ORG: 'rdkcentral' META_REPO_PATH: ${{ github.workspace }}/meta_repo META_REPO_NAME: 'rdkcentral/meta-rdk-video' - PR_NUMBER: 173 + PR_NUMBER: 111 BASE_BRANCH: ${{ github.event.pull_request.base.ref }} run: | cd meta_repo From c378f57ed144981a603481cedcce60c147793e9b Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 11:15:44 +0530 Subject: [PATCH 10/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 014202d..b1fe973 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -53,7 +53,7 @@ jobs: META_REPO_PATH: ${{ github.workspace }}/meta_repo META_REPO_NAME: 'rdkcentral/meta-rdk-video' PR_NUMBER: 111 - BASE_BRANCH: ${{ github.event.pull_request.base.ref }} + BASE_BRANCH: develop run: | cd meta_repo python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_meta.py From 96a3a9220e1457068a6e0e25bb0fd83fe38f8b2d Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 11:22:47 +0530 Subject: [PATCH 11/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 8e01f51..1bf4195 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -141,33 +141,41 @@ def write_xml(element, file_path): def update_xml_files(manifest_repo_path, updates): repo = Repo(manifest_repo_path) - xml_files = [f for f in os.listdir(manifest_repo_path) if f.endswith('.xml')] - changes_made = False # Flag to check if any changes are made - - for xml_file in xml_files: - xml_path = os.path.join(manifest_repo_path, xml_file) - tree = ET.parse(xml_path) - root = tree.getroot() - file_changed = False - - for project in root.findall('project'): - if project.get('name') in updates and project.get('revision') != updates[project.get('name')]: - print("Updating {}: {} from {} to {}".format(xml_file, project.get('name'), project.get('revision'), updates[project.get('name')])) - project.set('revision', updates[project.get('name')]) - file_changed = True - - if file_changed: - write_xml(root, xml_path) - print("Updated {}".format(xml_file)) - changes_made = True - - if changes_made: - repo.git.add(all=True) + # Find the .bb recipe file (assuming only one entservices-inputoutput.bb in the repo) + bb_file = None + for f in os.listdir(manifest_repo_path): + if f == 'entservices-inputoutput.bb': + bb_file = os.path.join(manifest_repo_path, f) + break + + if not bb_file: + print("No entservices-inputoutput.bb recipe file found.") + return False + + # Get the new SHA (assume only one update, as in your usage) + new_srcrev = list(updates.values())[0] + changed = False + with open(bb_file, 'r') as f: + lines = f.readlines() + + + + with open(bb_file, 'w') as f: + for line in lines: + if line.strip().startswith('SRCREV ='): + old_line = line.strip() + f.write(f'SRCREV = "{new_srcrev}"\n') + print(f"Updated SRCREV in {bb_file}: {old_line} -> SRCREV = \"{new_srcrev}\"") + changed = True + else: + f.write(line) + + if changed: + repo.git.add(bb_file) else: - print("No changes were made to XML files.") - - return changes_made + print("No changes were made to SRCREV in the recipe file.") + return changed #Build the PR list description def build_pr_list_description(prs): From 5933193f742c92b8930fcab52772d4a768d7ec15 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 11:28:09 +0530 Subject: [PATCH 12/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 1bf4195..bef0d44 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -141,11 +141,15 @@ def write_xml(element, file_path): def update_xml_files(manifest_repo_path, updates): repo = Repo(manifest_repo_path) - # Find the .bb recipe file (assuming only one entservices-inputoutput.bb in the repo) + + # Recursively search for entservices-inputoutput.bb in all subdirectories bb_file = None - for f in os.listdir(manifest_repo_path): - if f == 'entservices-inputoutput.bb': - bb_file = os.path.join(manifest_repo_path, f) + for root, dirs, files in os.walk(manifest_repo_path): + for f in files: + if f == 'entservices-inputoutput.bb': + bb_file = os.path.join(root, f) + break + if bb_file: break if not bb_file: From 6d3218049fdd6a9cfe3be69b5e9fffff0111c24f Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 3 Jul 2025 11:34:17 +0530 Subject: [PATCH 13/94] Update auto_pr_generation_meta.py --- build_health_check_workflow_scripts/auto_pr_generation_meta.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index bef0d44..6c738d0 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -207,8 +207,7 @@ def create_pull_request(github_token, repo_name, head_branch, base_branch, title try: pr = repo.create_pull(title=title, body=description, base=base_branch, head=head_branch) - pr.add_to_labels('bhc-auto-merge') - print("PR Created and labeled:", pr.html_url) + print("PR Created:", pr.html_url) return pr except github.GithubException as e: print("Failed to create PR:", str(e)) From 5e757644729eef186e37976bdc801d4e55c40fc5 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 11:05:29 +0530 Subject: [PATCH 14/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 121 ++++++++++++++---- 1 file changed, 97 insertions(+), 24 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 6c738d0..5b1f722 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -180,6 +180,69 @@ def update_xml_files(manifest_repo_path, updates): print("No changes were made to SRCREV in the recipe file.") return changed +def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): + """ + For each component, update the correct .bb file's SRCREV and the correct generic-pkgrev.inc PV field with the tag. + updates: list of dicts with keys: repo, sha, tag + """ + repo = Repo(manifest_repo_path) + changed = False + for update in updates: + repo_name = update['repo'] + sha = update['sha'] + tag = update.get('tag') + # Determine .bb and pkgrev.inc paths + if repo_name.startswith('rdkcentral/entservices-'): + comp = repo_name.split('/')[-1] + bb_file = os.path.join(manifest_repo_path, f'entservices-{comp.split("entservices-")[-1]}.bb') + pkgrev_file = os.path.join(generic_support_path, 'generic-pkgrev.inc') + pkgrev_key = comp + pkgrev_pv_field = f'PV:pn-{comp}' + elif repo_name == 'rdk-e/rdkservices-cpc': + bb_file = os.path.join(manifest_repo_path.replace('meta-middleware-generic-support', 'meta-rdk-comast-video'), 'rdkservices-comcast.bb') + pkgrev_file = os.path.join(generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support'), 'generic-pkgrev.inc') + pkgrev_key = 'rdkservices-comcast' + pkgrev_pv_field = f'{pkgrev_key}_PV' + else: + continue + # Update .bb file SRCREV + if os.path.exists(bb_file): + with open(bb_file, 'r') as f: + lines = f.readlines() + file_changed = False + with open(bb_file, 'w') as f: + for line in lines: + if line.strip().startswith('SRCREV ='): + f.write(f'SRCREV = "{sha}"\n') + file_changed = True + else: + f.write(line) + if file_changed: + repo.git.add(bb_file) + changed = True + # Update generic-pkgrev.inc PV + if tag and os.path.exists(pkgrev_file): + with open(pkgrev_file, 'r') as f: + lines = f.readlines() + file_changed = False + with open(pkgrev_file, 'w') as f: + for line in lines: + if repo_name.startswith('rdkcentral/entservices-'): + if line.strip().startswith(f'{pkgrev_pv_field} ='): + f.write(f'{pkgrev_pv_field} = "{tag}"\n') + file_changed = True + else: + f.write(line) + else: + if line.strip().startswith(f'{pkgrev_pv_field} ='): + f.write(f'{pkgrev_pv_field} = "{tag}"\n') + file_changed = True + else: + f.write(line) + if file_changed: + repo.git.add(pkgrev_file) + changed = True + return changed #Build the PR list description def build_pr_list_description(prs): @@ -206,6 +269,7 @@ def create_pull_request(github_token, repo_name, head_branch, base_branch, title ensure_label_exists(repo, 'bhc-auto-merge', color='008672') try: + # Only create the PR, do NOT merge it. Manual review/merge is required. pr = repo.create_pull(title=title, body=description, base=base_branch, head=head_branch) print("PR Created:", pr.html_url) return pr @@ -251,9 +315,22 @@ def create_or_checkout_branch(repo, branch_name, base_branch): print("Error checking out branch: {}".format(str(e))) sys.exit(1) +def get_tag_for_sha(github_token, repo_full_name, sha): + """ + Return the tag name for a given repo and commit SHA, or None if not found. + """ + g = Github(github_token) + repo = g.get_repo(repo_full_name) + tags = repo.get_tags() + for tag in tags: + if tag.commit.sha.startswith(sha): + return tag.name + return None + def main(): github_token = os.getenv('GITHUB_TOKEN') manifest_repo_path = os.getenv('META_REPO_PATH') + generic_support_path = os.getenv('GENERIC_SUPPORT_PATH') # new env var for meta-middleware-generic-support pr_number = os.getenv('PR_NUMBER') manifest_repo_name = os.getenv('META_REPO_NAME') repo_name = os.getenv('GITHUB_REPOSITORY') @@ -268,32 +345,28 @@ def main(): ticket_number = extract_ticket_number(meta_pr.title) prs, issue_repo_name, issue_number = fetch_merge_commits(repo_owner, repo_name, int(pr_number), github_token) - - if issue_number: - feature_branch = "feature_{}_issue_{}".format(issue_repo_name, issue_number) - pr_title = "Auto PR for {} {}".format(issue_repo_name, issue_number) - else: - feature_branch = "feature_{}_pr_{}".format(repo_name.split('/')[-1], pr_number) - pr_title = "Auto PR for {} {}".format(repo_name, pr_number) - - # Create or check out the branch in the local manifest repository - repo = Repo(manifest_repo_path) - create_or_checkout_branch(repo, feature_branch, base_branch) - time.sleep(5) - - # Set the new PR title and description - manifest_pr_title = "{} - {}".format(ticket_number, pr_title) - pr_list = build_pr_list_description(prs) - manifest_pr_description = "Details: {}\n{}".format(meta_pr.body, pr_list) - - updates = {pr['repo'].split('/')[-1]: pr['sha'] for pr in prs} + # For each PR, get the tag from GitHub + updates = [] + for pr in prs: + tag = get_tag_for_sha(github_token, pr['repo'], pr['sha']) + updates.append({'repo': pr['repo'], 'sha': pr['sha'], 'tag': tag}) print("Updates to be pushed to feature branch: {}".format(updates)) - - changes_made = update_xml_files(manifest_repo_path, updates) - if changes_made: - commit_and_push(manifest_repo_path, "Update manifest for {}".format(','.join(updates.keys()))) - create_pull_request(github_token, manifest_repo_name, feature_branch, base_branch, manifest_pr_title, manifest_pr_description) + changes_made = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + if changes_made: + commit_and_push( + manifest_repo_path, + "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + ) + create_pull_request( + github_token, + manifest_repo_name, + feature_branch, + base_branch, + manifest_pr_title, + manifest_pr_description + ) +# ...existing code... if __name__ == '__main__': main() From 0abe3f2698e363c1bd5135ba1573aeefd2614a01 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 11:22:42 +0530 Subject: [PATCH 15/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 5b1f722..3ca828c 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -195,12 +195,13 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] bb_file = os.path.join(manifest_repo_path, f'entservices-{comp.split("entservices-")[-1]}.bb') - pkgrev_file = os.path.join(generic_support_path, 'generic-pkgrev.inc') + pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') pkgrev_key = comp pkgrev_pv_field = f'PV:pn-{comp}' elif repo_name == 'rdk-e/rdkservices-cpc': bb_file = os.path.join(manifest_repo_path.replace('meta-middleware-generic-support', 'meta-rdk-comast-video'), 'rdkservices-comcast.bb') - pkgrev_file = os.path.join(generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support'), 'generic-pkgrev.inc') + cspc_support_path = generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support') + pkgrev_file = os.path.join(cspc_support_path, 'conf', 'include', 'cspc-pkgrev.inc') pkgrev_key = 'rdkservices-comcast' pkgrev_pv_field = f'{pkgrev_key}_PV' else: @@ -337,6 +338,32 @@ def main(): repo_owner = os.getenv('GITHUB_ORG') base_branch = os.getenv('BASE_BRANCH') + # Check required environment variables + if not generic_support_path: + print("ERROR: GENERIC_SUPPORT_PATH environment variable is not set.") + sys.exit(1) + if not manifest_repo_path: + print("ERROR: META_REPO_PATH environment variable is not set.") + sys.exit(1) + if not github_token: + print("ERROR: GITHUB_TOKEN environment variable is not set.") + sys.exit(1) + if not pr_number: + print("ERROR: PR_NUMBER environment variable is not set.") + sys.exit(1) + if not manifest_repo_name: + print("ERROR: META_REPO_NAME environment variable is not set.") + sys.exit(1) + if not repo_name: + print("ERROR: GITHUB_REPOSITORY environment variable is not set.") + sys.exit(1) + if not repo_owner: + print("ERROR: GITHUB_ORG environment variable is not set.") + sys.exit(1) + if not base_branch: + print("ERROR: BASE_BRANCH environment variable is not set.") + sys.exit(1) + g = Github(github_token) repo = g.get_repo(repo_name) meta_pr = repo.get_pull(int(pr_number)) From 147e0f60ccf080bd4514b591b7db14e6e0ad6d1f Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 11:25:53 +0530 Subject: [PATCH 16/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index b1fe973..71043a9 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -52,6 +52,7 @@ jobs: GITHUB_ORG: 'rdkcentral' META_REPO_PATH: ${{ github.workspace }}/meta_repo META_REPO_NAME: 'rdkcentral/meta-rdk-video' + GENERIC_SUPPORT_PATH: 'rdkcentral/meta-middleware-generic-support' PR_NUMBER: 111 BASE_BRANCH: develop run: | From 82f3d8cfb4143e9709a6ee77a3cfad6c11faea1b Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 11:31:25 +0530 Subject: [PATCH 17/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 3ca828c..c44cdd3 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -191,6 +191,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): repo_name = update['repo'] sha = update['sha'] tag = update.get('tag') + print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") # Determine .bb and pkgrev.inc paths if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] @@ -205,7 +206,10 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_key = 'rdkservices-comcast' pkgrev_pv_field = f'{pkgrev_key}_PV' else: + print(f"[DEBUG] Skipping repo {repo_name} (not handled)") continue + print(f"[DEBUG] bb_file: {bb_file}") + print(f"[DEBUG] pkgrev_file: {pkgrev_file}") # Update .bb file SRCREV if os.path.exists(bb_file): with open(bb_file, 'r') as f: @@ -214,6 +218,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): with open(bb_file, 'w') as f: for line in lines: if line.strip().startswith('SRCREV ='): + print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") f.write(f'SRCREV = "{sha}"\n') file_changed = True else: @@ -221,6 +226,11 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): if file_changed: repo.git.add(bb_file) changed = True + print(f"[DEBUG] Changed {bb_file}") + else: + print(f"[DEBUG] No change needed for {bb_file}") + else: + print(f"[DEBUG] .bb file does not exist: {bb_file}") # Update generic-pkgrev.inc PV if tag and os.path.exists(pkgrev_file): with open(pkgrev_file, 'r') as f: @@ -230,12 +240,14 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): for line in lines: if repo_name.startswith('rdkcentral/entservices-'): if line.strip().startswith(f'{pkgrev_pv_field} ='): + print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag}") f.write(f'{pkgrev_pv_field} = "{tag}"\n') file_changed = True else: f.write(line) else: if line.strip().startswith(f'{pkgrev_pv_field} ='): + print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag}") f.write(f'{pkgrev_pv_field} = "{tag}"\n') file_changed = True else: @@ -243,6 +255,14 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): if file_changed: repo.git.add(pkgrev_file) changed = True + print(f"[DEBUG] Changed {pkgrev_file}") + else: + print(f"[DEBUG] No change needed for {pkgrev_file}") + elif tag: + print(f"[DEBUG] pkgrev_file does not exist: {pkgrev_file}") + else: + print(f"[DEBUG] No tag found for {repo_name}, skipping PV update.") + print(f"[DEBUG] update_bb_and_pkgrev changed={changed}") return changed #Build the PR list description def build_pr_list_description(prs): @@ -373,14 +393,17 @@ def main(): prs, issue_repo_name, issue_number = fetch_merge_commits(repo_owner, repo_name, int(pr_number), github_token) # For each PR, get the tag from GitHub + print(f"[DEBUG] PRs to process: {prs}") updates = [] for pr in prs: tag = get_tag_for_sha(github_token, pr['repo'], pr['sha']) + print(f"[DEBUG] Tag for {pr['repo']} at {pr['sha']}: {tag}") updates.append({'repo': pr['repo'], 'sha': pr['sha'], 'tag': tag}) print("Updates to be pushed to feature branch: {}".format(updates)) changes_made = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + print(f"[DEBUG] changes_made: {changes_made}") if changes_made: commit_and_push( manifest_repo_path, @@ -394,6 +417,8 @@ def main(): manifest_pr_title, manifest_pr_description ) + else: + print("[DEBUG] No changes detected, PR will not be created.") # ...existing code... if __name__ == '__main__': main() From 4519fdb4bb62556b5cfdbb435d6f6a597b867802 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 11:37:03 +0530 Subject: [PATCH 18/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index c44cdd3..ad65043 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -195,7 +195,17 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): # Determine .bb and pkgrev.inc paths if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - bb_file = os.path.join(manifest_repo_path, f'entservices-{comp.split("entservices-")[-1]}.bb') + # Recursively search for entservices-*.bb under meta-rdk-video/recipes-extended/entservices/ + bb_file = None + entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') + if os.path.isdir(entservices_dir): + for root, dirs, files in os.walk(entservices_dir): + for f in files: + if f == f'entservices-{comp.split("entservices-")[-1]}.bb': + bb_file = os.path.join(root, f) + break + if bb_file: + break pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') pkgrev_key = comp pkgrev_pv_field = f'PV:pn-{comp}' @@ -211,7 +221,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] bb_file: {bb_file}") print(f"[DEBUG] pkgrev_file: {pkgrev_file}") # Update .bb file SRCREV - if os.path.exists(bb_file): + if bb_file and os.path.exists(bb_file): with open(bb_file, 'r') as f: lines = f.readlines() file_changed = False @@ -231,8 +241,9 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] No change needed for {bb_file}") else: print(f"[DEBUG] .bb file does not exist: {bb_file}") - # Update generic-pkgrev.inc PV - if tag and os.path.exists(pkgrev_file): + # Always use a tag, fallback to '1.0.0' if tag is None + tag_to_use = tag if tag else '1.0.0' + if pkgrev_file and os.path.exists(pkgrev_file): with open(pkgrev_file, 'r') as f: lines = f.readlines() file_changed = False @@ -240,15 +251,15 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): for line in lines: if repo_name.startswith('rdkcentral/entservices-'): if line.strip().startswith(f'{pkgrev_pv_field} ='): - print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag}") - f.write(f'{pkgrev_pv_field} = "{tag}"\n') + print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use}") + f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True else: f.write(line) else: if line.strip().startswith(f'{pkgrev_pv_field} ='): - print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag}") - f.write(f'{pkgrev_pv_field} = "{tag}"\n') + print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use}") + f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True else: f.write(line) @@ -258,10 +269,8 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] Changed {pkgrev_file}") else: print(f"[DEBUG] No change needed for {pkgrev_file}") - elif tag: - print(f"[DEBUG] pkgrev_file does not exist: {pkgrev_file}") else: - print(f"[DEBUG] No tag found for {repo_name}, skipping PV update.") + print(f"[DEBUG] pkgrev_file does not exist: {pkgrev_file}") print(f"[DEBUG] update_bb_and_pkgrev changed={changed}") return changed #Build the PR list description From d960d27e3815ab9785f2d763b6ea8737d2b98a12 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 11:43:20 +0530 Subject: [PATCH 19/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index ad65043..19c6352 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -414,9 +414,15 @@ def main(): changes_made = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) print(f"[DEBUG] changes_made: {changes_made}") if changes_made: + # Generate a feature branch name and PR title/description + feature_branch = f"auto-update-{ticket_number.lower()}" + manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" + manifest_pr_description = build_pr_list_description(updates) + + create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) commit_and_push( manifest_repo_path, - "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) ) create_pull_request( github_token, From 3a1e97501645980f7c2b74a98cc24037816a4028 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 11:51:04 +0530 Subject: [PATCH 20/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 19c6352..cb3cc04 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -296,7 +296,6 @@ def commit_and_push(manifest_repo_path, commit_message): def create_pull_request(github_token, repo_name, head_branch, base_branch, title, description): g = Github(github_token) repo = g.get_repo(repo_name) - ensure_label_exists(repo, 'bhc-auto-merge', color='008672') try: # Only create the PR, do NOT merge it. Manual review/merge is required. @@ -411,15 +410,17 @@ def main(): print("Updates to be pushed to feature branch: {}".format(updates)) + # Generate a feature branch name and PR title/description + feature_branch = f"auto-update-{ticket_number.lower()}" + manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" + manifest_pr_description = build_pr_list_description(updates) + + # Switch to feature branch BEFORE making changes + create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) + changes_made = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) print(f"[DEBUG] changes_made: {changes_made}") if changes_made: - # Generate a feature branch name and PR title/description - feature_branch = f"auto-update-{ticket_number.lower()}" - manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" - manifest_pr_description = build_pr_list_description(updates) - - create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) commit_and_push( manifest_repo_path, "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) From e822351555f4b01af9029af5acd7e9249b4fc5d9 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 12:06:48 +0530 Subject: [PATCH 21/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 71043a9..10b94cc 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -52,7 +52,7 @@ jobs: GITHUB_ORG: 'rdkcentral' META_REPO_PATH: ${{ github.workspace }}/meta_repo META_REPO_NAME: 'rdkcentral/meta-rdk-video' - GENERIC_SUPPORT_PATH: 'rdkcentral/meta-middleware-generic-support' + GENERIC_SUPPORT_PATH: ${{ github.workspace }}/rdkcentral/meta-middleware-generic-support PR_NUMBER: 111 BASE_BRANCH: develop run: | From dd99f4dd87399a33bad3bc0c090998a45b7df80f Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 12:10:50 +0530 Subject: [PATCH 22/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 10b94cc..f6f157b 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -27,6 +27,14 @@ jobs: ref: RDKEMW-4778 token: ${{ secrets.RDKCM_RDKE }} + - name: Checkout meta-middleware-generic-support + uses: actions/checkout@v4 + with: + repository: 'rdkcentral/meta-middleware-generic-support' + path: 'rdkcentral/meta-middleware-generic-support' + ref: RDKEMW-4778 + token: ${{ secrets.RDKCM_RDKE }} + - name: Update Git Config env: BOT_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} From 8b05bb9628a0fd4953ac48fa1a6626b079e96506 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 12:16:53 +0530 Subject: [PATCH 23/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 75 +++++++++++++++++-- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index cb3cc04..ba54d4a 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -186,7 +186,15 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): updates: list of dicts with keys: repo, sha, tag """ repo = Repo(manifest_repo_path) + support_repo = None + support_repo_path = generic_support_path + if os.path.isdir(support_repo_path): + try: + support_repo = Repo(support_repo_path) + except Exception as e: + print(f"[DEBUG] Could not open support repo at {support_repo_path}: {e}") changed = False + support_changed = False for update in updates: repo_name = update['repo'] sha = update['sha'] @@ -209,6 +217,17 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') pkgrev_key = comp pkgrev_pv_field = f'PV:pn-{comp}' + # For support layer PR + support_bb_file = None + support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') + if os.path.isdir(support_entservices_dir): + for root, dirs, files in os.walk(support_entservices_dir): + for f in files: + if f == f'entservices-{comp.split("entservices-")[-1]}.bb': + support_bb_file = os.path.join(root, f) + break + if support_bb_file: + break elif repo_name == 'rdk-e/rdkservices-cpc': bb_file = os.path.join(manifest_repo_path.replace('meta-middleware-generic-support', 'meta-rdk-comast-video'), 'rdkservices-comcast.bb') cspc_support_path = generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support') @@ -220,7 +239,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): continue print(f"[DEBUG] bb_file: {bb_file}") print(f"[DEBUG] pkgrev_file: {pkgrev_file}") - # Update .bb file SRCREV + # Update .bb file SRCREV in meta layer if bb_file and os.path.exists(bb_file): with open(bb_file, 'r') as f: lines = f.readlines() @@ -241,6 +260,28 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] No change needed for {bb_file}") else: print(f"[DEBUG] .bb file does not exist: {bb_file}") + + # Update .bb file SRCREV in support layer (if present) + if support_repo and support_bb_file and os.path.exists(support_bb_file): + with open(support_bb_file, 'r') as f: + lines = f.readlines() + file_changed = False + with open(support_bb_file, 'w') as f: + for line in lines: + if line.strip().startswith('SRCREV ='): + print(f"[DEBUG] Updating SRCREV in {support_bb_file} to {sha}") + f.write(f'SRCREV = "{sha}"\n') + file_changed = True + else: + f.write(line) + if file_changed: + support_repo.git.add(support_bb_file) + support_changed = True + print(f"[DEBUG] Changed {support_bb_file}") + else: + print(f"[DEBUG] No change needed for {support_bb_file}") + elif support_bb_file: + print(f"[DEBUG] Support .bb file does not exist: {support_bb_file}") # Always use a tag, fallback to '1.0.0' if tag is None tag_to_use = tag if tag else '1.0.0' if pkgrev_file and os.path.exists(pkgrev_file): @@ -271,8 +312,8 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] No change needed for {pkgrev_file}") else: print(f"[DEBUG] pkgrev_file does not exist: {pkgrev_file}") - print(f"[DEBUG] update_bb_and_pkgrev changed={changed}") - return changed + print(f"[DEBUG] update_bb_and_pkgrev changed={changed}, support_changed={support_changed}") + return changed, support_changed #Build the PR list description def build_pr_list_description(prs): @@ -418,8 +459,8 @@ def main(): # Switch to feature branch BEFORE making changes create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) - changes_made = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) - print(f"[DEBUG] changes_made: {changes_made}") + changes_made, support_changed = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") if changes_made: commit_and_push( manifest_repo_path, @@ -434,7 +475,29 @@ def main(): manifest_pr_description ) else: - print("[DEBUG] No changes detected, PR will not be created.") + print("[DEBUG] No changes detected, PR will not be created for meta layer.") + + # Support layer PR + if support_changed: + support_branch = f"auto-update-support-{ticket_number.lower()}" + support_pr_title = f"[Auto] Update support layer for {ticket_number}" + support_pr_description = build_pr_list_description(updates) + if support_repo: + create_or_checkout_branch(support_repo, support_branch, base_branch) + commit_and_push( + support_repo_path, + "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) + ) + create_pull_request( + github_token, + 'rdkcentral/meta-middleware-generic-support', + support_branch, + base_branch, + support_pr_title, + support_pr_description + ) + else: + print("[DEBUG] No support_repo found for PR creation.") # ...existing code... if __name__ == '__main__': main() From 662cc4d6cd30a53e55752f78558dbb9e7fb41bf9 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 12:23:17 +0530 Subject: [PATCH 24/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 48 ++++++++----------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index ba54d4a..5a6cf2b 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -200,11 +200,14 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): sha = update['sha'] tag = update.get('tag') print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") - # Determine .bb and pkgrev.inc paths + # Determine .bb paths (meta and support layer) + bb_file = None + support_bb_file = None + pkgrev_file = None + pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] # Recursively search for entservices-*.bb under meta-rdk-video/recipes-extended/entservices/ - bb_file = None entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') if os.path.isdir(entservices_dir): for root, dirs, files in os.walk(entservices_dir): @@ -214,11 +217,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): break if bb_file: break - pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') - pkgrev_key = comp - pkgrev_pv_field = f'PV:pn-{comp}' # For support layer PR - support_bb_file = None support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') if os.path.isdir(support_entservices_dir): for root, dirs, files in os.walk(support_entservices_dir): @@ -228,12 +227,14 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): break if support_bb_file: break + pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') + pkgrev_pv_field = f'PV:pn-{comp}' elif repo_name == 'rdk-e/rdkservices-cpc': bb_file = os.path.join(manifest_repo_path.replace('meta-middleware-generic-support', 'meta-rdk-comast-video'), 'rdkservices-comcast.bb') cspc_support_path = generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support') + support_bb_file = None # Not handled for support layer in this case pkgrev_file = os.path.join(cspc_support_path, 'conf', 'include', 'cspc-pkgrev.inc') - pkgrev_key = 'rdkservices-comcast' - pkgrev_pv_field = f'{pkgrev_key}_PV' + pkgrev_pv_field = 'rdkservices-comcast_PV' else: print(f"[DEBUG] Skipping repo {repo_name} (not handled)") continue @@ -282,36 +283,29 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] No change needed for {support_bb_file}") elif support_bb_file: print(f"[DEBUG] Support .bb file does not exist: {support_bb_file}") - # Always use a tag, fallback to '1.0.0' if tag is None + + # Only update pkgrev_file in support layer repo tag_to_use = tag if tag else '1.0.0' - if pkgrev_file and os.path.exists(pkgrev_file): + if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: with open(pkgrev_file, 'r') as f: lines = f.readlines() file_changed = False with open(pkgrev_file, 'w') as f: for line in lines: - if repo_name.startswith('rdkcentral/entservices-'): - if line.strip().startswith(f'{pkgrev_pv_field} ='): - print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use}") - f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - else: - f.write(line) + if line.strip().startswith(f'{pkgrev_pv_field} ='): + print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use}") + f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True else: - if line.strip().startswith(f'{pkgrev_pv_field} ='): - print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use}") - f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - else: - f.write(line) + f.write(line) if file_changed: - repo.git.add(pkgrev_file) - changed = True + support_repo.git.add(pkgrev_file) + support_changed = True print(f"[DEBUG] Changed {pkgrev_file}") else: print(f"[DEBUG] No change needed for {pkgrev_file}") - else: - print(f"[DEBUG] pkgrev_file does not exist: {pkgrev_file}") + elif pkgrev_file: + print(f"[DEBUG] pkgrev_file does not exist or support_repo not found: {pkgrev_file}") print(f"[DEBUG] update_bb_and_pkgrev changed={changed}, support_changed={support_changed}") return changed, support_changed #Build the PR list description From 75d508843e005e41af682de352eac3b42fe79d64 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 12:26:37 +0530 Subject: [PATCH 25/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 5a6cf2b..e150d02 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -307,7 +307,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): elif pkgrev_file: print(f"[DEBUG] pkgrev_file does not exist or support_repo not found: {pkgrev_file}") print(f"[DEBUG] update_bb_and_pkgrev changed={changed}, support_changed={support_changed}") - return changed, support_changed + return changed, support_changed, support_repo #Build the PR list description def build_pr_list_description(prs): @@ -453,7 +453,7 @@ def main(): # Switch to feature branch BEFORE making changes create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) - changes_made, support_changed = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + changes_made, support_changed, support_repo = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") if changes_made: commit_and_push( @@ -479,7 +479,7 @@ def main(): if support_repo: create_or_checkout_branch(support_repo, support_branch, base_branch) commit_and_push( - support_repo_path, + generic_support_path, "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) ) create_pull_request( From 119005766e44866e15fb892ad0c80ed2e7a07061 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 12:29:41 +0530 Subject: [PATCH 26/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index e150d02..0d16e25 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -322,6 +322,19 @@ def build_pr_list_description(prs): def commit_and_push(manifest_repo_path, commit_message): repo = Repo(manifest_repo_path) if repo.is_dirty(): + # Ensure git user.name and user.email are set + config_writer = repo.config_writer() + try: + user_name = config_writer.get_value('user', 'name', None) + user_email = config_writer.get_value('user', 'email', None) + except Exception: + user_name = None + user_email = None + if not user_name: + config_writer.set_value('user', 'name', os.environ.get('GIT_COMMITTER_NAME', 'github-actions[bot]')) + if not user_email: + config_writer.set_value('user', 'email', os.environ.get('GIT_COMMITTER_EMAIL', 'github-actions[bot]@users.noreply.github.com')) + config_writer.release() repo.git.commit('-m', commit_message) repo.git.push('origin', repo.active_branch.name) else: From ae66b6c2aa12e90beafd50a2e1aadb73e21a97cb Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 14:31:38 +0530 Subject: [PATCH 27/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 0d16e25..900f066 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -240,17 +240,22 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): continue print(f"[DEBUG] bb_file: {bb_file}") print(f"[DEBUG] pkgrev_file: {pkgrev_file}") - # Update .bb file SRCREV in meta layer + # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): with open(bb_file, 'r') as f: lines = f.readlines() file_changed = False + tag_to_use = tag if tag else '1.0.0' with open(bb_file, 'w') as f: for line in lines: if line.strip().startswith('SRCREV ='): print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") f.write(f'SRCREV = "{sha}"\n') file_changed = True + elif line.strip().startswith('PV ?='): + print(f"[DEBUG] Updating PV in {bb_file} to {tag_to_use}") + f.write(f'PV ?= "{tag_to_use}"\n') + file_changed = True else: f.write(line) if file_changed: From 244c7613795cf935bd7657f2ef7b3b5407b764c0 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 14:46:50 +0530 Subject: [PATCH 28/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 604 +++++++++++++++++--- 1 file changed, 535 insertions(+), 69 deletions(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index f6f157b..2457ec4 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -1,69 +1,535 @@ -name: Update Meta on Component Repo Merge - -on: - workflow_call: - secrets: - RDKCM_RDKE: - required: true - -jobs: - auto_pr_creation_meta: - runs-on: ubuntu-latest - #if: github.event.pull_request.merged == true - steps: - - name: Checkout build_tools_workflows code - uses: actions/checkout@v4 - with: - repository: rdkcentral/build_tools_workflows - path: 'tools' - ref: RDKEMW-4778 - token: ${{ secrets.RDKCM_RDKE }} - - - name: Checkout Meta Repository - uses: actions/checkout@v4 - with: - repository: 'rdkcentral/meta-rdk-video' - path: 'meta_repo' - ref: RDKEMW-4778 - token: ${{ secrets.RDKCM_RDKE }} - - - name: Checkout meta-middleware-generic-support - uses: actions/checkout@v4 - with: - repository: 'rdkcentral/meta-middleware-generic-support' - path: 'rdkcentral/meta-middleware-generic-support' - ref: RDKEMW-4778 - token: ${{ secrets.RDKCM_RDKE }} - - - name: Update Git Config - env: - BOT_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} - run: | - cd meta_repo - git config user.name "bot" - git config user.email "$BOT_EMAIL" - cd .. - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - - - name: Install Python dependencies - run: | - python3 -m pip install --upgrade pip - pip install requests PyGithub GitPython - - - name: Run the update script - env: - GITHUB_TOKEN: ${{ secrets.RDKCM_RDKE }} - GITHUB_ORG: 'rdkcentral' - META_REPO_PATH: ${{ github.workspace }}/meta_repo - META_REPO_NAME: 'rdkcentral/meta-rdk-video' - GENERIC_SUPPORT_PATH: ${{ github.workspace }}/rdkcentral/meta-middleware-generic-support - PR_NUMBER: 111 - BASE_BRANCH: develop - run: | - cd meta_repo - python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_meta.py - cd .. +import os +import requests +import github +from github import Github +import xml.etree.ElementTree as ET +from git import Repo +import re +from git import GitCommandError +import sys +import time + + +#Fetch all merged PRs linked to a specific issue. +def fetch_merge_commits(owner, repo, pr_number, github_token): + + url = 'https://api.github.com/graphql' + repo_without_org = repo.split('/')[-1] + headers = {'Authorization': 'Bearer {}'.format(github_token)} + query = """ + query($repoOwner: String!, $repoName: String!, $prNumber: Int!) { + repository(owner: $repoOwner, name: $repoName) { + nameWithOwner + pullRequest(number: $prNumber) { + merged + mergeCommit { + oid + } + repository { + nameWithOwner + } + timelineItems(last: 100, itemTypes: [CONNECTED_EVENT]) { + nodes { + ... on ConnectedEvent { + subject { + __typename + ... on Issue { + number + title + repository { + nameWithOwner + } + timelineItems(last: 100, itemTypes: [CONNECTED_EVENT]) { + nodes { + ... on ConnectedEvent { + subject { + __typename + ... on PullRequest { + number + merged + mergeCommit { + oid + } + repository { + nameWithOwner + } + } + } + } + } + } + } + } + } + } + } + } + } + } + """ + variables = { + 'repoOwner': owner, + 'repoName': repo_without_org, + 'prNumber': pr_number + } + response = requests.post(url, json={'query': query, 'variables': variables}, headers=headers) + result = response.json() + print(result) + + prs = [] + main_pr_merge_commit = None + issue_number = None + issue_repo_name = None + + if response.status_code == 200: + data = result['data']['repository']['pullRequest'] + #print(data) + # Fetch the main PR merge commit + if data.get('merged') and data.get('mergeCommit'): + main_pr_merge_commit = { + 'repo': data['repository']['nameWithOwner'], + 'sha': data['mergeCommit']['oid'] + } + + # Find the linked issue number + for node in data['timelineItems']['nodes']: + subject = node.get('subject', {}) + if subject.get('__typename') == 'Issue': + issue_number = subject['number'] + issue_repo_name = subject['repository']['nameWithOwner'] + break + + # Extract all linked PRs' merge commits from the connected issue + for node in data['timelineItems']['nodes']: + subject = node.get('subject', {}) + if subject.get('__typename') == 'Issue': + issue_number = subject['number'] + issue_nodes = subject['timelineItems']['nodes'] + for issue_node in issue_nodes: + issue_pr = issue_node['subject'] + if issue_pr.get('__typename') == 'PullRequest' and issue_pr.get('merged') and issue_pr['mergeCommit']: + prs.append({ + 'repo': issue_pr['repository']['nameWithOwner'], + 'sha': issue_pr['mergeCommit']['oid'] + }) + + else: + print("Failed to fetch data:", result.get('errors')) + + # If no linked PRs are found, return only the input PR's merge commit + if not prs and main_pr_merge_commit: + prs.append(main_pr_merge_commit) + + if issue_number : + return prs, issue_repo_name, issue_number + else: + return prs, None, None + +#Extract the ticket number from the PR title +def extract_ticket_number(pr_title): + + ticket_pattern = r"[A-Z]+-[0-9]+" + match = re.search(ticket_pattern, pr_title) + return match.group(0) if match else "NO-TICKET" + +# function to write the xml file +def write_xml(element, file_path): + tree = ET.ElementTree(element) + tree.write(file_path, encoding='utf-8', xml_declaration=True) + +# function to update xml files +def update_xml_files(manifest_repo_path, updates): + + repo = Repo(manifest_repo_path) + + # Recursively search for entservices-inputoutput.bb in all subdirectories + bb_file = None + for root, dirs, files in os.walk(manifest_repo_path): + for f in files: + if f == 'entservices-inputoutput.bb': + bb_file = os.path.join(root, f) + break + if bb_file: + break + + if not bb_file: + print("No entservices-inputoutput.bb recipe file found.") + return False + + # Get the new SHA (assume only one update, as in your usage) + new_srcrev = list(updates.values())[0] + changed = False + with open(bb_file, 'r') as f: + lines = f.readlines() + + + + with open(bb_file, 'w') as f: + for line in lines: + if line.strip().startswith('SRCREV ='): + old_line = line.strip() + f.write(f'SRCREV = "{new_srcrev}"\n') + print(f"Updated SRCREV in {bb_file}: {old_line} -> SRCREV = \"{new_srcrev}\"") + changed = True + else: + f.write(line) + + if changed: + repo.git.add(bb_file) + else: + print("No changes were made to SRCREV in the recipe file.") + + return changed +def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): + """ + For each component, update the correct .bb file's SRCREV and the correct generic-pkgrev.inc PV field with the tag. + updates: list of dicts with keys: repo, sha, tag + """ + repo = Repo(manifest_repo_path) + support_repo = None + support_repo_path = generic_support_path + if os.path.isdir(support_repo_path): + try: + support_repo = Repo(support_repo_path) + except Exception as e: + print(f"[DEBUG] Could not open support repo at {support_repo_path}: {e}") + changed = False + support_changed = False + for update in updates: + repo_name = update['repo'] + sha = update['sha'] + tag = update.get('tag') + print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") + # Determine .bb paths (meta and support layer) + bb_file = None + support_bb_file = None + pkgrev_file = None + pkgrev_pv_field = None + if repo_name.startswith('rdkcentral/entservices-'): + comp = repo_name.split('/')[-1] + # Recursively search for entservices-*.bb under meta-rdk-video/recipes-extended/entservices/ + entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') + if os.path.isdir(entservices_dir): + for root, dirs, files in os.walk(entservices_dir): + for f in files: + if f == f'entservices-{comp.split("entservices-")[-1]}.bb': + bb_file = os.path.join(root, f) + break + if bb_file: + break + # For support layer PR + support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') + if os.path.isdir(support_entservices_dir): + for root, dirs, files in os.walk(support_entservices_dir): + for f in files: + if f == f'entservices-{comp.split("entservices-")[-1]}.bb': + support_bb_file = os.path.join(root, f) + break + if support_bb_file: + break + pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') + pkgrev_pv_field = f'PV:pn-{comp}' + elif repo_name == 'rdk-e/rdkservices-cpc': + bb_file = os.path.join(manifest_repo_path.replace('meta-middleware-generic-support', 'meta-rdk-comast-video'), 'rdkservices-comcast.bb') + cspc_support_path = generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support') + support_bb_file = None # Not handled for support layer in this case + pkgrev_file = os.path.join(cspc_support_path, 'conf', 'include', 'cspc-pkgrev.inc') + pkgrev_pv_field = 'rdkservices-comcast_PV' + else: + print(f"[DEBUG] Skipping repo {repo_name} (not handled)") + continue + print(f"[DEBUG] bb_file: {bb_file}") + print(f"[DEBUG] pkgrev_file: {pkgrev_file}") + # Update .bb file SRCREV and PV in meta layer + if bb_file and os.path.exists(bb_file): + with open(bb_file, 'r') as f: + lines = f.readlines() + file_changed = False + tag_to_use = tag if tag else '1.0.0' + with open(bb_file, 'w') as f: + for line in lines: + if line.strip().startswith('SRCREV ='): + print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") + f.write(f'SRCREV = "{sha}"\n') + file_changed = True + elif line.strip().startswith('PV ?='): + print(f"[DEBUG] Updating PV in {bb_file} to {tag_to_use}") + f.write(f'PV ?= "{tag_to_use}"\n') + file_changed = True + else: + f.write(line) + if file_changed: + repo.git.add(bb_file) + changed = True + print(f"[DEBUG] Changed {bb_file}") + else: + print(f"[DEBUG] No change needed for {bb_file}") + else: + print(f"[DEBUG] .bb file does not exist: {bb_file}") + + # Update .bb file SRCREV in support layer (if present) + if support_repo and support_bb_file and os.path.exists(support_bb_file): + with open(support_bb_file, 'r') as f: + lines = f.readlines() + file_changed = False + with open(support_bb_file, 'w') as f: + for line in lines: + if line.strip().startswith('SRCREV ='): + print(f"[DEBUG] Updating SRCREV in {support_bb_file} to {sha}") + f.write(f'SRCREV = "{sha}"\n') + file_changed = True + else: + f.write(line) + if file_changed: + support_repo.git.add(support_bb_file) + support_changed = True + print(f"[DEBUG] Changed {support_bb_file}") + else: + print(f"[DEBUG] No change needed for {support_bb_file}") + elif support_bb_file: + print(f"[DEBUG] Support .bb file does not exist: {support_bb_file}") + + # Only update pkgrev_file in support layer repo + tag_to_use = tag if tag else '1.0.0' + if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + with open(pkgrev_file, 'r') as f: + lines = f.readlines() + file_changed = False + with open(pkgrev_file, 'w') as f: + for line in lines: + if line.strip().startswith(f'{pkgrev_pv_field} ='): + print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use}") + f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + else: + f.write(line) + if file_changed: + support_repo.git.add(pkgrev_file) + support_changed = True + print(f"[DEBUG] Changed {pkgrev_file}") + else: + print(f"[DEBUG] No change needed for {pkgrev_file}") + elif pkgrev_file: + print(f"[DEBUG] pkgrev_file does not exist or support_repo not found: {pkgrev_file}") + print(f"[DEBUG] update_bb_and_pkgrev changed={changed}, support_changed={support_changed}") + return changed, support_changed, support_repo +#Build the PR list description +def build_pr_list_description(prs): + + pr_list = "\n\nList of PRs and Repositories Involved:\n" + for pr in prs: + repo_name = pr['repo'] + sha = pr['sha'] + pr_list += "- Repository: {}, Merge Commit SHA: {}\n".format(repo_name, sha) + return pr_list + +#Commit the changes to the manifest files and push to the feature branch +def commit_and_push(manifest_repo_path, commit_message): + repo = Repo(manifest_repo_path) + if repo.is_dirty(): + # Ensure git user.name and user.email are set + config_writer = repo.config_writer() + try: + user_name = config_writer.get_value('user', 'name', None) + user_email = config_writer.get_value('user', 'email', None) + except Exception: + user_name = None + user_email = None + if not user_name: + config_writer.set_value('user', 'name', os.environ.get('GIT_COMMITTER_NAME', 'github-actions[bot]')) + if not user_email: + config_writer.set_value('user', 'email', os.environ.get('GIT_COMMITTER_EMAIL', 'github-actions[bot]@users.noreply.github.com')) + config_writer.release() + repo.git.commit('-m', commit_message) + repo.git.push('origin', repo.active_branch.name) + else: + print("No changes to commit.") + +#Create a new PR for the updated manifest files +def create_pull_request(github_token, repo_name, head_branch, base_branch, title, description): + g = Github(github_token) + repo = g.get_repo(repo_name) + + try: + # Only create the PR, do NOT merge it. Manual review/merge is required. + pr = repo.create_pull(title=title, body=description, base=base_branch, head=head_branch) + print("PR Created:", pr.html_url) + return pr + except github.GithubException as e: + print("Failed to create PR:", str(e)) + return None + +#Ensure that the label exists in the repository +def ensure_label_exists(repo, label_name, color='FFFFFF'): + labels = repo.get_labels() + label_list = {label.name: label for label in labels} + if label_name not in label_list: + repo.create_label(name=label_name, color=color) + print("Label '{}' created.".format(label_name)) + else: + print("Label '{}' already exists.".format(label_name)) + +#Create or checkout the branch in the local manifest repository +def create_or_checkout_branch(repo, branch_name, base_branch): + + try: + # Fetch all branches from the remote + repo.git.fetch('origin') + + # Check if the branch exists in the remote repository + existing_branches = repo.git.branch('-r') + if 'origin/{}'.format(branch_name) in existing_branches: + print("Branch {} already exists remotely. Stopping further processing.".format(branch_name)) + sys.exit(1) # Exit with a non-zero code to signal that the branch already exists + else: + # Switch to 'base_branch' and pull the latest changes to ensure local repo is up-to-date + repo.git.checkout(base_branch) + repo.git.pull('origin', base_branch) + + # Create and check out the new branch locally + repo.git.checkout('-b', branch_name) + print("Created and checked out new branch: {}".format(branch_name)) + + # Push the newly created branch to the remote + repo.git.push('origin', branch_name) + + except GitCommandError as e: + print("Error checking out branch: {}".format(str(e))) + sys.exit(1) + +def get_tag_for_sha(github_token, repo_full_name, sha): + """ + Return the tag name for a given repo and commit SHA, or None if not found. + """ + g = Github(github_token) + repo = g.get_repo(repo_full_name) + tags = list(repo.get_tags()) + # Try exact match first + for tag in tags: + if tag.commit.sha.startswith(sha): + return tag.name + # If not found, walk back up to 10 parent commits from the merge commit + try: + commit = repo.get_commit(sha) + visited = set() + queue = [(commit, 0)] + max_depth = 10 + while queue: + current_commit, depth = queue.pop(0) + if current_commit.sha in visited or depth > max_depth: + continue + visited.add(current_commit.sha) + for tag in tags: + if tag.commit.sha == current_commit.sha: + return tag.name + # Add parents to queue + for parent in current_commit.parents: + queue.append((parent, depth + 1)) + except Exception as e: + print(f"[DEBUG] Error walking parent commits for tag lookup: {e}") + return None + +def main(): + github_token = os.getenv('GITHUB_TOKEN') + manifest_repo_path = os.getenv('META_REPO_PATH') + generic_support_path = os.getenv('GENERIC_SUPPORT_PATH') # new env var for meta-middleware-generic-support + pr_number = os.getenv('PR_NUMBER') + manifest_repo_name = os.getenv('META_REPO_NAME') + repo_name = os.getenv('GITHUB_REPOSITORY') + repo_owner = os.getenv('GITHUB_ORG') + base_branch = os.getenv('BASE_BRANCH') + + # Check required environment variables + if not generic_support_path: + print("ERROR: GENERIC_SUPPORT_PATH environment variable is not set.") + sys.exit(1) + if not manifest_repo_path: + print("ERROR: META_REPO_PATH environment variable is not set.") + sys.exit(1) + if not github_token: + print("ERROR: GITHUB_TOKEN environment variable is not set.") + sys.exit(1) + if not pr_number: + print("ERROR: PR_NUMBER environment variable is not set.") + sys.exit(1) + if not manifest_repo_name: + print("ERROR: META_REPO_NAME environment variable is not set.") + sys.exit(1) + if not repo_name: + print("ERROR: GITHUB_REPOSITORY environment variable is not set.") + sys.exit(1) + if not repo_owner: + print("ERROR: GITHUB_ORG environment variable is not set.") + sys.exit(1) + if not base_branch: + print("ERROR: BASE_BRANCH environment variable is not set.") + sys.exit(1) + + g = Github(github_token) + repo = g.get_repo(repo_name) + meta_pr = repo.get_pull(int(pr_number)) + + # Extract ticket number + ticket_number = extract_ticket_number(meta_pr.title) + + prs, issue_repo_name, issue_number = fetch_merge_commits(repo_owner, repo_name, int(pr_number), github_token) + # For each PR, get the tag from GitHub + print(f"[DEBUG] PRs to process: {prs}") + updates = [] + for pr in prs: + tag = get_tag_for_sha(github_token, pr['repo'], pr['sha']) + print(f"[DEBUG] Tag for {pr['repo']} at {pr['sha']}: {tag}") + updates.append({'repo': pr['repo'], 'sha': pr['sha'], 'tag': tag}) + + print("Updates to be pushed to feature branch: {}".format(updates)) + + # Generate a feature branch name and PR title/description + feature_branch = f"auto-update-{ticket_number.lower()}" + manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" + manifest_pr_description = build_pr_list_description(updates) + + # Switch to feature branch BEFORE making changes + create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) + + changes_made, support_changed, support_repo = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") + if changes_made: + commit_and_push( + manifest_repo_path, + "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) + ) + create_pull_request( + github_token, + manifest_repo_name, + feature_branch, + base_branch, + manifest_pr_title, + manifest_pr_description + ) + else: + print("[DEBUG] No changes detected, PR will not be created for meta layer.") + + # Support layer PR + if support_changed: + support_branch = f"auto-update-support-{ticket_number.lower()}" + support_pr_title = f"[Auto] Update support layer for {ticket_number}" + support_pr_description = build_pr_list_description(updates) + if support_repo: + create_or_checkout_branch(support_repo, support_branch, base_branch) + commit_and_push( + generic_support_path, + "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) + ) + create_pull_request( + github_token, + 'rdkcentral/meta-middleware-generic-support', + support_branch, + base_branch, + support_pr_title, + support_pr_description + ) + else: + print("[DEBUG] No support_repo found for PR creation.") +# ...existing code... +if __name__ == '__main__': + main() From 916afb73dac0486b7036a2a576d3a02800086592 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 14:49:38 +0530 Subject: [PATCH 29/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 604 +++----------------- 1 file changed, 69 insertions(+), 535 deletions(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 2457ec4..f6f157b 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -1,535 +1,69 @@ -import os -import requests -import github -from github import Github -import xml.etree.ElementTree as ET -from git import Repo -import re -from git import GitCommandError -import sys -import time - - -#Fetch all merged PRs linked to a specific issue. -def fetch_merge_commits(owner, repo, pr_number, github_token): - - url = 'https://api.github.com/graphql' - repo_without_org = repo.split('/')[-1] - headers = {'Authorization': 'Bearer {}'.format(github_token)} - query = """ - query($repoOwner: String!, $repoName: String!, $prNumber: Int!) { - repository(owner: $repoOwner, name: $repoName) { - nameWithOwner - pullRequest(number: $prNumber) { - merged - mergeCommit { - oid - } - repository { - nameWithOwner - } - timelineItems(last: 100, itemTypes: [CONNECTED_EVENT]) { - nodes { - ... on ConnectedEvent { - subject { - __typename - ... on Issue { - number - title - repository { - nameWithOwner - } - timelineItems(last: 100, itemTypes: [CONNECTED_EVENT]) { - nodes { - ... on ConnectedEvent { - subject { - __typename - ... on PullRequest { - number - merged - mergeCommit { - oid - } - repository { - nameWithOwner - } - } - } - } - } - } - } - } - } - } - } - } - } - } - """ - variables = { - 'repoOwner': owner, - 'repoName': repo_without_org, - 'prNumber': pr_number - } - response = requests.post(url, json={'query': query, 'variables': variables}, headers=headers) - result = response.json() - print(result) - - prs = [] - main_pr_merge_commit = None - issue_number = None - issue_repo_name = None - - if response.status_code == 200: - data = result['data']['repository']['pullRequest'] - #print(data) - # Fetch the main PR merge commit - if data.get('merged') and data.get('mergeCommit'): - main_pr_merge_commit = { - 'repo': data['repository']['nameWithOwner'], - 'sha': data['mergeCommit']['oid'] - } - - # Find the linked issue number - for node in data['timelineItems']['nodes']: - subject = node.get('subject', {}) - if subject.get('__typename') == 'Issue': - issue_number = subject['number'] - issue_repo_name = subject['repository']['nameWithOwner'] - break - - # Extract all linked PRs' merge commits from the connected issue - for node in data['timelineItems']['nodes']: - subject = node.get('subject', {}) - if subject.get('__typename') == 'Issue': - issue_number = subject['number'] - issue_nodes = subject['timelineItems']['nodes'] - for issue_node in issue_nodes: - issue_pr = issue_node['subject'] - if issue_pr.get('__typename') == 'PullRequest' and issue_pr.get('merged') and issue_pr['mergeCommit']: - prs.append({ - 'repo': issue_pr['repository']['nameWithOwner'], - 'sha': issue_pr['mergeCommit']['oid'] - }) - - else: - print("Failed to fetch data:", result.get('errors')) - - # If no linked PRs are found, return only the input PR's merge commit - if not prs and main_pr_merge_commit: - prs.append(main_pr_merge_commit) - - if issue_number : - return prs, issue_repo_name, issue_number - else: - return prs, None, None - -#Extract the ticket number from the PR title -def extract_ticket_number(pr_title): - - ticket_pattern = r"[A-Z]+-[0-9]+" - match = re.search(ticket_pattern, pr_title) - return match.group(0) if match else "NO-TICKET" - -# function to write the xml file -def write_xml(element, file_path): - tree = ET.ElementTree(element) - tree.write(file_path, encoding='utf-8', xml_declaration=True) - -# function to update xml files -def update_xml_files(manifest_repo_path, updates): - - repo = Repo(manifest_repo_path) - - # Recursively search for entservices-inputoutput.bb in all subdirectories - bb_file = None - for root, dirs, files in os.walk(manifest_repo_path): - for f in files: - if f == 'entservices-inputoutput.bb': - bb_file = os.path.join(root, f) - break - if bb_file: - break - - if not bb_file: - print("No entservices-inputoutput.bb recipe file found.") - return False - - # Get the new SHA (assume only one update, as in your usage) - new_srcrev = list(updates.values())[0] - changed = False - with open(bb_file, 'r') as f: - lines = f.readlines() - - - - with open(bb_file, 'w') as f: - for line in lines: - if line.strip().startswith('SRCREV ='): - old_line = line.strip() - f.write(f'SRCREV = "{new_srcrev}"\n') - print(f"Updated SRCREV in {bb_file}: {old_line} -> SRCREV = \"{new_srcrev}\"") - changed = True - else: - f.write(line) - - if changed: - repo.git.add(bb_file) - else: - print("No changes were made to SRCREV in the recipe file.") - - return changed -def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): - """ - For each component, update the correct .bb file's SRCREV and the correct generic-pkgrev.inc PV field with the tag. - updates: list of dicts with keys: repo, sha, tag - """ - repo = Repo(manifest_repo_path) - support_repo = None - support_repo_path = generic_support_path - if os.path.isdir(support_repo_path): - try: - support_repo = Repo(support_repo_path) - except Exception as e: - print(f"[DEBUG] Could not open support repo at {support_repo_path}: {e}") - changed = False - support_changed = False - for update in updates: - repo_name = update['repo'] - sha = update['sha'] - tag = update.get('tag') - print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") - # Determine .bb paths (meta and support layer) - bb_file = None - support_bb_file = None - pkgrev_file = None - pkgrev_pv_field = None - if repo_name.startswith('rdkcentral/entservices-'): - comp = repo_name.split('/')[-1] - # Recursively search for entservices-*.bb under meta-rdk-video/recipes-extended/entservices/ - entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') - if os.path.isdir(entservices_dir): - for root, dirs, files in os.walk(entservices_dir): - for f in files: - if f == f'entservices-{comp.split("entservices-")[-1]}.bb': - bb_file = os.path.join(root, f) - break - if bb_file: - break - # For support layer PR - support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') - if os.path.isdir(support_entservices_dir): - for root, dirs, files in os.walk(support_entservices_dir): - for f in files: - if f == f'entservices-{comp.split("entservices-")[-1]}.bb': - support_bb_file = os.path.join(root, f) - break - if support_bb_file: - break - pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') - pkgrev_pv_field = f'PV:pn-{comp}' - elif repo_name == 'rdk-e/rdkservices-cpc': - bb_file = os.path.join(manifest_repo_path.replace('meta-middleware-generic-support', 'meta-rdk-comast-video'), 'rdkservices-comcast.bb') - cspc_support_path = generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support') - support_bb_file = None # Not handled for support layer in this case - pkgrev_file = os.path.join(cspc_support_path, 'conf', 'include', 'cspc-pkgrev.inc') - pkgrev_pv_field = 'rdkservices-comcast_PV' - else: - print(f"[DEBUG] Skipping repo {repo_name} (not handled)") - continue - print(f"[DEBUG] bb_file: {bb_file}") - print(f"[DEBUG] pkgrev_file: {pkgrev_file}") - # Update .bb file SRCREV and PV in meta layer - if bb_file and os.path.exists(bb_file): - with open(bb_file, 'r') as f: - lines = f.readlines() - file_changed = False - tag_to_use = tag if tag else '1.0.0' - with open(bb_file, 'w') as f: - for line in lines: - if line.strip().startswith('SRCREV ='): - print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") - f.write(f'SRCREV = "{sha}"\n') - file_changed = True - elif line.strip().startswith('PV ?='): - print(f"[DEBUG] Updating PV in {bb_file} to {tag_to_use}") - f.write(f'PV ?= "{tag_to_use}"\n') - file_changed = True - else: - f.write(line) - if file_changed: - repo.git.add(bb_file) - changed = True - print(f"[DEBUG] Changed {bb_file}") - else: - print(f"[DEBUG] No change needed for {bb_file}") - else: - print(f"[DEBUG] .bb file does not exist: {bb_file}") - - # Update .bb file SRCREV in support layer (if present) - if support_repo and support_bb_file and os.path.exists(support_bb_file): - with open(support_bb_file, 'r') as f: - lines = f.readlines() - file_changed = False - with open(support_bb_file, 'w') as f: - for line in lines: - if line.strip().startswith('SRCREV ='): - print(f"[DEBUG] Updating SRCREV in {support_bb_file} to {sha}") - f.write(f'SRCREV = "{sha}"\n') - file_changed = True - else: - f.write(line) - if file_changed: - support_repo.git.add(support_bb_file) - support_changed = True - print(f"[DEBUG] Changed {support_bb_file}") - else: - print(f"[DEBUG] No change needed for {support_bb_file}") - elif support_bb_file: - print(f"[DEBUG] Support .bb file does not exist: {support_bb_file}") - - # Only update pkgrev_file in support layer repo - tag_to_use = tag if tag else '1.0.0' - if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - with open(pkgrev_file, 'r') as f: - lines = f.readlines() - file_changed = False - with open(pkgrev_file, 'w') as f: - for line in lines: - if line.strip().startswith(f'{pkgrev_pv_field} ='): - print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use}") - f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - else: - f.write(line) - if file_changed: - support_repo.git.add(pkgrev_file) - support_changed = True - print(f"[DEBUG] Changed {pkgrev_file}") - else: - print(f"[DEBUG] No change needed for {pkgrev_file}") - elif pkgrev_file: - print(f"[DEBUG] pkgrev_file does not exist or support_repo not found: {pkgrev_file}") - print(f"[DEBUG] update_bb_and_pkgrev changed={changed}, support_changed={support_changed}") - return changed, support_changed, support_repo -#Build the PR list description -def build_pr_list_description(prs): - - pr_list = "\n\nList of PRs and Repositories Involved:\n" - for pr in prs: - repo_name = pr['repo'] - sha = pr['sha'] - pr_list += "- Repository: {}, Merge Commit SHA: {}\n".format(repo_name, sha) - return pr_list - -#Commit the changes to the manifest files and push to the feature branch -def commit_and_push(manifest_repo_path, commit_message): - repo = Repo(manifest_repo_path) - if repo.is_dirty(): - # Ensure git user.name and user.email are set - config_writer = repo.config_writer() - try: - user_name = config_writer.get_value('user', 'name', None) - user_email = config_writer.get_value('user', 'email', None) - except Exception: - user_name = None - user_email = None - if not user_name: - config_writer.set_value('user', 'name', os.environ.get('GIT_COMMITTER_NAME', 'github-actions[bot]')) - if not user_email: - config_writer.set_value('user', 'email', os.environ.get('GIT_COMMITTER_EMAIL', 'github-actions[bot]@users.noreply.github.com')) - config_writer.release() - repo.git.commit('-m', commit_message) - repo.git.push('origin', repo.active_branch.name) - else: - print("No changes to commit.") - -#Create a new PR for the updated manifest files -def create_pull_request(github_token, repo_name, head_branch, base_branch, title, description): - g = Github(github_token) - repo = g.get_repo(repo_name) - - try: - # Only create the PR, do NOT merge it. Manual review/merge is required. - pr = repo.create_pull(title=title, body=description, base=base_branch, head=head_branch) - print("PR Created:", pr.html_url) - return pr - except github.GithubException as e: - print("Failed to create PR:", str(e)) - return None - -#Ensure that the label exists in the repository -def ensure_label_exists(repo, label_name, color='FFFFFF'): - labels = repo.get_labels() - label_list = {label.name: label for label in labels} - if label_name not in label_list: - repo.create_label(name=label_name, color=color) - print("Label '{}' created.".format(label_name)) - else: - print("Label '{}' already exists.".format(label_name)) - -#Create or checkout the branch in the local manifest repository -def create_or_checkout_branch(repo, branch_name, base_branch): - - try: - # Fetch all branches from the remote - repo.git.fetch('origin') - - # Check if the branch exists in the remote repository - existing_branches = repo.git.branch('-r') - if 'origin/{}'.format(branch_name) in existing_branches: - print("Branch {} already exists remotely. Stopping further processing.".format(branch_name)) - sys.exit(1) # Exit with a non-zero code to signal that the branch already exists - else: - # Switch to 'base_branch' and pull the latest changes to ensure local repo is up-to-date - repo.git.checkout(base_branch) - repo.git.pull('origin', base_branch) - - # Create and check out the new branch locally - repo.git.checkout('-b', branch_name) - print("Created and checked out new branch: {}".format(branch_name)) - - # Push the newly created branch to the remote - repo.git.push('origin', branch_name) - - except GitCommandError as e: - print("Error checking out branch: {}".format(str(e))) - sys.exit(1) - -def get_tag_for_sha(github_token, repo_full_name, sha): - """ - Return the tag name for a given repo and commit SHA, or None if not found. - """ - g = Github(github_token) - repo = g.get_repo(repo_full_name) - tags = list(repo.get_tags()) - # Try exact match first - for tag in tags: - if tag.commit.sha.startswith(sha): - return tag.name - # If not found, walk back up to 10 parent commits from the merge commit - try: - commit = repo.get_commit(sha) - visited = set() - queue = [(commit, 0)] - max_depth = 10 - while queue: - current_commit, depth = queue.pop(0) - if current_commit.sha in visited or depth > max_depth: - continue - visited.add(current_commit.sha) - for tag in tags: - if tag.commit.sha == current_commit.sha: - return tag.name - # Add parents to queue - for parent in current_commit.parents: - queue.append((parent, depth + 1)) - except Exception as e: - print(f"[DEBUG] Error walking parent commits for tag lookup: {e}") - return None - -def main(): - github_token = os.getenv('GITHUB_TOKEN') - manifest_repo_path = os.getenv('META_REPO_PATH') - generic_support_path = os.getenv('GENERIC_SUPPORT_PATH') # new env var for meta-middleware-generic-support - pr_number = os.getenv('PR_NUMBER') - manifest_repo_name = os.getenv('META_REPO_NAME') - repo_name = os.getenv('GITHUB_REPOSITORY') - repo_owner = os.getenv('GITHUB_ORG') - base_branch = os.getenv('BASE_BRANCH') - - # Check required environment variables - if not generic_support_path: - print("ERROR: GENERIC_SUPPORT_PATH environment variable is not set.") - sys.exit(1) - if not manifest_repo_path: - print("ERROR: META_REPO_PATH environment variable is not set.") - sys.exit(1) - if not github_token: - print("ERROR: GITHUB_TOKEN environment variable is not set.") - sys.exit(1) - if not pr_number: - print("ERROR: PR_NUMBER environment variable is not set.") - sys.exit(1) - if not manifest_repo_name: - print("ERROR: META_REPO_NAME environment variable is not set.") - sys.exit(1) - if not repo_name: - print("ERROR: GITHUB_REPOSITORY environment variable is not set.") - sys.exit(1) - if not repo_owner: - print("ERROR: GITHUB_ORG environment variable is not set.") - sys.exit(1) - if not base_branch: - print("ERROR: BASE_BRANCH environment variable is not set.") - sys.exit(1) - - g = Github(github_token) - repo = g.get_repo(repo_name) - meta_pr = repo.get_pull(int(pr_number)) - - # Extract ticket number - ticket_number = extract_ticket_number(meta_pr.title) - - prs, issue_repo_name, issue_number = fetch_merge_commits(repo_owner, repo_name, int(pr_number), github_token) - # For each PR, get the tag from GitHub - print(f"[DEBUG] PRs to process: {prs}") - updates = [] - for pr in prs: - tag = get_tag_for_sha(github_token, pr['repo'], pr['sha']) - print(f"[DEBUG] Tag for {pr['repo']} at {pr['sha']}: {tag}") - updates.append({'repo': pr['repo'], 'sha': pr['sha'], 'tag': tag}) - - print("Updates to be pushed to feature branch: {}".format(updates)) - - # Generate a feature branch name and PR title/description - feature_branch = f"auto-update-{ticket_number.lower()}" - manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" - manifest_pr_description = build_pr_list_description(updates) - - # Switch to feature branch BEFORE making changes - create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) - - changes_made, support_changed, support_repo = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) - print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") - if changes_made: - commit_and_push( - manifest_repo_path, - "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) - ) - create_pull_request( - github_token, - manifest_repo_name, - feature_branch, - base_branch, - manifest_pr_title, - manifest_pr_description - ) - else: - print("[DEBUG] No changes detected, PR will not be created for meta layer.") - - # Support layer PR - if support_changed: - support_branch = f"auto-update-support-{ticket_number.lower()}" - support_pr_title = f"[Auto] Update support layer for {ticket_number}" - support_pr_description = build_pr_list_description(updates) - if support_repo: - create_or_checkout_branch(support_repo, support_branch, base_branch) - commit_and_push( - generic_support_path, - "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) - ) - create_pull_request( - github_token, - 'rdkcentral/meta-middleware-generic-support', - support_branch, - base_branch, - support_pr_title, - support_pr_description - ) - else: - print("[DEBUG] No support_repo found for PR creation.") -# ...existing code... -if __name__ == '__main__': - main() +name: Update Meta on Component Repo Merge + +on: + workflow_call: + secrets: + RDKCM_RDKE: + required: true + +jobs: + auto_pr_creation_meta: + runs-on: ubuntu-latest + #if: github.event.pull_request.merged == true + steps: + - name: Checkout build_tools_workflows code + uses: actions/checkout@v4 + with: + repository: rdkcentral/build_tools_workflows + path: 'tools' + ref: RDKEMW-4778 + token: ${{ secrets.RDKCM_RDKE }} + + - name: Checkout Meta Repository + uses: actions/checkout@v4 + with: + repository: 'rdkcentral/meta-rdk-video' + path: 'meta_repo' + ref: RDKEMW-4778 + token: ${{ secrets.RDKCM_RDKE }} + + - name: Checkout meta-middleware-generic-support + uses: actions/checkout@v4 + with: + repository: 'rdkcentral/meta-middleware-generic-support' + path: 'rdkcentral/meta-middleware-generic-support' + ref: RDKEMW-4778 + token: ${{ secrets.RDKCM_RDKE }} + + - name: Update Git Config + env: + BOT_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} + run: | + cd meta_repo + git config user.name "bot" + git config user.email "$BOT_EMAIL" + cd .. + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install Python dependencies + run: | + python3 -m pip install --upgrade pip + pip install requests PyGithub GitPython + + - name: Run the update script + env: + GITHUB_TOKEN: ${{ secrets.RDKCM_RDKE }} + GITHUB_ORG: 'rdkcentral' + META_REPO_PATH: ${{ github.workspace }}/meta_repo + META_REPO_NAME: 'rdkcentral/meta-rdk-video' + GENERIC_SUPPORT_PATH: ${{ github.workspace }}/rdkcentral/meta-middleware-generic-support + PR_NUMBER: 111 + BASE_BRANCH: develop + run: | + cd meta_repo + python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_meta.py + cd .. From 2c1a6a4886b4e476a5c5faea3a9e9b27e7ef33a5 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 14:50:00 +0530 Subject: [PATCH 30/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 900f066..2457ec4 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -403,10 +403,30 @@ def get_tag_for_sha(github_token, repo_full_name, sha): """ g = Github(github_token) repo = g.get_repo(repo_full_name) - tags = repo.get_tags() + tags = list(repo.get_tags()) + # Try exact match first for tag in tags: if tag.commit.sha.startswith(sha): return tag.name + # If not found, walk back up to 10 parent commits from the merge commit + try: + commit = repo.get_commit(sha) + visited = set() + queue = [(commit, 0)] + max_depth = 10 + while queue: + current_commit, depth = queue.pop(0) + if current_commit.sha in visited or depth > max_depth: + continue + visited.add(current_commit.sha) + for tag in tags: + if tag.commit.sha == current_commit.sha: + return tag.name + # Add parents to queue + for parent in current_commit.parents: + queue.append((parent, depth + 1)) + except Exception as e: + print(f"[DEBUG] Error walking parent commits for tag lookup: {e}") return None def main(): From 5b2ab2324c0d6d9222362fffbdbbcbd1a8fc4966 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 14:54:56 +0530 Subject: [PATCH 31/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 2457ec4..f047d10 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -408,25 +408,17 @@ def get_tag_for_sha(github_token, repo_full_name, sha): for tag in tags: if tag.commit.sha.startswith(sha): return tag.name - # If not found, walk back up to 10 parent commits from the merge commit + # If not found, check if the tag contains the commit (i.e., the tag's commit is a descendant of sha) try: - commit = repo.get_commit(sha) - visited = set() - queue = [(commit, 0)] - max_depth = 10 - while queue: - current_commit, depth = queue.pop(0) - if current_commit.sha in visited or depth > max_depth: - continue - visited.add(current_commit.sha) - for tag in tags: - if tag.commit.sha == current_commit.sha: + for tag in tags: + tag_commit = repo.get_commit(tag.commit.sha) + # Use the compare API: if sha is an ancestor of tag_commit, it will be in the 'commits' list + comparison = repo.compare(sha, tag_commit.sha) + for c in comparison.commits: + if c.sha.startswith(sha): return tag.name - # Add parents to queue - for parent in current_commit.parents: - queue.append((parent, depth + 1)) except Exception as e: - print(f"[DEBUG] Error walking parent commits for tag lookup: {e}") + print(f"[DEBUG] Error checking if tag contains commit: {e}") return None def main(): From f53c481906f96f31dfb9878662708aad6287f845 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 15:22:11 +0530 Subject: [PATCH 32/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index f047d10..a27df7c 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -408,18 +408,22 @@ def get_tag_for_sha(github_token, repo_full_name, sha): for tag in tags: if tag.commit.sha.startswith(sha): return tag.name - # If not found, check if the tag contains the commit (i.e., the tag's commit is a descendant of sha) + # Find all tags whose commit is a descendant of the given sha (i.e., tag contains the commit) + closest_tag = None + min_ahead_by = None try: for tag in tags: tag_commit = repo.get_commit(tag.commit.sha) - # Use the compare API: if sha is an ancestor of tag_commit, it will be in the 'commits' list comparison = repo.compare(sha, tag_commit.sha) - for c in comparison.commits: - if c.sha.startswith(sha): - return tag.name + # Only consider if tag_commit is ahead (i.e., contains sha) + if comparison.status == 'ahead': + # Find the tag with the smallest number of commits ahead (closest tag) + if min_ahead_by is None or comparison.ahead_by < min_ahead_by: + min_ahead_by = comparison.ahead_by + closest_tag = tag.name except Exception as e: print(f"[DEBUG] Error checking if tag contains commit: {e}") - return None + return closest_tag def main(): github_token = os.getenv('GITHUB_TOKEN') From 5c2ca07ae6c26f80e3ea560fbf86516c1a18e2f7 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 15:25:00 +0530 Subject: [PATCH 33/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index a27df7c..25c4695 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -245,7 +245,9 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): with open(bb_file, 'r') as f: lines = f.readlines() file_changed = False - tag_to_use = tag if tag else '1.0.0' + if not tag: + raise RuntimeError(f"No tag found that contains commit {sha} for repo {repo_name}") + tag_to_use = tag with open(bb_file, 'w') as f: for line in lines: if line.strip().startswith('SRCREV ='): @@ -290,7 +292,9 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] Support .bb file does not exist: {support_bb_file}") # Only update pkgrev_file in support layer repo - tag_to_use = tag if tag else '1.0.0' + if not tag: + raise RuntimeError(f"No tag found that contains commit {sha} for repo {repo_name}") + tag_to_use = tag if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: with open(pkgrev_file, 'r') as f: lines = f.readlines() @@ -475,6 +479,8 @@ def main(): for pr in prs: tag = get_tag_for_sha(github_token, pr['repo'], pr['sha']) print(f"[DEBUG] Tag for {pr['repo']} at {pr['sha']}: {tag}") + if not tag: + raise RuntimeError(f"No tag found that contains commit {pr['sha']} for repo {pr['repo']}") updates.append({'repo': pr['repo'], 'sha': pr['sha'], 'tag': tag}) print("Updates to be pushed to feature branch: {}".format(updates)) @@ -492,7 +498,7 @@ def main(): if changes_made: commit_and_push( manifest_repo_path, - "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) + "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) create_pull_request( github_token, @@ -514,7 +520,7 @@ def main(): create_or_checkout_branch(support_repo, support_branch, base_branch) commit_and_push( generic_support_path, - "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag'] if u['tag'] else '1.0.0'}" for u in updates])) + "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) create_pull_request( github_token, From 8cec58f0d266984771a02fd65fe504205546afc1 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 15:31:17 +0530 Subject: [PATCH 34/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index f6f157b..2220ae1 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -61,7 +61,7 @@ jobs: META_REPO_PATH: ${{ github.workspace }}/meta_repo META_REPO_NAME: 'rdkcentral/meta-rdk-video' GENERIC_SUPPORT_PATH: ${{ github.workspace }}/rdkcentral/meta-middleware-generic-support - PR_NUMBER: 111 + PR_NUMBER: 80 BASE_BRANCH: develop run: | cd meta_repo From d285296038880bc3c80a9875b58a5163d24cda57 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 15:40:40 +0530 Subject: [PATCH 35/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 25c4695..4db2712 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -207,16 +207,19 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - # Recursively search for entservices-*.bb under meta-rdk-video/recipes-extended/entservices/ - entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') - if os.path.isdir(entservices_dir): - for root, dirs, files in os.walk(entservices_dir): - for f in files: - if f == f'entservices-{comp.split("entservices-")[-1]}.bb': - bb_file = os.path.join(root, f) + # Special case for entservices-apis + if comp == 'entservices-apis': + bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'wpe-framework', 'entservices-apis.bb') + else: + entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') + if os.path.isdir(entservices_dir): + for root, dirs, files in os.walk(entservices_dir): + for f in files: + if f == f'entservices-{comp.split("entservices-")[-1]}.bb': + bb_file = os.path.join(root, f) + break + if bb_file: break - if bb_file: - break # For support layer PR support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') if os.path.isdir(support_entservices_dir): @@ -405,6 +408,7 @@ def get_tag_for_sha(github_token, repo_full_name, sha): """ Return the tag name for a given repo and commit SHA, or None if not found. """ + from packaging.version import Version, InvalidVersion g = Github(github_token) repo = g.get_repo(repo_full_name) tags = list(repo.get_tags()) @@ -413,21 +417,25 @@ def get_tag_for_sha(github_token, repo_full_name, sha): if tag.commit.sha.startswith(sha): return tag.name # Find all tags whose commit is a descendant of the given sha (i.e., tag contains the commit) - closest_tag = None - min_ahead_by = None + tags_with_commit = [] try: for tag in tags: tag_commit = repo.get_commit(tag.commit.sha) comparison = repo.compare(sha, tag_commit.sha) - # Only consider if tag_commit is ahead (i.e., contains sha) if comparison.status == 'ahead': - # Find the tag with the smallest number of commits ahead (closest tag) - if min_ahead_by is None or comparison.ahead_by < min_ahead_by: - min_ahead_by = comparison.ahead_by - closest_tag = tag.name + tags_with_commit.append(tag) except Exception as e: print(f"[DEBUG] Error checking if tag contains commit: {e}") - return closest_tag + # Sort tags_with_commit by semantic version (lowest first) + def version_key(tag): + try: + return Version(tag.name) + except InvalidVersion: + return Version('0.0.0') + tags_with_commit.sort(key=version_key) + if tags_with_commit: + return tags_with_commit[0].name + return None def main(): github_token = os.getenv('GITHUB_TOKEN') From 4c1adb6e388d45b6e94ce2b62e3669b09d68e7c1 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 15:43:51 +0530 Subject: [PATCH 36/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 2220ae1..08aef71 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -52,7 +52,7 @@ jobs: - name: Install Python dependencies run: | python3 -m pip install --upgrade pip - pip install requests PyGithub GitPython + pip install requests PyGithub GitPython packaging - name: Run the update script env: From 282654794396e20b3865a7baae5468f5198abe2a Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 15:54:16 +0530 Subject: [PATCH 37/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 4db2712..ef78b02 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -253,11 +253,23 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): tag_to_use = tag with open(bb_file, 'w') as f: for line in lines: - if line.strip().startswith('SRCREV ='): + line_stripped = line.strip() + # Match SRCREV, SRCREV ?=, or SRCREV_ = + if ( + line_stripped.startswith('SRCREV =') or + line_stripped.startswith('SRCREV ?=') or + (line_stripped.startswith(f'SRCREV_{comp.upper()} =') if comp else False) + ): print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") - f.write(f'SRCREV = "{sha}"\n') + # Preserve the assignment type (e.g., =, ?=) + if 'SRCREV ?=' in line_stripped: + f.write(f'SRCREV ?= "{sha}"\n') + elif f'SRCREV_{comp.upper()} =' in line_stripped: + f.write(f'SRCREV_{comp.upper()} = "{sha}"\n') + else: + f.write(f'SRCREV = "{sha}"\n') file_changed = True - elif line.strip().startswith('PV ?='): + elif line_stripped.startswith('PV ?='): print(f"[DEBUG] Updating PV in {bb_file} to {tag_to_use}") f.write(f'PV ?= "{tag_to_use}"\n') file_changed = True From 0961acbe9e9ec73cd9941939c39ecfb3baf286d4 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 17:30:46 +0530 Subject: [PATCH 38/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index ef78b02..1e25ed8 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -254,18 +254,18 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): with open(bb_file, 'w') as f: for line in lines: line_stripped = line.strip() - # Match SRCREV, SRCREV ?=, or SRCREV_ = + # Match SRCREV, SRCREV ?=, or SRCREV_ = (component always lower case) if ( line_stripped.startswith('SRCREV =') or line_stripped.startswith('SRCREV ?=') or - (line_stripped.startswith(f'SRCREV_{comp.upper()} =') if comp else False) + (line_stripped.startswith(f'SRCREV_{comp} =') if comp else False) ): print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") # Preserve the assignment type (e.g., =, ?=) if 'SRCREV ?=' in line_stripped: f.write(f'SRCREV ?= "{sha}"\n') - elif f'SRCREV_{comp.upper()} =' in line_stripped: - f.write(f'SRCREV_{comp.upper()} = "{sha}"\n') + elif f'SRCREV_{comp} =' in line_stripped: + f.write(f'SRCREV_{comp} = "{sha}"\n') else: f.write(f'SRCREV = "{sha}"\n') file_changed = True From cab718f5e5835a486f9fa561084d6a1dc160f0b7 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 17:41:48 +0530 Subject: [PATCH 39/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 1e25ed8..6f3b80f 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -438,6 +438,7 @@ def get_tag_for_sha(github_token, repo_full_name, sha): tags_with_commit.append(tag) except Exception as e: print(f"[DEBUG] Error checking if tag contains commit: {e}") + # Sort tags_with_commit by semantic version (lowest first) def version_key(tag): try: @@ -445,6 +446,24 @@ def version_key(tag): except InvalidVersion: return Version('0.0.0') tags_with_commit.sort(key=version_key) + + # Now, for each tag (in ascending order), check if the previous (lower) tag does NOT contain the commit + for i, tag in enumerate(tags_with_commit): + if i == 0: + # If this is the lowest tag that contains the commit, always return it + return tag.name + prev_tag = tags_with_commit[i-1] + # Check if previous tag contains the commit + try: + prev_tag_commit = repo.get_commit(prev_tag.commit.sha) + comparison = repo.compare(sha, prev_tag_commit.sha) + if comparison.status != 'ahead': + # Previous tag does NOT contain the commit, so this is the first tag that does + return tag.name + except Exception as e: + print(f"[DEBUG] Error comparing with previous tag: {e}") + return tag.name + # Fallback: if all lower tags also contain the commit, return the lowest if tags_with_commit: return tags_with_commit[0].name return None From 07aff6193544828ea234b8e46689c3a0fedf787e Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 17:45:27 +0530 Subject: [PATCH 40/94] Update auto_pr_generation_meta.py --- build_health_check_workflow_scripts/auto_pr_generation_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 6f3b80f..b29461c 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -423,7 +423,7 @@ def get_tag_for_sha(github_token, repo_full_name, sha): from packaging.version import Version, InvalidVersion g = Github(github_token) repo = g.get_repo(repo_full_name) - tags = list(repo.get_tags()) + tags = [tag for tag in repo.get_tags() if re.match(r'^\d+\.\d+\.\d+$', tag.name)] # Try exact match first for tag in tags: if tag.commit.sha.startswith(sha): From c459ceb803b3372086a874a5d6f2672aadbad0b4 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 18:05:27 +0530 Subject: [PATCH 41/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index b29461c..e1e3d8e 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -512,7 +512,31 @@ def main(): ticket_number = extract_ticket_number(meta_pr.title) prs, issue_repo_name, issue_number = fetch_merge_commits(repo_owner, repo_name, int(pr_number), github_token) - # For each PR, get the tag from GitHub + # If PR is linked to an issue, check if all PRs in that issue are merged to the target branch + if issue_number: + print(f"[DEBUG] PR is linked to issue #{issue_number}. Checking all linked PRs...") + all_merged = True + g = Github(github_token) + for pr_info in prs: + repo_full = pr_info['repo'] + sha = pr_info['sha'] + repo_obj = g.get_repo(repo_full) + # Find the PR for this SHA + found = False + for pr in repo_obj.get_pulls(state='closed'): + if pr.merge_commit_sha and pr.merge_commit_sha.startswith(sha): + # Check if merged to the correct base branch + if pr.merged and pr.base.ref == base_branch: + found = True + break + if not found: + all_merged = False + print(f"[DEBUG] Not all PRs are merged to {base_branch}. Waiting...") + break + if not all_merged: + print(f"[DEBUG] Exiting: Not all PRs in issue #{issue_number} are merged to {base_branch}.") + sys.exit(0) + # Continue as before: aggregate all PRs for update print(f"[DEBUG] PRs to process: {prs}") updates = [] for pr in prs: From fe36c65c315c13b6b7fa2443384c98dd367dea18 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 8 Jul 2025 18:06:19 +0530 Subject: [PATCH 42/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index 08aef71..daac7d6 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -62,7 +62,7 @@ jobs: META_REPO_NAME: 'rdkcentral/meta-rdk-video' GENERIC_SUPPORT_PATH: ${{ github.workspace }}/rdkcentral/meta-middleware-generic-support PR_NUMBER: 80 - BASE_BRANCH: develop + BASE_BRANCH: test_develop run: | cd meta_repo python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_meta.py From f4dc46b28710270c68f0bcd017019d0e88ec14c3 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 11:06:27 +0530 Subject: [PATCH 43/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 122 ++++++++++++------ 1 file changed, 83 insertions(+), 39 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index e1e3d8e..9fbe00a 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -548,53 +548,97 @@ def main(): print("Updates to be pushed to feature branch: {}".format(updates)) - # Generate a feature branch name and PR title/description - feature_branch = f"auto-update-{ticket_number.lower()}" - manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" - manifest_pr_description = build_pr_list_description(updates) - - # Switch to feature branch BEFORE making changes - create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) - - changes_made, support_changed, support_repo = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) - print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") - if changes_made: - commit_and_push( - manifest_repo_path, - "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) - ) - create_pull_request( - github_token, - manifest_repo_name, - feature_branch, - base_branch, - manifest_pr_title, - manifest_pr_description - ) + # Only if the PR is linked to an issue, aggregate all PRs under a single branch for the issue + if issue_number: + feature_branch = f"auto-update-{ticket_number.lower()}" + manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" + manifest_pr_description = build_pr_list_description(updates) + # Switch to feature branch BEFORE making changes + create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) + changes_made, support_changed, support_repo = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") + if changes_made: + commit_and_push( + manifest_repo_path, + "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + ) + create_pull_request( + github_token, + manifest_repo_name, + feature_branch, + base_branch, + manifest_pr_title, + manifest_pr_description + ) + else: + print("[DEBUG] No changes detected, PR will not be created for meta layer.") + + # Support layer PR + if support_changed: + support_branch = f"auto-update-support-{ticket_number.lower()}" + support_pr_title = f"[Auto] Update support layer for {ticket_number}" + support_pr_description = build_pr_list_description(updates) + if support_repo: + create_or_checkout_branch(support_repo, support_branch, base_branch) + commit_and_push( + generic_support_path, + "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + ) + create_pull_request( + github_token, + 'rdkcentral/meta-middleware-generic-support', + support_branch, + base_branch, + support_pr_title, + support_pr_description + ) + else: + print("[DEBUG] No support_repo found for PR creation.") else: - print("[DEBUG] No changes detected, PR will not be created for meta layer.") - - # Support layer PR - if support_changed: - support_branch = f"auto-update-support-{ticket_number.lower()}" - support_pr_title = f"[Auto] Update support layer for {ticket_number}" - support_pr_description = build_pr_list_description(updates) - if support_repo: - create_or_checkout_branch(support_repo, support_branch, base_branch) + # If not linked to an issue, run for the individual PR only (separate branch) + feature_branch = f"auto-update-{ticket_number.lower()}-{pr_number}" + manifest_pr_title = f"[Auto] Update meta layer for {ticket_number} (PR {pr_number})" + manifest_pr_description = build_pr_list_description(updates) + create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) + changes_made, support_changed, support_repo = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") + if changes_made: commit_and_push( - generic_support_path, - "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + manifest_repo_path, + "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) create_pull_request( github_token, - 'rdkcentral/meta-middleware-generic-support', - support_branch, + manifest_repo_name, + feature_branch, base_branch, - support_pr_title, - support_pr_description + manifest_pr_title, + manifest_pr_description ) else: - print("[DEBUG] No support_repo found for PR creation.") + print("[DEBUG] No changes detected, PR will not be created for meta layer.") + + # Support layer PR + if support_changed: + support_branch = f"auto-update-support-{ticket_number.lower()}-{pr_number}" + support_pr_title = f"[Auto] Update support layer for {ticket_number} (PR {pr_number})" + support_pr_description = build_pr_list_description(updates) + if support_repo: + create_or_checkout_branch(support_repo, support_branch, base_branch) + commit_and_push( + generic_support_path, + "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + ) + create_pull_request( + github_token, + 'rdkcentral/meta-middleware-generic-support', + support_branch, + base_branch, + support_pr_title, + support_pr_description + ) + else: + print("[DEBUG] No support_repo found for PR creation.") # ...existing code... if __name__ == '__main__': main() From 192320bae4ccb2050a62f7fc9612c604e4ed05c6 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 11:11:56 +0530 Subject: [PATCH 44/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index daac7d6..ec2b136 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -61,7 +61,7 @@ jobs: META_REPO_PATH: ${{ github.workspace }}/meta_repo META_REPO_NAME: 'rdkcentral/meta-rdk-video' GENERIC_SUPPORT_PATH: ${{ github.workspace }}/rdkcentral/meta-middleware-generic-support - PR_NUMBER: 80 + PR_NUMBER: ${{ github.event.pull_request.number }} BASE_BRANCH: test_develop run: | cd meta_repo From b65a1ba2609cdd618ccc24edcc279e2a26569869 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 11:46:24 +0530 Subject: [PATCH 45/94] Update auto_pr_generation_meta.py --- build_health_check_workflow_scripts/auto_pr_generation_meta.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 9fbe00a..5d31c44 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -543,7 +543,8 @@ def main(): tag = get_tag_for_sha(github_token, pr['repo'], pr['sha']) print(f"[DEBUG] Tag for {pr['repo']} at {pr['sha']}: {tag}") if not tag: - raise RuntimeError(f"No tag found that contains commit {pr['sha']} for repo {pr['repo']}") + print(f"[WARNING] No tag found that contains commit {pr['sha']} for repo {pr['repo']}. Setting tag as None.") + tag = None updates.append({'repo': pr['repo'], 'sha': pr['sha'], 'tag': tag}) print("Updates to be pushed to feature branch: {}".format(updates)) From f5a139050563734f102f1d5714e5c63a0eb3588f Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 11:51:27 +0530 Subject: [PATCH 46/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 5d31c44..60bbbc3 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -249,8 +249,10 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): lines = f.readlines() file_changed = False if not tag: - raise RuntimeError(f"No tag found that contains commit {sha} for repo {repo_name}") - tag_to_use = tag + print(f"[WARNING] No tag found that contains commit {sha} for repo {repo_name}. Setting tag as None.") + tag_to_use = None + else: + tag_to_use = tag with open(bb_file, 'w') as f: for line in lines: line_stripped = line.strip() @@ -308,8 +310,10 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): # Only update pkgrev_file in support layer repo if not tag: - raise RuntimeError(f"No tag found that contains commit {sha} for repo {repo_name}") - tag_to_use = tag + print(f"[WARNING] No tag found that contains commit {sha} for repo {repo_name}. Setting tag as None.") + tag_to_use = None + else: + tag_to_use = tag if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: with open(pkgrev_file, 'r') as f: lines = f.readlines() From fa13d129cb30b92ad653326034238bf2d401a8f0 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 12:54:37 +0530 Subject: [PATCH 47/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 60bbbc3..5e8ec40 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -401,9 +401,19 @@ def create_or_checkout_branch(repo, branch_name, base_branch): # Check if the branch exists in the remote repository existing_branches = repo.git.branch('-r') - if 'origin/{}'.format(branch_name) in existing_branches: - print("Branch {} already exists remotely. Stopping further processing.".format(branch_name)) - sys.exit(1) # Exit with a non-zero code to signal that the branch already exists + if f'origin/{branch_name}' in existing_branches: + print(f"Branch {branch_name} already exists remotely. Checking out and updating it.") + # If we are not already on the branch, check it out + current_branch = repo.active_branch.name + if current_branch != branch_name: + # If branch does not exist locally, create tracking branch + local_branches = [b.name for b in repo.branches] + if branch_name not in local_branches: + repo.git.checkout('-b', branch_name, f'origin/{branch_name}') + else: + repo.git.checkout(branch_name) + # Pull latest changes from remote + repo.git.pull('origin', branch_name) else: # Switch to 'base_branch' and pull the latest changes to ensure local repo is up-to-date repo.git.checkout(base_branch) @@ -411,13 +421,13 @@ def create_or_checkout_branch(repo, branch_name, base_branch): # Create and check out the new branch locally repo.git.checkout('-b', branch_name) - print("Created and checked out new branch: {}".format(branch_name)) + print(f"Created and checked out new branch: {branch_name}") # Push the newly created branch to the remote repo.git.push('origin', branch_name) except GitCommandError as e: - print("Error checking out branch: {}".format(str(e))) + print(f"Error checking out branch: {str(e)}") sys.exit(1) def get_tag_for_sha(github_token, repo_full_name, sha): From 9deb0985462854d154858c13845755b206e2777b Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 13:01:59 +0530 Subject: [PATCH 48/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 5e8ec40..66fc0ef 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -403,6 +403,13 @@ def create_or_checkout_branch(repo, branch_name, base_branch): existing_branches = repo.git.branch('-r') if f'origin/{branch_name}' in existing_branches: print(f"Branch {branch_name} already exists remotely. Checking out and updating it.") + # Commit any outstanding changes before switching branches + if repo.is_dirty(): + try: + repo.git.add('--all') + repo.git.commit('-m', 'WIP: commit outstanding changes before branch switch') + except Exception as e: + print(f"[DEBUG] Could not commit outstanding changes: {e}") # If we are not already on the branch, check it out current_branch = repo.active_branch.name if current_branch != branch_name: From 1d585605d3e652cab54a4834a94797066ce2b47e Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 14:16:08 +0530 Subject: [PATCH 49/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 66fc0ef..32196a1 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -399,6 +399,20 @@ def create_or_checkout_branch(repo, branch_name, base_branch): # Fetch all branches from the remote repo.git.fetch('origin') + # Ensure git user.name and user.email are set for this repo + config_writer = repo.config_writer() + try: + user_name = config_writer.get_value('user', 'name', None) + user_email = config_writer.get_value('user', 'email', None) + except Exception: + user_name = None + user_email = None + if not user_name: + config_writer.set_value('user', 'name', os.environ.get('GIT_COMMITTER_NAME', 'github-actions[bot]')) + if not user_email: + config_writer.set_value('user', 'email', os.environ.get('GIT_COMMITTER_EMAIL', 'github-actions[bot]@users.noreply.github.com')) + config_writer.release() + # Check if the branch exists in the remote repository existing_branches = repo.git.branch('-r') if f'origin/{branch_name}' in existing_branches: From 5fad02c36e4b3b71aa2eb3c755bbf5226bce0426 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 14:33:51 +0530 Subject: [PATCH 50/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 32196a1..70a73c0 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -207,37 +207,47 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] + print(f"[DBG] Component: {comp}") # Special case for entservices-apis if comp == 'entservices-apis': bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'wpe-framework', 'entservices-apis.bb') + print(f"[DBG] entservices-apis special case, bb_file: {bb_file}") else: entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') + print(f"[DBG] Searching for .bb in {entservices_dir}") if os.path.isdir(entservices_dir): for root, dirs, files in os.walk(entservices_dir): for f in files: + print(f"[DBG] Checking file: {f}") if f == f'entservices-{comp.split("entservices-")[-1]}.bb': bb_file = os.path.join(root, f) + print(f"[DBG] Found bb_file: {bb_file}") break if bb_file: break # For support layer PR support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') + print(f"[DBG] Searching for support .bb in {support_entservices_dir}") if os.path.isdir(support_entservices_dir): for root, dirs, files in os.walk(support_entservices_dir): for f in files: + print(f"[DBG] Support layer: checking file: {f}") if f == f'entservices-{comp.split("entservices-")[-1]}.bb': support_bb_file = os.path.join(root, f) + print(f"[DBG] Found support_bb_file: {support_bb_file}") break if support_bb_file: break pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') pkgrev_pv_field = f'PV:pn-{comp}' + print(f"[DBG] pkgrev_file: {pkgrev_file}, pkgrev_pv_field: {pkgrev_pv_field}") elif repo_name == 'rdk-e/rdkservices-cpc': bb_file = os.path.join(manifest_repo_path.replace('meta-middleware-generic-support', 'meta-rdk-comast-video'), 'rdkservices-comcast.bb') cspc_support_path = generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support') support_bb_file = None # Not handled for support layer in this case pkgrev_file = os.path.join(cspc_support_path, 'conf', 'include', 'cspc-pkgrev.inc') pkgrev_pv_field = 'rdkservices-comcast_PV' + print(f"[DBG] cspc case, bb_file: {bb_file}, pkgrev_file: {pkgrev_file}, pkgrev_pv_field: {pkgrev_pv_field}") else: print(f"[DEBUG] Skipping repo {repo_name} (not handled)") continue @@ -245,6 +255,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] pkgrev_file: {pkgrev_file}") # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): + print(f"[DBG] Opening bb_file: {bb_file}") with open(bb_file, 'r') as f: lines = f.readlines() file_changed = False @@ -254,8 +265,9 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: tag_to_use = tag with open(bb_file, 'w') as f: - for line in lines: + for idx, line in enumerate(lines): line_stripped = line.strip() + print(f"[DBG] bb_file line {idx}: {line_stripped}") # Match SRCREV, SRCREV ?=, or SRCREV_ = (component always lower case) if ( line_stripped.startswith('SRCREV =') or @@ -288,11 +300,13 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): # Update .bb file SRCREV in support layer (if present) if support_repo and support_bb_file and os.path.exists(support_bb_file): + print(f"[DBG] Opening support_bb_file: {support_bb_file}") with open(support_bb_file, 'r') as f: lines = f.readlines() file_changed = False with open(support_bb_file, 'w') as f: - for line in lines: + for idx, line in enumerate(lines): + print(f"[DBG] support_bb_file line {idx}: {line.strip()}") if line.strip().startswith('SRCREV ='): print(f"[DEBUG] Updating SRCREV in {support_bb_file} to {sha}") f.write(f'SRCREV = "{sha}"\n') @@ -315,17 +329,26 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: tag_to_use = tag if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + print(f"[DBG] Opening pkgrev_file: {pkgrev_file}") with open(pkgrev_file, 'r') as f: lines = f.readlines() file_changed = False + found_pv = False with open(pkgrev_file, 'w') as f: - for line in lines: + for idx, line in enumerate(lines): + print(f"[DBG] pkgrev_file line {idx}: {line.strip()}") if line.strip().startswith(f'{pkgrev_pv_field} ='): - print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use}") + print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use} (line {idx})") f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True + found_pv = True else: f.write(line) + if not found_pv: + print(f"[DEBUG] PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") + with open(pkgrev_file, 'a') as f_append: + f_append.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True if file_changed: support_repo.git.add(pkgrev_file) support_changed = True From 1e7a00d4a37bd23979b1c1d65e27248b112c4367 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 18:03:04 +0530 Subject: [PATCH 51/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 70a73c0..988c7c2 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -322,9 +322,13 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): elif support_bb_file: print(f"[DEBUG] Support .bb file does not exist: {support_bb_file}") + # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- + print(f"[DEBUG] update_bb_and_pkgrev: comp={comp}, pkgrev_pv_field={pkgrev_pv_field}, tag={tag}, pkgrev_file={pkgrev_file}") # Only update pkgrev_file in support layer repo + # --- DEBUG: Always log intent to update PV, even if tag is None --- + print(f"[DEBUG] Attempting PV update for {pkgrev_pv_field} in {pkgrev_file} with tag_to_use={tag if tag else None}") if not tag: - print(f"[WARNING] No tag found that contains commit {sha} for repo {repo_name}. Setting tag as None.") + print(f"[WARNING] No tag found that contains commit {sha} for repo {repo_name}. Setting PV to None for {pkgrev_pv_field} in {pkgrev_file}.") tag_to_use = None else: tag_to_use = tag @@ -349,6 +353,9 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): with open(pkgrev_file, 'a') as f_append: f_append.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True + print(f"[DEBUG] After write: file_changed={file_changed}, found_pv={found_pv}") + with open(pkgrev_file, 'r') as f_check: + print(f"[DEBUG] pkgrev_file content after update:\n" + f_check.read()) if file_changed: support_repo.git.add(pkgrev_file) support_changed = True From b8e9bb34c9217ef92b840c56b19a2be86bc1aa48 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 18:12:29 +0530 Subject: [PATCH 52/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 988c7c2..de6ab21 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -379,6 +379,8 @@ def build_pr_list_description(prs): #Commit the changes to the manifest files and push to the feature branch def commit_and_push(manifest_repo_path, commit_message): repo = Repo(manifest_repo_path) + print(f"[DEBUG] commit_and_push: current branch is {repo.active_branch.name}") + print(f"[DEBUG] commit_and_push: git status before commit:\n" + repo.git.status()) if repo.is_dirty(): # Ensure git user.name and user.email are set config_writer = repo.config_writer() @@ -394,7 +396,9 @@ def commit_and_push(manifest_repo_path, commit_message): config_writer.set_value('user', 'email', os.environ.get('GIT_COMMITTER_EMAIL', 'github-actions[bot]@users.noreply.github.com')) config_writer.release() repo.git.commit('-m', commit_message) + print(f"[DEBUG] commit_and_push: git log after commit:\n" + repo.git.log('-n', '2', '--oneline')) repo.git.push('origin', repo.active_branch.name) + print(f"[DEBUG] commit_and_push: git status after push:\n" + repo.git.status()) else: print("No changes to commit.") From 643de4df26c0ef1b2511e70045b8296ad90f003b Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 9 Jul 2025 18:26:05 +0530 Subject: [PATCH 53/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 149 +++++++++++------- 1 file changed, 92 insertions(+), 57 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index de6ab21..f5774dc 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -256,40 +256,51 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): print(f"[DBG] Opening bb_file: {bb_file}") - with open(bb_file, 'r') as f: - lines = f.readlines() + with open(bb_file, 'r', newline='') as f: + old_lines = f.readlines() file_changed = False if not tag: print(f"[WARNING] No tag found that contains commit {sha} for repo {repo_name}. Setting tag as None.") tag_to_use = None else: tag_to_use = tag - with open(bb_file, 'w') as f: - for idx, line in enumerate(lines): - line_stripped = line.strip() - print(f"[DBG] bb_file line {idx}: {line_stripped}") - # Match SRCREV, SRCREV ?=, or SRCREV_ = (component always lower case) - if ( - line_stripped.startswith('SRCREV =') or - line_stripped.startswith('SRCREV ?=') or - (line_stripped.startswith(f'SRCREV_{comp} =') if comp else False) - ): - print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") - # Preserve the assignment type (e.g., =, ?=) - if 'SRCREV ?=' in line_stripped: - f.write(f'SRCREV ?= "{sha}"\n') - elif f'SRCREV_{comp} =' in line_stripped: - f.write(f'SRCREV_{comp} = "{sha}"\n') - else: - f.write(f'SRCREV = "{sha}"\n') - file_changed = True - elif line_stripped.startswith('PV ?='): - print(f"[DEBUG] Updating PV in {bb_file} to {tag_to_use}") - f.write(f'PV ?= "{tag_to_use}"\n') - file_changed = True + new_lines = [] + for idx, line in enumerate(old_lines): + line_stripped = line.strip() + print(f"[DBG] bb_file line {idx}: {line_stripped}") + # Match SRCREV, SRCREV ?=, or SRCREV_ = (component always lower case) + if ( + line_stripped.startswith('SRCREV =') or + line_stripped.startswith('SRCREV ?=') or + (line_stripped.startswith(f'SRCREV_{comp} =') if comp else False) + ): + print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") + # Preserve the assignment type (e.g., =, ?=) + if 'SRCREV ?=' in line_stripped: + new_lines.append(f'SRCREV ?= "{sha}"\n') + elif f'SRCREV_{comp} =' in line_stripped: + new_lines.append(f'SRCREV_{comp} = "{sha}"\n') else: - f.write(line) - if file_changed: + new_lines.append(f'SRCREV = "{sha}"\n') + file_changed = True + elif line_stripped.startswith('PV ?='): + print(f"[DEBUG] Updating PV in {bb_file} to {tag_to_use}") + new_lines.append(f'PV ?= "{tag_to_use}"\n') + file_changed = True + else: + new_lines.append(line) + # Print diff for debugging + if old_lines != new_lines: + print("[DEBUG] Diff for bb_file:") + for i, (old, new) in enumerate(zip(old_lines, new_lines)): + if old != new: + print(f"- {old.rstrip()}\n+ {new.rstrip()}") + else: + print("[DEBUG] No content change in bb_file.") + # Write only if changed + if old_lines != new_lines: + with open(bb_file, 'w', newline='\n') as f: + f.writelines(new_lines) repo.git.add(bb_file) changed = True print(f"[DEBUG] Changed {bb_file}") @@ -301,19 +312,29 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): # Update .bb file SRCREV in support layer (if present) if support_repo and support_bb_file and os.path.exists(support_bb_file): print(f"[DBG] Opening support_bb_file: {support_bb_file}") - with open(support_bb_file, 'r') as f: - lines = f.readlines() + with open(support_bb_file, 'r', newline='') as f: + old_lines = f.readlines() file_changed = False - with open(support_bb_file, 'w') as f: - for idx, line in enumerate(lines): - print(f"[DBG] support_bb_file line {idx}: {line.strip()}") - if line.strip().startswith('SRCREV ='): - print(f"[DEBUG] Updating SRCREV in {support_bb_file} to {sha}") - f.write(f'SRCREV = "{sha}"\n') - file_changed = True - else: - f.write(line) - if file_changed: + new_lines = [] + for idx, line in enumerate(old_lines): + print(f"[DBG] support_bb_file line {idx}: {line.strip()}") + if line.strip().startswith('SRCREV ='): + print(f"[DEBUG] Updating SRCREV in {support_bb_file} to {sha}") + new_lines.append(f'SRCREV = "{sha}"\n') + file_changed = True + else: + new_lines.append(line) + # Print diff for debugging + if old_lines != new_lines: + print("[DEBUG] Diff for support_bb_file:") + for i, (old, new) in enumerate(zip(old_lines, new_lines)): + if old != new: + print(f"- {old.rstrip()}\n+ {new.rstrip()}") + else: + print("[DEBUG] No content change in support_bb_file.") + if old_lines != new_lines: + with open(support_bb_file, 'w', newline='\n') as f: + f.writelines(new_lines) support_repo.git.add(support_bb_file) support_changed = True print(f"[DEBUG] Changed {support_bb_file}") @@ -334,29 +355,38 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): tag_to_use = tag if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: print(f"[DBG] Opening pkgrev_file: {pkgrev_file}") - with open(pkgrev_file, 'r') as f: - lines = f.readlines() + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() file_changed = False found_pv = False - with open(pkgrev_file, 'w') as f: - for idx, line in enumerate(lines): - print(f"[DBG] pkgrev_file line {idx}: {line.strip()}") - if line.strip().startswith(f'{pkgrev_pv_field} ='): - print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use} (line {idx})") - f.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - found_pv = True - else: - f.write(line) + new_lines = [] + for idx, line in enumerate(old_lines): + print(f"[DBG] pkgrev_file line {idx}: {line.strip()}") + if line.strip().startswith(f'{pkgrev_pv_field} ='): + print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use} (line {idx})") + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + found_pv = True + else: + new_lines.append(line) if not found_pv: print(f"[DEBUG] PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") - with open(pkgrev_file, 'a') as f_append: - f_append.write(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True - print(f"[DEBUG] After write: file_changed={file_changed}, found_pv={found_pv}") - with open(pkgrev_file, 'r') as f_check: - print(f"[DEBUG] pkgrev_file content after update:\n" + f_check.read()) - if file_changed: + # Print diff for debugging + if old_lines != new_lines: + print("[DEBUG] Diff for pkgrev_file:") + for i, (old, new) in enumerate(zip(old_lines, new_lines)): + if old != new: + print(f"- {old.rstrip()}\n+ {new.rstrip()}") + if len(new_lines) > len(old_lines): + for i in range(len(old_lines), len(new_lines)): + print(f"+ {new_lines[i].rstrip()}") + else: + print("[DEBUG] No content change in pkgrev_file.") + if old_lines != new_lines: + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) support_repo.git.add(pkgrev_file) support_changed = True print(f"[DEBUG] Changed {pkgrev_file}") @@ -407,6 +437,11 @@ def create_pull_request(github_token, repo_name, head_branch, base_branch, title g = Github(github_token) repo = g.get_repo(repo_name) + # Check if a PR already exists for this branch + pulls = repo.get_pulls(state='open', head=f"{repo.owner.login}:{head_branch}") + for pr in pulls: + print(f"[DEBUG] Existing PR found for branch {head_branch}: {pr.html_url}") + return pr try: # Only create the PR, do NOT merge it. Manual review/merge is required. pr = repo.create_pull(title=title, body=description, base=base_branch, head=head_branch) From 7728b4bd4602552443e13a1664ad18c2ccd798e2 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 10 Jul 2025 12:37:04 +0530 Subject: [PATCH 54/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 51 +++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index f5774dc..3c1cf55 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -432,6 +432,7 @@ def commit_and_push(manifest_repo_path, commit_message): else: print("No changes to commit.") + #Create a new PR for the updated manifest files def create_pull_request(github_token, repo_name, head_branch, base_branch, title, description): g = Github(github_token) @@ -451,6 +452,14 @@ def create_pull_request(github_token, repo_name, head_branch, base_branch, title print("Failed to create PR:", str(e)) return None +# Create a summary issue linking meta*video and meta*support auto PRs +def create_summary_issue(github_token, repo_name, issue_title, issue_body): + g = Github(github_token) + repo = g.get_repo(repo_name) + issue = repo.create_issue(title=issue_title, body=issue_body) + print(f"Issue created: {issue.html_url}") + return issue + #Ensure that the label exists in the repository def ensure_label_exists(repo, label_name, color='FFFFFF'): labels = repo.get_labels() @@ -654,6 +663,8 @@ def main(): print("Updates to be pushed to feature branch: {}".format(updates)) # Only if the PR is linked to an issue, aggregate all PRs under a single branch for the issue + meta_pr_obj = None + support_pr_obj = None if issue_number: feature_branch = f"auto-update-{ticket_number.lower()}" manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" @@ -667,7 +678,7 @@ def main(): manifest_repo_path, "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) - create_pull_request( + meta_pr_obj = create_pull_request( github_token, manifest_repo_name, feature_branch, @@ -689,7 +700,7 @@ def main(): generic_support_path, "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) - create_pull_request( + support_pr_obj = create_pull_request( github_token, 'rdkcentral/meta-middleware-generic-support', support_branch, @@ -699,6 +710,22 @@ def main(): ) else: print("[DEBUG] No support_repo found for PR creation.") + # Create summary issue if at least one PR was created + if meta_pr_obj or support_pr_obj: + pr_links = [] + if meta_pr_obj: + pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") + if support_pr_obj: + pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") + issue_title = f"[Auto] Summary for {ticket_number} Updates" + issue_body = ( + f"## Automated Update Summary for {ticket_number}\n\n" + f"### PRs Created:\n" + + "\n".join(pr_links) + + "\n\n### Details:\n" + + build_pr_list_description(updates) + ) + create_summary_issue(github_token, manifest_repo_name, issue_title, issue_body) else: # If not linked to an issue, run for the individual PR only (separate branch) feature_branch = f"auto-update-{ticket_number.lower()}-{pr_number}" @@ -712,7 +739,7 @@ def main(): manifest_repo_path, "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) - create_pull_request( + meta_pr_obj = create_pull_request( github_token, manifest_repo_name, feature_branch, @@ -734,7 +761,7 @@ def main(): generic_support_path, "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) - create_pull_request( + support_pr_obj = create_pull_request( github_token, 'rdkcentral/meta-middleware-generic-support', support_branch, @@ -744,6 +771,22 @@ def main(): ) else: print("[DEBUG] No support_repo found for PR creation.") + # Create summary issue if at least one PR was created + if meta_pr_obj or support_pr_obj: + pr_links = [] + if meta_pr_obj: + pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") + if support_pr_obj: + pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") + issue_title = f"[Auto] Summary for {ticket_number} (PR {pr_number}) Updates" + issue_body = ( + f"## Automated Update Summary for {ticket_number} (PR {pr_number})\n\n" + f"### PRs Created:\n" + + "\n".join(pr_links) + + "\n\n### Details:\n" + + build_pr_list_description(updates) + ) + create_summary_issue(github_token, manifest_repo_name, issue_title, issue_body) # ...existing code... if __name__ == '__main__': main() From a79e7f548acd30fa472f728e8c622307d598943b Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Thu, 10 Jul 2025 12:38:49 +0530 Subject: [PATCH 55/94] Update auto_pr_generation_meta.py From 8e4817c2f293a1b69f37e158c72c796f18fe978c Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Fri, 11 Jul 2025 15:21:10 +0530 Subject: [PATCH 56/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 167 +++++++----------- 1 file changed, 68 insertions(+), 99 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 3c1cf55..15a93d0 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -227,35 +227,28 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): break # For support layer PR support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') - print(f"[DBG] Searching for support .bb in {support_entservices_dir}") + # Searching for support .bb in support_entservices_dir if os.path.isdir(support_entservices_dir): for root, dirs, files in os.walk(support_entservices_dir): for f in files: - print(f"[DBG] Support layer: checking file: {f}") + # Support layer: checking file: {f} if f == f'entservices-{comp.split("entservices-")[-1]}.bb': support_bb_file = os.path.join(root, f) - print(f"[DBG] Found support_bb_file: {support_bb_file}") + # Found support_bb_file: {support_bb_file} break if support_bb_file: break pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') pkgrev_pv_field = f'PV:pn-{comp}' - print(f"[DBG] pkgrev_file: {pkgrev_file}, pkgrev_pv_field: {pkgrev_pv_field}") - elif repo_name == 'rdk-e/rdkservices-cpc': - bb_file = os.path.join(manifest_repo_path.replace('meta-middleware-generic-support', 'meta-rdk-comast-video'), 'rdkservices-comcast.bb') - cspc_support_path = generic_support_path.replace('meta-middleware-generic-support', 'meta-middleware-cspc-support') - support_bb_file = None # Not handled for support layer in this case - pkgrev_file = os.path.join(cspc_support_path, 'conf', 'include', 'cspc-pkgrev.inc') - pkgrev_pv_field = 'rdkservices-comcast_PV' - print(f"[DBG] cspc case, bb_file: {bb_file}, pkgrev_file: {pkgrev_file}, pkgrev_pv_field: {pkgrev_pv_field}") + # pkgrev_file: {pkgrev_file}, pkgrev_pv_field: {pkgrev_pv_field} + # ...existing code... else: print(f"[DEBUG] Skipping repo {repo_name} (not handled)") continue - print(f"[DEBUG] bb_file: {bb_file}") - print(f"[DEBUG] pkgrev_file: {pkgrev_file}") + # Informational: bb_file and pkgrev_file # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): - print(f"[DBG] Opening bb_file: {bb_file}") + # Opening bb_file: {bb_file} with open(bb_file, 'r', newline='') as f: old_lines = f.readlines() file_changed = False @@ -267,14 +260,14 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): new_lines = [] for idx, line in enumerate(old_lines): line_stripped = line.strip() - print(f"[DBG] bb_file line {idx}: {line_stripped}") + # bb_file line {idx}: {line_stripped} # Match SRCREV, SRCREV ?=, or SRCREV_ = (component always lower case) if ( line_stripped.startswith('SRCREV =') or line_stripped.startswith('SRCREV ?=') or (line_stripped.startswith(f'SRCREV_{comp} =') if comp else False) ): - print(f"[DEBUG] Updating SRCREV in {bb_file} to {sha}") + # Updating SRCREV in {bb_file} to {sha} # Preserve the assignment type (e.g., =, ?=) if 'SRCREV ?=' in line_stripped: new_lines.append(f'SRCREV ?= "{sha}"\n') @@ -284,117 +277,93 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): new_lines.append(f'SRCREV = "{sha}"\n') file_changed = True elif line_stripped.startswith('PV ?='): - print(f"[DEBUG] Updating PV in {bb_file} to {tag_to_use}") + # Updating PV in {bb_file} to {tag_to_use} new_lines.append(f'PV ?= "{tag_to_use}"\n') file_changed = True else: new_lines.append(line) # Print diff for debugging - if old_lines != new_lines: - print("[DEBUG] Diff for bb_file:") - for i, (old, new) in enumerate(zip(old_lines, new_lines)): - if old != new: - print(f"- {old.rstrip()}\n+ {new.rstrip()}") - else: - print("[DEBUG] No content change in bb_file.") + # Diff and content change info removed # Write only if changed if old_lines != new_lines: with open(bb_file, 'w', newline='\n') as f: f.writelines(new_lines) repo.git.add(bb_file) changed = True - print(f"[DEBUG] Changed {bb_file}") + print(f"Updated {bb_file}") else: - print(f"[DEBUG] No change needed for {bb_file}") + print(f"No change needed for {bb_file}") else: print(f"[DEBUG] .bb file does not exist: {bb_file}") # Update .bb file SRCREV in support layer (if present) if support_repo and support_bb_file and os.path.exists(support_bb_file): - print(f"[DBG] Opening support_bb_file: {support_bb_file}") + # Opening support_bb_file: {support_bb_file} with open(support_bb_file, 'r', newline='') as f: old_lines = f.readlines() file_changed = False new_lines = [] for idx, line in enumerate(old_lines): - print(f"[DBG] support_bb_file line {idx}: {line.strip()}") + # support_bb_file line {idx}: {line.strip()} if line.strip().startswith('SRCREV ='): - print(f"[DEBUG] Updating SRCREV in {support_bb_file} to {sha}") + # Updating SRCREV in {support_bb_file} to {sha} new_lines.append(f'SRCREV = "{sha}"\n') file_changed = True else: new_lines.append(line) # Print diff for debugging - if old_lines != new_lines: - print("[DEBUG] Diff for support_bb_file:") - for i, (old, new) in enumerate(zip(old_lines, new_lines)): - if old != new: - print(f"- {old.rstrip()}\n+ {new.rstrip()}") - else: - print("[DEBUG] No content change in support_bb_file.") + # Diff and content change info removed if old_lines != new_lines: with open(support_bb_file, 'w', newline='\n') as f: f.writelines(new_lines) support_repo.git.add(support_bb_file) support_changed = True - print(f"[DEBUG] Changed {support_bb_file}") + print(f"Updated {support_bb_file}") else: - print(f"[DEBUG] No change needed for {support_bb_file}") + print(f"No change needed for {support_bb_file}") elif support_bb_file: print(f"[DEBUG] Support .bb file does not exist: {support_bb_file}") # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- - print(f"[DEBUG] update_bb_and_pkgrev: comp={comp}, pkgrev_pv_field={pkgrev_pv_field}, tag={tag}, pkgrev_file={pkgrev_file}") - # Only update pkgrev_file in support layer repo - # --- DEBUG: Always log intent to update PV, even if tag is None --- - print(f"[DEBUG] Attempting PV update for {pkgrev_pv_field} in {pkgrev_file} with tag_to_use={tag if tag else None}") + # Informational: update_bb_and_pkgrev status if not tag: - print(f"[WARNING] No tag found that contains commit {sha} for repo {repo_name}. Setting PV to None for {pkgrev_pv_field} in {pkgrev_file}.") + print(f"No tag found that contains commit {sha} for repo {repo_name}. Setting PV to None for {pkgrev_pv_field} in {pkgrev_file}.") tag_to_use = None else: tag_to_use = tag if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - print(f"[DBG] Opening pkgrev_file: {pkgrev_file}") + # Opening pkgrev_file: {pkgrev_file} with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() file_changed = False found_pv = False new_lines = [] for idx, line in enumerate(old_lines): - print(f"[DBG] pkgrev_file line {idx}: {line.strip()}") + # pkgrev_file line {idx}: {line.strip()} if line.strip().startswith(f'{pkgrev_pv_field} ='): - print(f"[DEBUG] Updating PV in {pkgrev_file} to {tag_to_use} (line {idx})") + # Updating PV in {pkgrev_file} to {tag_to_use} (line {idx}) new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True found_pv = True else: new_lines.append(line) if not found_pv: - print(f"[DEBUG] PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") + print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True # Print diff for debugging - if old_lines != new_lines: - print("[DEBUG] Diff for pkgrev_file:") - for i, (old, new) in enumerate(zip(old_lines, new_lines)): - if old != new: - print(f"- {old.rstrip()}\n+ {new.rstrip()}") - if len(new_lines) > len(old_lines): - for i in range(len(old_lines), len(new_lines)): - print(f"+ {new_lines[i].rstrip()}") - else: - print("[DEBUG] No content change in pkgrev_file.") + # Diff and content change info removed if old_lines != new_lines: with open(pkgrev_file, 'w', newline='\n') as f: f.writelines(new_lines) support_repo.git.add(pkgrev_file) support_changed = True - print(f"[DEBUG] Changed {pkgrev_file}") + print(f"Updated {pkgrev_file}") else: - print(f"[DEBUG] No change needed for {pkgrev_file}") + print(f"No change needed for {pkgrev_file}") elif pkgrev_file: - print(f"[DEBUG] pkgrev_file does not exist or support_repo not found: {pkgrev_file}") - print(f"[DEBUG] update_bb_and_pkgrev changed={changed}, support_changed={support_changed}") + print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") + print(f"update_bb_and_pkgrev changed={changed}, support_changed={support_changed}") return changed, support_changed, support_repo #Build the PR list description def build_pr_list_description(prs): @@ -583,10 +552,10 @@ def version_key(tag): def main(): github_token = os.getenv('GITHUB_TOKEN') - manifest_repo_path = os.getenv('META_REPO_PATH') + meta_repo_path = os.getenv('META_REPO_PATH') generic_support_path = os.getenv('GENERIC_SUPPORT_PATH') # new env var for meta-middleware-generic-support pr_number = os.getenv('PR_NUMBER') - manifest_repo_name = os.getenv('META_REPO_NAME') + meta_repo_name = os.getenv('META_REPO_NAME') repo_name = os.getenv('GITHUB_REPOSITORY') repo_owner = os.getenv('GITHUB_ORG') base_branch = os.getenv('BASE_BRANCH') @@ -595,7 +564,7 @@ def main(): if not generic_support_path: print("ERROR: GENERIC_SUPPORT_PATH environment variable is not set.") sys.exit(1) - if not manifest_repo_path: + if not meta_repo_path: print("ERROR: META_REPO_PATH environment variable is not set.") sys.exit(1) if not github_token: @@ -604,7 +573,7 @@ def main(): if not pr_number: print("ERROR: PR_NUMBER environment variable is not set.") sys.exit(1) - if not manifest_repo_name: + if not meta_repo_name: print("ERROR: META_REPO_NAME environment variable is not set.") sys.exit(1) if not repo_name: @@ -623,7 +592,7 @@ def main(): # Extract ticket number ticket_number = extract_ticket_number(meta_pr.title) - + prs, issue_repo_name, issue_number = fetch_merge_commits(repo_owner, repo_name, int(pr_number), github_token) # If PR is linked to an issue, check if all PRs in that issue are merged to the target branch if issue_number: @@ -662,38 +631,38 @@ def main(): print("Updates to be pushed to feature branch: {}".format(updates)) - # Only if the PR is linked to an issue, aggregate all PRs under a single branch for the issue meta_pr_obj = None support_pr_obj = None + comp_name = updates[0]['repo'].split('/')[-1] if updates else "unknown" if issue_number: - feature_branch = f"auto-update-{ticket_number.lower()}" - manifest_pr_title = f"[Auto] Update meta layer for {ticket_number}" - manifest_pr_description = build_pr_list_description(updates) - # Switch to feature branch BEFORE making changes - create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) - changes_made, support_changed, support_repo = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + # Branch name for issue-linked PRs + feature_branch = f"topic/auto-{ticket_number.lower()}-issue-{issue_number}" + meta_pr_title = f"[Auto] Update meta layer for {ticket_number}" + meta_pr_description = build_pr_list_description(updates) + create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) + changes_made, support_changed, support_repo = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") if changes_made: commit_and_push( - manifest_repo_path, - "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + meta_repo_path, + "Update meta and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) meta_pr_obj = create_pull_request( github_token, - manifest_repo_name, + meta_repo_name, feature_branch, base_branch, - manifest_pr_title, - manifest_pr_description + meta_pr_title, + meta_pr_description ) else: print("[DEBUG] No changes detected, PR will not be created for meta layer.") # Support layer PR + support_branch = f"topic-issue/auto-support-{ticket_number.lower()}-{issue_number}" + support_pr_title = f"[Auto] Update support layer for {ticket_number}" + support_pr_description = build_pr_list_description(updates) if support_changed: - support_branch = f"auto-update-support-{ticket_number.lower()}" - support_pr_title = f"[Auto] Update support layer for {ticket_number}" - support_pr_description = build_pr_list_description(updates) if support_repo: create_or_checkout_branch(support_repo, support_branch, base_branch) commit_and_push( @@ -717,7 +686,7 @@ def main(): pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") if support_pr_obj: pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") - issue_title = f"[Auto] Summary for {ticket_number} Updates" + issue_title = f"{ticket_number} - Auto PR for rdkcentral/{comp_name} {issue_number}" issue_body = ( f"## Automated Update Summary for {ticket_number}\n\n" f"### PRs Created:\n" + @@ -725,36 +694,36 @@ def main(): "\n\n### Details:\n" + build_pr_list_description(updates) ) - create_summary_issue(github_token, manifest_repo_name, issue_title, issue_body) + create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) else: - # If not linked to an issue, run for the individual PR only (separate branch) - feature_branch = f"auto-update-{ticket_number.lower()}-{pr_number}" - manifest_pr_title = f"[Auto] Update meta layer for {ticket_number} (PR {pr_number})" - manifest_pr_description = build_pr_list_description(updates) - create_or_checkout_branch(Repo(manifest_repo_path), feature_branch, base_branch) - changes_made, support_changed, support_repo = update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates) + # Branch name for single PRs + feature_branch = f"topic/auto-{ticket_number.lower()}-pr-{pr_number}" + meta_pr_title = f"[Auto] Update meta layer for {ticket_number} (PR {pr_number})" + meta_pr_description = build_pr_list_description(updates) + create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) + changes_made, support_changed, support_repo = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") if changes_made: commit_and_push( - manifest_repo_path, - "Update manifest and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + meta_repo_path, + "Update meta and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) ) meta_pr_obj = create_pull_request( github_token, - manifest_repo_name, + meta_repo_name, feature_branch, base_branch, - manifest_pr_title, - manifest_pr_description + meta_pr_title, + meta_pr_description ) else: print("[DEBUG] No changes detected, PR will not be created for meta layer.") # Support layer PR + support_branch = f"topic/auto-support-{ticket_number.lower()}-pr-{pr_number}" + support_pr_title = f"[Auto] Update support layer for {ticket_number} (PR {pr_number})" + support_pr_description = build_pr_list_description(updates) if support_changed: - support_branch = f"auto-update-support-{ticket_number.lower()}-{pr_number}" - support_pr_title = f"[Auto] Update support layer for {ticket_number} (PR {pr_number})" - support_pr_description = build_pr_list_description(updates) if support_repo: create_or_checkout_branch(support_repo, support_branch, base_branch) commit_and_push( @@ -778,7 +747,7 @@ def main(): pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") if support_pr_obj: pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") - issue_title = f"[Auto] Summary for {ticket_number} (PR {pr_number}) Updates" + issue_title = f"{ticket_number} - Auto PR for rdkcentral/{comp_name} {pr_number}" issue_body = ( f"## Automated Update Summary for {ticket_number} (PR {pr_number})\n\n" f"### PRs Created:\n" + @@ -786,7 +755,7 @@ def main(): "\n\n### Details:\n" + build_pr_list_description(updates) ) - create_summary_issue(github_token, manifest_repo_name, issue_title, issue_body) + create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) # ...existing code... if __name__ == '__main__': main() From a01cb32b6163d0cb861be2cf9cdd6a94857f2b45 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Fri, 11 Jul 2025 15:39:59 +0530 Subject: [PATCH 57/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 15a93d0..05fbf5a 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -241,7 +241,6 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') pkgrev_pv_field = f'PV:pn-{comp}' # pkgrev_file: {pkgrev_file}, pkgrev_pv_field: {pkgrev_pv_field} - # ...existing code... else: print(f"[DEBUG] Skipping repo {repo_name} (not handled)") continue @@ -252,11 +251,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): with open(bb_file, 'r', newline='') as f: old_lines = f.readlines() file_changed = False - if not tag: - print(f"[WARNING] No tag found that contains commit {sha} for repo {repo_name}. Setting tag as None.") - tag_to_use = None - else: - tag_to_use = tag + tag_to_use = tag new_lines = [] for idx, line in enumerate(old_lines): line_stripped = line.strip() @@ -326,11 +321,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- # Informational: update_bb_and_pkgrev status - if not tag: - print(f"No tag found that contains commit {sha} for repo {repo_name}. Setting PV to None for {pkgrev_pv_field} in {pkgrev_file}.") - tag_to_use = None - else: - tag_to_use = tag + tag_to_use = tag if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: # Opening pkgrev_file: {pkgrev_file} with open(pkgrev_file, 'r', newline='') as f: @@ -378,8 +369,6 @@ def build_pr_list_description(prs): #Commit the changes to the manifest files and push to the feature branch def commit_and_push(manifest_repo_path, commit_message): repo = Repo(manifest_repo_path) - print(f"[DEBUG] commit_and_push: current branch is {repo.active_branch.name}") - print(f"[DEBUG] commit_and_push: git status before commit:\n" + repo.git.status()) if repo.is_dirty(): # Ensure git user.name and user.email are set config_writer = repo.config_writer() @@ -389,15 +378,18 @@ def commit_and_push(manifest_repo_path, commit_message): except Exception: user_name = None user_email = None + # Set from environment only, do not hardcode defaults if not user_name: - config_writer.set_value('user', 'name', os.environ.get('GIT_COMMITTER_NAME', 'github-actions[bot]')) + committer_name = os.environ.get('GIT_COMMITTER_NAME') + if committer_name: + config_writer.set_value('user', 'name', committer_name) if not user_email: - config_writer.set_value('user', 'email', os.environ.get('GIT_COMMITTER_EMAIL', 'github-actions[bot]@users.noreply.github.com')) + committer_email = os.environ.get('GIT_COMMITTER_EMAIL') + if committer_email: + config_writer.set_value('user', 'email', committer_email) config_writer.release() repo.git.commit('-m', commit_message) - print(f"[DEBUG] commit_and_push: git log after commit:\n" + repo.git.log('-n', '2', '--oneline')) repo.git.push('origin', repo.active_branch.name) - print(f"[DEBUG] commit_and_push: git status after push:\n" + repo.git.status()) else: print("No changes to commit.") @@ -756,6 +748,5 @@ def main(): build_pr_list_description(updates) ) create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) -# ...existing code... if __name__ == '__main__': main() From 2c1d2885f0858e4f725669eaf14710b3fe8c5239 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Fri, 11 Jul 2025 15:41:10 +0530 Subject: [PATCH 58/94] Update auto_pr_creation_meta.yml --- .github/workflows/auto_pr_creation_meta.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/auto_pr_creation_meta.yml b/.github/workflows/auto_pr_creation_meta.yml index ec2b136..0a14fb7 100644 --- a/.github/workflows/auto_pr_creation_meta.yml +++ b/.github/workflows/auto_pr_creation_meta.yml @@ -63,6 +63,8 @@ jobs: GENERIC_SUPPORT_PATH: ${{ github.workspace }}/rdkcentral/meta-middleware-generic-support PR_NUMBER: ${{ github.event.pull_request.number }} BASE_BRANCH: test_develop + GIT_COMMITTER_NAME: "bot" + GIT_COMMITTER_EMAIL: ${{ vars.RDKM_BOT_EMAIL }} run: | cd meta_repo python3 ../tools/build_health_check_workflow_scripts/auto_pr_generation_meta.py From 5c3add69665523be930e31c49ffcc2f4985df56a Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Fri, 11 Jul 2025 15:49:59 +0530 Subject: [PATCH 59/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 05fbf5a..0175080 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -207,21 +207,16 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - print(f"[DBG] Component: {comp}") # Special case for entservices-apis if comp == 'entservices-apis': bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'wpe-framework', 'entservices-apis.bb') - print(f"[DBG] entservices-apis special case, bb_file: {bb_file}") else: entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') - print(f"[DBG] Searching for .bb in {entservices_dir}") if os.path.isdir(entservices_dir): for root, dirs, files in os.walk(entservices_dir): for f in files: - print(f"[DBG] Checking file: {f}") if f == f'entservices-{comp.split("entservices-")[-1]}.bb': bb_file = os.path.join(root, f) - print(f"[DBG] Found bb_file: {bb_file}") break if bb_file: break @@ -231,10 +226,8 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): if os.path.isdir(support_entservices_dir): for root, dirs, files in os.walk(support_entservices_dir): for f in files: - # Support layer: checking file: {f} if f == f'entservices-{comp.split("entservices-")[-1]}.bb': support_bb_file = os.path.join(root, f) - # Found support_bb_file: {support_bb_file} break if support_bb_file: break From 6bc8e12ea91eeb39b94e9f8267c7ae5ebd1a6a3c Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Fri, 11 Jul 2025 15:58:36 +0530 Subject: [PATCH 60/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 0175080..8d8c489 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -347,7 +347,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"No change needed for {pkgrev_file}") elif pkgrev_file: print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") - print(f"update_bb_and_pkgrev changed={changed}, support_changed={support_changed}") + print(f"update_bb_and_pkgrev completed") return changed, support_changed, support_repo #Build the PR list description def build_pr_list_description(prs): @@ -474,7 +474,6 @@ def create_or_checkout_branch(repo, branch_name, base_branch): # Create and check out the new branch locally repo.git.checkout('-b', branch_name) - print(f"Created and checked out new branch: {branch_name}") # Push the newly created branch to the remote repo.git.push('origin', branch_name) @@ -614,7 +613,7 @@ def main(): tag = None updates.append({'repo': pr['repo'], 'sha': pr['sha'], 'tag': tag}) - print("Updates to be pushed to feature branch: {}".format(updates)) + print("Updates to be pushed to topic branch: {}".format(updates)) meta_pr_obj = None support_pr_obj = None @@ -644,7 +643,7 @@ def main(): print("[DEBUG] No changes detected, PR will not be created for meta layer.") # Support layer PR - support_branch = f"topic-issue/auto-support-{ticket_number.lower()}-{issue_number}" + support_branch = f"topic/auto-support-{ticket_number.lower()}-issue-{issue_number}" support_pr_title = f"[Auto] Update support layer for {ticket_number}" support_pr_description = build_pr_list_description(updates) if support_changed: From 83e0d9e8c2666cf850bcd02bd508de05a60ba2e5 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Fri, 11 Jul 2025 16:01:53 +0530 Subject: [PATCH 61/94] Update auto_pr_generation_meta.py --- build_health_check_workflow_scripts/auto_pr_generation_meta.py | 1 - 1 file changed, 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 8d8c489..30876fb 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -625,7 +625,6 @@ def main(): meta_pr_description = build_pr_list_description(updates) create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) changes_made, support_changed, support_repo = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) - print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") if changes_made: commit_and_push( meta_repo_path, From 677adf42fc65a50315da100760e11ac59cae3740 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Fri, 11 Jul 2025 18:28:03 +0530 Subject: [PATCH 62/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 30876fb..68c04e2 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -207,33 +207,16 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - # Special case for entservices-apis + # Determine .bb file location for entservices-apis and other entservices-* components if comp == 'entservices-apis': bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'wpe-framework', 'entservices-apis.bb') else: - entservices_dir = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices') - if os.path.isdir(entservices_dir): - for root, dirs, files in os.walk(entservices_dir): - for f in files: - if f == f'entservices-{comp.split("entservices-")[-1]}.bb': - bb_file = os.path.join(root, f) - break - if bb_file: - break - # For support layer PR + bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices', f'{comp}.bb') + # For support layer PR (if support .bb files exist, keep logic, else skip) support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') - # Searching for support .bb in support_entservices_dir - if os.path.isdir(support_entservices_dir): - for root, dirs, files in os.walk(support_entservices_dir): - for f in files: - if f == f'entservices-{comp.split("entservices-")[-1]}.bb': - support_bb_file = os.path.join(root, f) - break - if support_bb_file: - break + support_bb_file = os.path.join(support_entservices_dir, f'{comp}.bb') pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') pkgrev_pv_field = f'PV:pn-{comp}' - # pkgrev_file: {pkgrev_file}, pkgrev_pv_field: {pkgrev_pv_field} else: print(f"[DEBUG] Skipping repo {repo_name} (not handled)") continue From 70967fa19a54e26ca72c3ec9ae8adb551a8697a3 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Fri, 11 Jul 2025 19:30:17 +0530 Subject: [PATCH 63/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 68c04e2..8bf62b2 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -267,33 +267,35 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: print(f"[DEBUG] .bb file does not exist: {bb_file}") - # Update .bb file SRCREV in support layer (if present) - if support_repo and support_bb_file and os.path.exists(support_bb_file): - # Opening support_bb_file: {support_bb_file} - with open(support_bb_file, 'r', newline='') as f: + # Only update PV in support layer for entservices-apis + if comp == 'entservices-apis' and pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + tag_to_use = tag + with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() file_changed = False + found_pv = False new_lines = [] for idx, line in enumerate(old_lines): - # support_bb_file line {idx}: {line.strip()} - if line.strip().startswith('SRCREV ='): - # Updating SRCREV in {support_bb_file} to {sha} - new_lines.append(f'SRCREV = "{sha}"\n') + if line.strip().startswith(f'{pkgrev_pv_field} ='): + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True + found_pv = True else: new_lines.append(line) - # Print diff for debugging - # Diff and content change info removed + if not found_pv: + print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True if old_lines != new_lines: - with open(support_bb_file, 'w', newline='\n') as f: + with open(pkgrev_file, 'w', newline='\n') as f: f.writelines(new_lines) - support_repo.git.add(support_bb_file) + support_repo.git.add(pkgrev_file) support_changed = True - print(f"Updated {support_bb_file}") + print(f"Updated {pkgrev_file}") else: - print(f"No change needed for {support_bb_file}") - elif support_bb_file: - print(f"[DEBUG] Support .bb file does not exist: {support_bb_file}") + print(f"No change needed for {pkgrev_file}") + elif comp == 'entservices-apis' and pkgrev_file: + print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- # Informational: update_bb_and_pkgrev status From 809d1f977ae5795f16eb1da66f978611948fdaea Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 13:04:10 +0530 Subject: [PATCH 64/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 8bf62b2..cb8eb1c 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -207,16 +207,35 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - # Determine .bb file location for entservices-apis and other entservices-* components - if comp == 'entservices-apis': - bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'wpe-framework', 'entservices-apis.bb') - else: - bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices', f'{comp}.bb') - # For support layer PR (if support .bb files exist, keep logic, else skip) - support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') - support_bb_file = os.path.join(support_entservices_dir, f'{comp}.bb') - pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') - pkgrev_pv_field = f'PV:pn-{comp}' + # Update PV in support layer for all entservices-* components + if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + tag_to_use = tag + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() + file_changed = False + found_pv = False + new_lines = [] + for idx, line in enumerate(old_lines): + if line.strip().startswith(f'{pkgrev_pv_field} ='): + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + found_pv = True + else: + new_lines.append(line) + if not found_pv: + print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + if old_lines != new_lines: + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + support_changed = True + print(f"Updated {pkgrev_file}") + else: + print(f"No change needed for {pkgrev_file}") + elif pkgrev_file: + print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") else: print(f"[DEBUG] Skipping repo {repo_name} (not handled)") continue @@ -395,6 +414,12 @@ def create_pull_request(github_token, repo_name, head_branch, base_branch, title def create_summary_issue(github_token, repo_name, issue_title, issue_body): g = Github(github_token) repo = g.get_repo(repo_name) + # Check for existing open issue with the same title + for issue in repo.get_issues(state='open'): + if issue.title == issue_title: + print(f"Summary issue already exists: {issue.html_url}") + return issue + # If not found, create new issue = repo.create_issue(title=issue_title, body=issue_body) print(f"Issue created: {issue.html_url}") return issue From d024edf45f216b0afb3e7dc5aa0373ac089fb678 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 13:15:58 +0530 Subject: [PATCH 65/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 93 +++++-------------- 1 file changed, 21 insertions(+), 72 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index cb8eb1c..e55bdaa 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -200,45 +200,30 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): sha = update['sha'] tag = update.get('tag') print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") - # Determine .bb paths (meta and support layer) bb_file = None - support_bb_file = None pkgrev_file = None pkgrev_pv_field = None + comp = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - # Update PV in support layer for all entservices-* components - if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - tag_to_use = tag - with open(pkgrev_file, 'r', newline='') as f: - old_lines = f.readlines() - file_changed = False - found_pv = False - new_lines = [] - for idx, line in enumerate(old_lines): - if line.strip().startswith(f'{pkgrev_pv_field} ='): - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - found_pv = True - else: - new_lines.append(line) - if not found_pv: - print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - if old_lines != new_lines: - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_changed = True - print(f"Updated {pkgrev_file}") - else: - print(f"No change needed for {pkgrev_file}") - elif pkgrev_file: - print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") - else: - print(f"[DEBUG] Skipping repo {repo_name} (not handled)") - continue + # Find .bb file + for root, dirs, files in os.walk(manifest_repo_path): + for f in files: + if f == f"{comp}.bb": + bb_file = os.path.join(root, f) + break + if bb_file: + break + # Find pkgrev.inc file and set PV field as PV:PN- + pkgrev_file_name = f"{comp}-pkgrev.inc" + for root, dirs, files in os.walk(generic_support_path): + for f in files: + if f == pkgrev_file_name: + pkgrev_file = os.path.join(root, f) + pkgrev_pv_field = f'PV:PN-{comp.upper()}' + break + if pkgrev_file: + break # Informational: bb_file and pkgrev_file # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): @@ -286,50 +271,16 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: print(f"[DEBUG] .bb file does not exist: {bb_file}") - # Only update PV in support layer for entservices-apis - if comp == 'entservices-apis' and pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - tag_to_use = tag - with open(pkgrev_file, 'r', newline='') as f: - old_lines = f.readlines() - file_changed = False - found_pv = False - new_lines = [] - for idx, line in enumerate(old_lines): - if line.strip().startswith(f'{pkgrev_pv_field} ='): - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - found_pv = True - else: - new_lines.append(line) - if not found_pv: - print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - if old_lines != new_lines: - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_changed = True - print(f"Updated {pkgrev_file}") - else: - print(f"No change needed for {pkgrev_file}") - elif comp == 'entservices-apis' and pkgrev_file: - print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") - - # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- - # Informational: update_bb_and_pkgrev status - tag_to_use = tag + # Update PV:PN- in pkgrev.inc for all components if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - # Opening pkgrev_file: {pkgrev_file} + tag_to_use = tag with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() file_changed = False found_pv = False new_lines = [] for idx, line in enumerate(old_lines): - # pkgrev_file line {idx}: {line.strip()} if line.strip().startswith(f'{pkgrev_pv_field} ='): - # Updating PV in {pkgrev_file} to {tag_to_use} (line {idx}) new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True found_pv = True @@ -339,8 +290,6 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True - # Print diff for debugging - # Diff and content change info removed if old_lines != new_lines: with open(pkgrev_file, 'w', newline='\n') as f: f.writelines(new_lines) From 9b2234f3d431df32fb21fc5621f1a20ef5e9d0de Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 13:54:48 +0530 Subject: [PATCH 66/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index e55bdaa..e3eae13 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -195,15 +195,25 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] Could not open support repo at {support_repo_path}: {e}") changed = False support_changed = False + pkgrev_file = None + # Find generic-pkgrev.inc once + for root, dirs, files in os.walk(generic_support_path): + for f in files: + if f == "generic-pkgrev.inc": + pkgrev_file = os.path.join(root, f) + break + if pkgrev_file: + break + if not pkgrev_file: + print(f"[WARNING] generic-pkgrev.inc file not found in {generic_support_path}") for update in updates: repo_name = update['repo'] sha = update['sha'] tag = update.get('tag') print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") bb_file = None - pkgrev_file = None - pkgrev_pv_field = None comp = None + pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] # Find .bb file @@ -214,16 +224,8 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): break if bb_file: break - # Find pkgrev.inc file and set PV field as PV:PN- - pkgrev_file_name = f"{comp}-pkgrev.inc" - for root, dirs, files in os.walk(generic_support_path): - for f in files: - if f == pkgrev_file_name: - pkgrev_file = os.path.join(root, f) - pkgrev_pv_field = f'PV:PN-{comp.upper()}' - break - if pkgrev_file: - break + # Set PV field for generic-pkgrev.inc + pkgrev_pv_field = f'PV:pn-{comp}' # Informational: bb_file and pkgrev_file # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): @@ -271,8 +273,9 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: print(f"[DEBUG] .bb file does not exist: {bb_file}") - # Update PV:PN- in pkgrev.inc for all components - if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + # Update PV:pn- in generic-pkgrev.inc for all components + if pkgrev_file and os.path.exists(pkgrev_file) and support_repo and pkgrev_pv_field: + print(f"[DEBUG] Attempting to update PV field {pkgrev_pv_field} in {pkgrev_file}") tag_to_use = tag with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() @@ -299,7 +302,9 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: print(f"No change needed for {pkgrev_file}") elif pkgrev_file: - print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") + print(f"[WARNING] pkgrev_file exists but support_repo not found: {pkgrev_file}") + else: + print(f"[WARNING] generic-pkgrev.inc file not found, skipping support layer update.") print(f"update_bb_and_pkgrev completed") return changed, support_changed, support_repo #Build the PR list description From 6184e0f3ab476d62f02ac8f4c2c3fdf91b496308 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 14:45:54 +0530 Subject: [PATCH 67/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index e3eae13..f77e15b 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -244,19 +244,26 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): line_stripped.startswith('SRCREV ?=') or (line_stripped.startswith(f'SRCREV_{comp} =') if comp else False) ): - # Updating SRCREV in {bb_file} to {sha} - # Preserve the assignment type (e.g., =, ?=) - if 'SRCREV ?=' in line_stripped: - new_lines.append(f'SRCREV ?= "{sha}"\n') - elif f'SRCREV_{comp} =' in line_stripped: - new_lines.append(f'SRCREV_{comp} = "{sha}"\n') + # Only update if value is different + current_value = re.findall(r'"([^"]+)"', line_stripped) + if current_value and current_value[0] == sha: + new_lines.append(line) else: - new_lines.append(f'SRCREV = "{sha}"\n') - file_changed = True + if 'SRCREV ?=' in line_stripped: + new_lines.append(f'SRCREV ?= "{sha}"\n') + elif f'SRCREV_{comp} =' in line_stripped: + new_lines.append(f'SRCREV_{comp} = "{sha}"\n') + else: + new_lines.append(f'SRCREV = "{sha}"\n') + file_changed = True elif line_stripped.startswith('PV ?='): - # Updating PV in {bb_file} to {tag_to_use} - new_lines.append(f'PV ?= "{tag_to_use}"\n') - file_changed = True + # Only update if value is different + current_value = re.findall(r'"([^"]+)"', line_stripped) + if current_value and current_value[0] == str(tag_to_use): + new_lines.append(line) + else: + new_lines.append(f'PV ?= "{tag_to_use}"\n') + file_changed = True else: new_lines.append(line) # Print diff for debugging From c0d5bf37900c8b1f25c447b27aee67be67d2960e Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 15:07:06 +0530 Subject: [PATCH 68/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index f77e15b..5b441cf 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -291,8 +291,15 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): new_lines = [] for idx, line in enumerate(old_lines): if line.strip().startswith(f'{pkgrev_pv_field} ='): - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True + # Only update if value is different + current_value = re.findall(r'"([^"]+)"', line.strip()) + if current_value and current_value[0] == str(tag_to_use): + new_lines.append(line) + print(f"[DEBUG] PV field {pkgrev_pv_field} already set to {tag_to_use}, no update needed.") + else: + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + print(f"[DEBUG] PV field {pkgrev_pv_field} updated from {current_value[0] if current_value else 'None'} to {tag_to_use}.") found_pv = True else: new_lines.append(line) From a0ef198424b907335f11e98e6cec2941fb45cdd5 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 15:24:59 +0530 Subject: [PATCH 69/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 5b441cf..a9c7417 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -283,7 +283,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): # Update PV:pn- in generic-pkgrev.inc for all components if pkgrev_file and os.path.exists(pkgrev_file) and support_repo and pkgrev_pv_field: print(f"[DEBUG] Attempting to update PV field {pkgrev_pv_field} in {pkgrev_file}") - tag_to_use = tag + tag_to_use = tag # tag may be None with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() file_changed = False @@ -291,8 +291,10 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): new_lines = [] for idx, line in enumerate(old_lines): if line.strip().startswith(f'{pkgrev_pv_field} ='): - # Only update if value is different current_value = re.findall(r'"([^"]+)"', line.strip()) + print(f"[DEBUG] Current PV value for {pkgrev_pv_field}: {current_value}") + print(f"[DEBUG] New PV value for {pkgrev_pv_field}: {tag_to_use}") + # If tag_to_use is None, it will update the field to PV:pn- = "None" if current_value and current_value[0] == str(tag_to_use): new_lines.append(line) print(f"[DEBUG] PV field {pkgrev_pv_field} already set to {tag_to_use}, no update needed.") @@ -307,6 +309,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True + # --- ADD THIS LOGIC TO FORCE GIT TO COMMIT EVEN IF FILE IS ALREADY STAGED --- if old_lines != new_lines: with open(pkgrev_file, 'w', newline='\n') as f: f.writelines(new_lines) @@ -314,7 +317,14 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): support_changed = True print(f"Updated {pkgrev_file}") else: - print(f"No change needed for {pkgrev_file}") + # If file_changed is True, but old_lines == new_lines, it means the file was already updated but not committed + # Force commit if file_changed is True + if file_changed and support_repo.is_dirty(): + support_repo.git.add(pkgrev_file) + support_changed = True + print(f"[DEBUG] File {pkgrev_file} was already updated, forcing commit.") + else: + print(f"No change needed for {pkgrev_file}") elif pkgrev_file: print(f"[WARNING] pkgrev_file exists but support_repo not found: {pkgrev_file}") else: From 26a527623159d8333b4fce14010a23c8535684a4 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 15:46:51 +0530 Subject: [PATCH 70/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 93 +++++++++---------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index a9c7417..51c7154 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -196,7 +196,6 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): changed = False support_changed = False pkgrev_file = None - # Find generic-pkgrev.inc once for root, dirs, files in os.walk(generic_support_path): for f in files: if f == "generic-pkgrev.inc": @@ -206,6 +205,8 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): break if not pkgrev_file: print(f"[WARNING] generic-pkgrev.inc file not found in {generic_support_path}") + # --- FIX: accumulate all PV changes and write once at the end --- + pv_updates = {} for update in updates: repo_name = update['repo'] sha = update['sha'] @@ -216,7 +217,6 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - # Find .bb file for root, dirs, files in os.walk(manifest_repo_path): for f in files: if f == f"{comp}.bb": @@ -224,9 +224,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): break if bb_file: break - # Set PV field for generic-pkgrev.inc pkgrev_pv_field = f'PV:pn-{comp}' - # Informational: bb_file and pkgrev_file # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): # Opening bb_file: {bb_file} @@ -280,55 +278,52 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: print(f"[DEBUG] .bb file does not exist: {bb_file}") - # Update PV:pn- in generic-pkgrev.inc for all components - if pkgrev_file and os.path.exists(pkgrev_file) and support_repo and pkgrev_pv_field: - print(f"[DEBUG] Attempting to update PV field {pkgrev_pv_field} in {pkgrev_file}") - tag_to_use = tag # tag may be None - with open(pkgrev_file, 'r', newline='') as f: - old_lines = f.readlines() - file_changed = False - found_pv = False - new_lines = [] - for idx, line in enumerate(old_lines): - if line.strip().startswith(f'{pkgrev_pv_field} ='): + # Instead of updating pkgrev_file immediately, accumulate intended PV changes + if pkgrev_pv_field: + pv_updates[pkgrev_pv_field] = tag # tag may be None + + # Now, update pkgrev_file once with all PV changes + if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + print(f"[DEBUG] Updating all PV fields in {pkgrev_file}: {pv_updates}") + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() + new_lines = [] + updated_fields = set() + for line in old_lines: + updated = False + for pv_field, pv_value in pv_updates.items(): + if line.strip().startswith(f'{pv_field} ='): current_value = re.findall(r'"([^"]+)"', line.strip()) - print(f"[DEBUG] Current PV value for {pkgrev_pv_field}: {current_value}") - print(f"[DEBUG] New PV value for {pkgrev_pv_field}: {tag_to_use}") - # If tag_to_use is None, it will update the field to PV:pn- = "None" - if current_value and current_value[0] == str(tag_to_use): + print(f"[DEBUG] Current PV value for {pv_field}: {current_value}") + print(f"[DEBUG] New PV value for {pv_field}: {pv_value}") + if current_value and current_value[0] == str(pv_value): new_lines.append(line) - print(f"[DEBUG] PV field {pkgrev_pv_field} already set to {tag_to_use}, no update needed.") + print(f"[DEBUG] PV field {pv_field} already set to {pv_value}, no update needed.") else: - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - print(f"[DEBUG] PV field {pkgrev_pv_field} updated from {current_value[0] if current_value else 'None'} to {tag_to_use}.") - found_pv = True - else: - new_lines.append(line) - if not found_pv: - print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - # --- ADD THIS LOGIC TO FORCE GIT TO COMMIT EVEN IF FILE IS ALREADY STAGED --- - if old_lines != new_lines: - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_changed = True - print(f"Updated {pkgrev_file}") - else: - # If file_changed is True, but old_lines == new_lines, it means the file was already updated but not committed - # Force commit if file_changed is True - if file_changed and support_repo.is_dirty(): - support_repo.git.add(pkgrev_file) - support_changed = True - print(f"[DEBUG] File {pkgrev_file} was already updated, forcing commit.") - else: - print(f"No change needed for {pkgrev_file}") - elif pkgrev_file: - print(f"[WARNING] pkgrev_file exists but support_repo not found: {pkgrev_file}") + new_lines.append(f'{pv_field} = "{pv_value}"\n') + print(f"[DEBUG] PV field {pv_field} updated from {current_value[0] if current_value else 'None'} to {pv_value}.") + updated_fields.add(pv_field) + updated = True + break + if not updated: + new_lines.append(line) + # Add any new PV fields not present in the file + for pv_field, pv_value in pv_updates.items(): + if pv_field not in updated_fields: + print(f"PV field {pv_field} not found in {pkgrev_file}, appending new line.") + new_lines.append(f'{pv_field} = "{pv_value}"\n') + if old_lines != new_lines: + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + support_changed = True + print(f"Updated {pkgrev_file}") else: - print(f"[WARNING] generic-pkgrev.inc file not found, skipping support layer update.") + print(f"No change needed for {pkgrev_file}") + elif pkgrev_file: + print(f"[WARNING] pkgrev_file exists but support_repo not found: {pkgrev_file}") + else: + print(f"[WARNING] generic-pkgrev.inc file not found, skipping support layer update.") print(f"update_bb_and_pkgrev completed") return changed, support_changed, support_repo #Build the PR list description From db988f3d33516cfad13ed99cf71f753abe1c2b91 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 15:58:21 +0530 Subject: [PATCH 71/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 51c7154..0d3cb04 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -294,14 +294,14 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): for pv_field, pv_value in pv_updates.items(): if line.strip().startswith(f'{pv_field} ='): current_value = re.findall(r'"([^"]+)"', line.strip()) - print(f"[DEBUG] Current PV value for {pv_field}: {current_value}") - print(f"[DEBUG] New PV value for {pv_field}: {pv_value}") + print(f"[SUPPORT-DBG] PKGREV: Found field {pv_field} in file.") + print(f"[SUPPORT-DBG] PKGREV: Current value: {current_value}, New value: {pv_value}") if current_value and current_value[0] == str(pv_value): new_lines.append(line) - print(f"[DEBUG] PV field {pv_field} already set to {pv_value}, no update needed.") + print(f"[SUPPORT-DBG] PKGREV: No update needed for {pv_field}.") else: + print(f"[SUPPORT-DBG] PKGREV: Updating {pv_field} from {current_value[0] if current_value else 'None'} to {pv_value}.") new_lines.append(f'{pv_field} = "{pv_value}"\n') - print(f"[DEBUG] PV field {pv_field} updated from {current_value[0] if current_value else 'None'} to {pv_value}.") updated_fields.add(pv_field) updated = True break @@ -310,20 +310,21 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): # Add any new PV fields not present in the file for pv_field, pv_value in pv_updates.items(): if pv_field not in updated_fields: - print(f"PV field {pv_field} not found in {pkgrev_file}, appending new line.") + print(f"[SUPPORT-DBG] PKGREV: Adding new field {pv_field} with value {pv_value}.") new_lines.append(f'{pv_field} = "{pv_value}"\n') if old_lines != new_lines: + print(f"[SUPPORT-DBG] PKGREV: Writing updated PKGREV file {pkgrev_file}.") with open(pkgrev_file, 'w', newline='\n') as f: f.writelines(new_lines) support_repo.git.add(pkgrev_file) support_changed = True - print(f"Updated {pkgrev_file}") + print(f"[SUPPORT-DBG] PKGREV: Staged {pkgrev_file} for commit.") else: - print(f"No change needed for {pkgrev_file}") + print(f"[SUPPORT-DBG] PKGREV: No changes detected in {pkgrev_file}.") elif pkgrev_file: - print(f"[WARNING] pkgrev_file exists but support_repo not found: {pkgrev_file}") + print(f"[SUPPORT-DBG] PKGREV: pkgrev_file exists but support_repo not found: {pkgrev_file}") else: - print(f"[WARNING] generic-pkgrev.inc file not found, skipping support layer update.") + print(f"[SUPPORT-DBG] PKGREV: generic-pkgrev.inc file not found, skipping support layer update.") print(f"update_bb_and_pkgrev completed") return changed, support_changed, support_repo #Build the PR list description @@ -339,6 +340,7 @@ def build_pr_list_description(prs): #Commit the changes to the manifest files and push to the feature branch def commit_and_push(manifest_repo_path, commit_message): repo = Repo(manifest_repo_path) + print(f"[DBG] Current branch before commit: {repo.active_branch.name}") if repo.is_dirty(): # Ensure git user.name and user.email are set config_writer = repo.config_writer() @@ -359,10 +361,13 @@ def commit_and_push(manifest_repo_path, commit_message): config_writer.set_value('user', 'email', committer_email) config_writer.release() repo.git.commit('-m', commit_message) + print(f"[DBG] Branch after commit: {repo.active_branch.name}") repo.git.push('origin', repo.active_branch.name) + print(f"[DBG] Branch after push: {repo.active_branch.name}") else: + print(f"[DBG] Current branch before commit: {repo.active_branch.name}") print("No changes to commit.") - + print(f"[DBG] Branch after commit: {repo.active_branch.name}") #Create a new PR for the updated manifest files def create_pull_request(github_token, repo_name, head_branch, base_branch, title, description): From 94d73f6fc8bc072cf0d11db8ada1a45c2ee54d10 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 17:11:02 +0530 Subject: [PATCH 72/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 119 +++++------------- 1 file changed, 34 insertions(+), 85 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 0d3cb04..ca10da2 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -195,6 +195,7 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] Could not open support repo at {support_repo_path}: {e}") changed = False support_changed = False + # --- FIX: ensure pv_updates accumulates all components, even if script is run multiple times --- pkgrev_file = None for root, dirs, files in os.walk(generic_support_path): for f in files: @@ -205,112 +206,60 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): break if not pkgrev_file: print(f"[WARNING] generic-pkgrev.inc file not found in {generic_support_path}") - # --- FIX: accumulate all PV changes and write once at the end --- + + # --- NEW: Load all existing PV fields from pkgrev_file before updating --- + existing_pv_fields = {} + if pkgrev_file and os.path.exists(pkgrev_file): + with open(pkgrev_file, 'r', newline='') as f: + for line in f: + m = re.match(r'^(PV:pn-[\w-]+)\s*=\s*"([^"]*)"', line.strip()) + if m: + existing_pv_fields[m.group(1)] = m.group(2) + pv_updates = {} for update in updates: repo_name = update['repo'] sha = update['sha'] tag = update.get('tag') - print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") bb_file = None comp = None pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - for root, dirs, files in os.walk(manifest_repo_path): - for f in files: - if f == f"{comp}.bb": - bb_file = os.path.join(root, f) - break - if bb_file: - break pkgrev_pv_field = f'PV:pn-{comp}' - # Update .bb file SRCREV and PV in meta layer - if bb_file and os.path.exists(bb_file): - # Opening bb_file: {bb_file} - with open(bb_file, 'r', newline='') as f: - old_lines = f.readlines() - file_changed = False - tag_to_use = tag - new_lines = [] - for idx, line in enumerate(old_lines): - line_stripped = line.strip() - # bb_file line {idx}: {line_stripped} - # Match SRCREV, SRCREV ?=, or SRCREV_ = (component always lower case) - if ( - line_stripped.startswith('SRCREV =') or - line_stripped.startswith('SRCREV ?=') or - (line_stripped.startswith(f'SRCREV_{comp} =') if comp else False) - ): - # Only update if value is different - current_value = re.findall(r'"([^"]+)"', line_stripped) - if current_value and current_value[0] == sha: - new_lines.append(line) - else: - if 'SRCREV ?=' in line_stripped: - new_lines.append(f'SRCREV ?= "{sha}"\n') - elif f'SRCREV_{comp} =' in line_stripped: - new_lines.append(f'SRCREV_{comp} = "{sha}"\n') - else: - new_lines.append(f'SRCREV = "{sha}"\n') - file_changed = True - elif line_stripped.startswith('PV ?='): - # Only update if value is different - current_value = re.findall(r'"([^"]+)"', line_stripped) - if current_value and current_value[0] == str(tag_to_use): - new_lines.append(line) - else: - new_lines.append(f'PV ?= "{tag_to_use}"\n') - file_changed = True - else: - new_lines.append(line) - # Print diff for debugging - # Diff and content change info removed - # Write only if changed - if old_lines != new_lines: - with open(bb_file, 'w', newline='\n') as f: - f.writelines(new_lines) - repo.git.add(bb_file) - changed = True - print(f"Updated {bb_file}") - else: - print(f"No change needed for {bb_file}") - else: - print(f"[DEBUG] .bb file does not exist: {bb_file}") - - # Instead of updating pkgrev_file immediately, accumulate intended PV changes + # Always update PV field for all components in updates if pkgrev_pv_field: pv_updates[pkgrev_pv_field] = tag # tag may be None + # --- Merge previous PV fields with new updates --- + # If a PV field is not in updates, preserve its previous value + merged_pv_fields = existing_pv_fields.copy() + merged_pv_fields.update(pv_updates) - # Now, update pkgrev_file once with all PV changes + # Now, update pkgrev_file once with all merged PV changes if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - print(f"[DEBUG] Updating all PV fields in {pkgrev_file}: {pv_updates}") + print(f"[DEBUG] Writing all PV fields in {pkgrev_file}: {merged_pv_fields}") + # Rebuild file with all PV fields (preserving order for existing fields, appending new ones) with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() new_lines = [] - updated_fields = set() + seen_fields = set() for line in old_lines: - updated = False - for pv_field, pv_value in pv_updates.items(): - if line.strip().startswith(f'{pv_field} ='): - current_value = re.findall(r'"([^"]+)"', line.strip()) - print(f"[SUPPORT-DBG] PKGREV: Found field {pv_field} in file.") - print(f"[SUPPORT-DBG] PKGREV: Current value: {current_value}, New value: {pv_value}") - if current_value and current_value[0] == str(pv_value): - new_lines.append(line) - print(f"[SUPPORT-DBG] PKGREV: No update needed for {pv_field}.") - else: - print(f"[SUPPORT-DBG] PKGREV: Updating {pv_field} from {current_value[0] if current_value else 'None'} to {pv_value}.") - new_lines.append(f'{pv_field} = "{pv_value}"\n') - updated_fields.add(pv_field) - updated = True - break - if not updated: + m = re.match(r'^(PV:pn-[\w-]+)\s*=\s*"([^"]*)"', line.strip()) + if m: + pv_field = m.group(1) + if pv_field in merged_pv_fields: + new_value = merged_pv_fields[pv_field] + print(f"[SUPPORT-DBG] PKGREV: Updating {pv_field} from {m.group(2)} to {new_value}") + new_lines.append(f'{pv_field} = "{new_value}"\n') + seen_fields.add(pv_field) + else: + new_lines.append(line) + else: new_lines.append(line) # Add any new PV fields not present in the file - for pv_field, pv_value in pv_updates.items(): - if pv_field not in updated_fields: - print(f"[SUPPORT-DBG] PKGREV: Adding new field {pv_field} with value {pv_value}.") + for pv_field, pv_value in merged_pv_fields.items(): + if pv_field not in seen_fields: + print(f"[SUPPORT-DBG] PKGREV: Adding new field {pv_field} with value {pv_value}") new_lines.append(f'{pv_field} = "{pv_value}"\n') if old_lines != new_lines: print(f"[SUPPORT-DBG] PKGREV: Writing updated PKGREV file {pkgrev_file}.") From ef117ac5b65fae9a805ee46a6bda981512db46d2 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 17:24:10 +0530 Subject: [PATCH 73/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 135 +++++++++++++----- 1 file changed, 100 insertions(+), 35 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index ca10da2..f89078b 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -195,7 +195,6 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] Could not open support repo at {support_repo_path}: {e}") changed = False support_changed = False - # --- FIX: ensure pv_updates accumulates all components, even if script is run multiple times --- pkgrev_file = None for root, dirs, files in os.walk(generic_support_path): for f in files: @@ -206,61 +205,118 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): break if not pkgrev_file: print(f"[WARNING] generic-pkgrev.inc file not found in {generic_support_path}") - - # --- NEW: Load all existing PV fields from pkgrev_file before updating --- - existing_pv_fields = {} - if pkgrev_file and os.path.exists(pkgrev_file): - with open(pkgrev_file, 'r', newline='') as f: - for line in f: - m = re.match(r'^(PV:pn-[\w-]+)\s*=\s*"([^"]*)"', line.strip()) - if m: - existing_pv_fields[m.group(1)] = m.group(2) - + # --- FIX: accumulate all PV changes and write once at the end --- pv_updates = {} for update in updates: repo_name = update['repo'] sha = update['sha'] tag = update.get('tag') + print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") bb_file = None comp = None pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] + for root, dirs, files in os.walk(manifest_repo_path): + for f in files: + if f == f"{comp}.bb": + bb_file = os.path.join(root, f) + break + if bb_file: + break pkgrev_pv_field = f'PV:pn-{comp}' - # Always update PV field for all components in updates + # Update .bb file SRCREV and PV in meta layer + if bb_file and os.path.exists(bb_file): + # Opening bb_file: {bb_file} + with open(bb_file, 'r', newline='') as f: + old_lines = f.readlines() + file_changed = False + tag_to_use = tag + new_lines = [] + for idx, line in enumerate(old_lines): + line_stripped = line.strip() + # bb_file line {idx}: {line_stripped} + # Match SRCREV, SRCREV ?=, or SRCREV_ = (component always lower case) + if ( + line_stripped.startswith('SRCREV =') or + line_stripped.startswith('SRCREV ?=') or + (line_stripped.startswith(f'SRCREV_{comp} =') if comp else False) + ): + # Only update if value is different + current_value = re.findall(r'"([^"]+)"', line_stripped) + if current_value and current_value[0] == sha: + new_lines.append(line) + else: + if 'SRCREV ?=' in line_stripped: + new_lines.append(f'SRCREV ?= "{sha}"\n') + elif f'SRCREV_{comp} =' in line_stripped: + new_lines.append(f'SRCREV_{comp} = "{sha}"\n') + else: + new_lines.append(f'SRCREV = "{sha}"\n') + file_changed = True + elif line_stripped.startswith('PV ?='): + # Only update if value is different + current_value = re.findall(r'"([^"]+)"', line_stripped) + if current_value and current_value[0] == str(tag_to_use): + new_lines.append(line) + else: + new_lines.append(f'PV ?= "{tag_to_use}"\n') + file_changed = True + else: + new_lines.append(line) + # Print diff for debugging + # Diff and content change info removed + # Write only if changed + if old_lines != new_lines: + with open(bb_file, 'w', newline='\n') as f: + f.writelines(new_lines) + repo.git.add(bb_file) + changed = True + print(f"Updated {bb_file}") + else: + print(f"No change needed for {bb_file}") + else: + print(f"[DEBUG] .bb file does not exist: {bb_file}") + + # Instead of updating pkgrev_file immediately, accumulate intended PV changes if pkgrev_pv_field: pv_updates[pkgrev_pv_field] = tag # tag may be None - # --- Merge previous PV fields with new updates --- - # If a PV field is not in updates, preserve its previous value - merged_pv_fields = existing_pv_fields.copy() - merged_pv_fields.update(pv_updates) - # Now, update pkgrev_file once with all merged PV changes + # Now, update pkgrev_file once with all PV changes if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - print(f"[DEBUG] Writing all PV fields in {pkgrev_file}: {merged_pv_fields}") - # Rebuild file with all PV fields (preserving order for existing fields, appending new ones) + print(f"[DEBUG] Updating all PV fields in {pkgrev_file}: {pv_updates}") with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() + print(f"[SUPPORT-DBG] PKGREV: Loaded {len(old_lines)} lines from {pkgrev_file}") + print(f"[SUPPORT-DBG] PKGREV: pv_updates to apply: {pv_updates}") new_lines = [] - seen_fields = set() - for line in old_lines: - m = re.match(r'^(PV:pn-[\w-]+)\s*=\s*"([^"]*)"', line.strip()) - if m: - pv_field = m.group(1) - if pv_field in merged_pv_fields: - new_value = merged_pv_fields[pv_field] - print(f"[SUPPORT-DBG] PKGREV: Updating {pv_field} from {m.group(2)} to {new_value}") - new_lines.append(f'{pv_field} = "{new_value}"\n') - seen_fields.add(pv_field) - else: - new_lines.append(line) - else: + updated_fields = set() + for line_num, line in enumerate(old_lines): + updated = False + for pv_field, pv_value in pv_updates.items(): + if line.strip().startswith(f'{pv_field} ='): + current_value = re.findall(r'"([^"]+)"', line.strip()) + print(f"[SUPPORT-DBG] PKGREV: Line {line_num}: Found field {pv_field} in file.") + print(f"[SUPPORT-DBG] PKGREV: Line {line_num}: Current value: {current_value}, New value: {pv_value}") + if current_value and current_value[0] == str(pv_value): + new_lines.append(line) + print(f"[SUPPORT-DBG] PKGREV: Line {line_num}: No update needed for {pv_field}.") + else: + print(f"[SUPPORT-DBG] PKGREV: Line {line_num}: Updating {pv_field} from {current_value[0] if current_value else 'None'} to {pv_value}.") + new_lines.append(f'{pv_field} = "{pv_value}"\n') + updated_fields.add(pv_field) + updated = True + break + if not updated: new_lines.append(line) # Add any new PV fields not present in the file - for pv_field, pv_value in merged_pv_fields.items(): - if pv_field not in seen_fields: - print(f"[SUPPORT-DBG] PKGREV: Adding new field {pv_field} with value {pv_value}") + for pv_field, pv_value in pv_updates.items(): + if pv_field not in updated_fields: + print(f"[SUPPORT-DBG] PKGREV: Adding new field {pv_field} with value {pv_value}.") new_lines.append(f'{pv_field} = "{pv_value}"\n') + print(f"[SUPPORT-DBG] PKGREV: old_lines == new_lines? {old_lines == new_lines}") + print(f"[SUPPORT-DBG] PKGREV: updated_fields: {updated_fields}") + print(f"[SUPPORT-DBG] PKGREV: pv_updates keys: {list(pv_updates.keys())}") if old_lines != new_lines: print(f"[SUPPORT-DBG] PKGREV: Writing updated PKGREV file {pkgrev_file}.") with open(pkgrev_file, 'w', newline='\n') as f: @@ -270,6 +326,11 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[SUPPORT-DBG] PKGREV: Staged {pkgrev_file} for commit.") else: print(f"[SUPPORT-DBG] PKGREV: No changes detected in {pkgrev_file}.") + print(f"[SUPPORT-DBG] PKGREV: Final PV values in file:") + for line in new_lines: + m = re.match(r'^(PV:pn-[\w-]+)\s*=\s*"([^"]*)"', line.strip()) + if m: + print(f"[SUPPORT-DBG] PKGREV: {m.group(1)} = {m.group(2)}") elif pkgrev_file: print(f"[SUPPORT-DBG] PKGREV: pkgrev_file exists but support_repo not found: {pkgrev_file}") else: @@ -316,6 +377,10 @@ def commit_and_push(manifest_repo_path, commit_message): else: print(f"[DBG] Current branch before commit: {repo.active_branch.name}") print("No changes to commit.") + print("[DBG] Git status output:") + print(repo.git.status()) + print("[DBG] Git diff output:") + print(repo.git.diff()) print(f"[DBG] Branch after commit: {repo.active_branch.name}") #Create a new PR for the updated manifest files From 743b3f9ab892da686dfd44372960167de1313569 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 18:49:45 +0530 Subject: [PATCH 74/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 218 +++++++++--------- 1 file changed, 108 insertions(+), 110 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index f89078b..313a13f 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -195,36 +195,32 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] Could not open support repo at {support_repo_path}: {e}") changed = False support_changed = False - pkgrev_file = None - for root, dirs, files in os.walk(generic_support_path): - for f in files: - if f == "generic-pkgrev.inc": - pkgrev_file = os.path.join(root, f) - break - if pkgrev_file: - break - if not pkgrev_file: - print(f"[WARNING] generic-pkgrev.inc file not found in {generic_support_path}") - # --- FIX: accumulate all PV changes and write once at the end --- - pv_updates = {} for update in updates: repo_name = update['repo'] sha = update['sha'] tag = update.get('tag') print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") + # Determine .bb paths (meta and support layer) bb_file = None - comp = None + support_bb_file = None + pkgrev_file = None pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - for root, dirs, files in os.walk(manifest_repo_path): - for f in files: - if f == f"{comp}.bb": - bb_file = os.path.join(root, f) - break - if bb_file: - break + # Determine .bb file location for entservices-apis and other entservices-* components + if comp == 'entservices-apis': + bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'wpe-framework', 'entservices-apis.bb') + else: + bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices', f'{comp}.bb') + # For support layer PR (if support .bb files exist, keep logic, else skip) + support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') + support_bb_file = os.path.join(support_entservices_dir, f'{comp}.bb') + pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') pkgrev_pv_field = f'PV:pn-{comp}' + else: + print(f"[DEBUG] Skipping repo {repo_name} (not handled)") + continue + # Informational: bb_file and pkgrev_file # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): # Opening bb_file: {bb_file} @@ -242,26 +238,19 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): line_stripped.startswith('SRCREV ?=') or (line_stripped.startswith(f'SRCREV_{comp} =') if comp else False) ): - # Only update if value is different - current_value = re.findall(r'"([^"]+)"', line_stripped) - if current_value and current_value[0] == sha: - new_lines.append(line) + # Updating SRCREV in {bb_file} to {sha} + # Preserve the assignment type (e.g., =, ?=) + if 'SRCREV ?=' in line_stripped: + new_lines.append(f'SRCREV ?= "{sha}"\n') + elif f'SRCREV_{comp} =' in line_stripped: + new_lines.append(f'SRCREV_{comp} = "{sha}"\n') else: - if 'SRCREV ?=' in line_stripped: - new_lines.append(f'SRCREV ?= "{sha}"\n') - elif f'SRCREV_{comp} =' in line_stripped: - new_lines.append(f'SRCREV_{comp} = "{sha}"\n') - else: - new_lines.append(f'SRCREV = "{sha}"\n') - file_changed = True + new_lines.append(f'SRCREV = "{sha}"\n') + file_changed = True elif line_stripped.startswith('PV ?='): - # Only update if value is different - current_value = re.findall(r'"([^"]+)"', line_stripped) - if current_value and current_value[0] == str(tag_to_use): - new_lines.append(line) - else: - new_lines.append(f'PV ?= "{tag_to_use}"\n') - file_changed = True + # Updating PV in {bb_file} to {tag_to_use} + new_lines.append(f'PV ?= "{tag_to_use}"\n') + file_changed = True else: new_lines.append(line) # Print diff for debugging @@ -278,64 +267,87 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: print(f"[DEBUG] .bb file does not exist: {bb_file}") - # Instead of updating pkgrev_file immediately, accumulate intended PV changes - if pkgrev_pv_field: - pv_updates[pkgrev_pv_field] = tag # tag may be None - - # Now, update pkgrev_file once with all PV changes - if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - print(f"[DEBUG] Updating all PV fields in {pkgrev_file}: {pv_updates}") - with open(pkgrev_file, 'r', newline='') as f: - old_lines = f.readlines() - print(f"[SUPPORT-DBG] PKGREV: Loaded {len(old_lines)} lines from {pkgrev_file}") - print(f"[SUPPORT-DBG] PKGREV: pv_updates to apply: {pv_updates}") - new_lines = [] - updated_fields = set() - for line_num, line in enumerate(old_lines): - updated = False - for pv_field, pv_value in pv_updates.items(): - if line.strip().startswith(f'{pv_field} ='): - current_value = re.findall(r'"([^"]+)"', line.strip()) - print(f"[SUPPORT-DBG] PKGREV: Line {line_num}: Found field {pv_field} in file.") - print(f"[SUPPORT-DBG] PKGREV: Line {line_num}: Current value: {current_value}, New value: {pv_value}") - if current_value and current_value[0] == str(pv_value): - new_lines.append(line) - print(f"[SUPPORT-DBG] PKGREV: Line {line_num}: No update needed for {pv_field}.") - else: - print(f"[SUPPORT-DBG] PKGREV: Line {line_num}: Updating {pv_field} from {current_value[0] if current_value else 'None'} to {pv_value}.") - new_lines.append(f'{pv_field} = "{pv_value}"\n') - updated_fields.add(pv_field) - updated = True - break - if not updated: - new_lines.append(line) - # Add any new PV fields not present in the file - for pv_field, pv_value in pv_updates.items(): - if pv_field not in updated_fields: - print(f"[SUPPORT-DBG] PKGREV: Adding new field {pv_field} with value {pv_value}.") - new_lines.append(f'{pv_field} = "{pv_value}"\n') - print(f"[SUPPORT-DBG] PKGREV: old_lines == new_lines? {old_lines == new_lines}") - print(f"[SUPPORT-DBG] PKGREV: updated_fields: {updated_fields}") - print(f"[SUPPORT-DBG] PKGREV: pv_updates keys: {list(pv_updates.keys())}") - if old_lines != new_lines: - print(f"[SUPPORT-DBG] PKGREV: Writing updated PKGREV file {pkgrev_file}.") - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_changed = True - print(f"[SUPPORT-DBG] PKGREV: Staged {pkgrev_file} for commit.") - else: - print(f"[SUPPORT-DBG] PKGREV: No changes detected in {pkgrev_file}.") - print(f"[SUPPORT-DBG] PKGREV: Final PV values in file:") - for line in new_lines: - m = re.match(r'^(PV:pn-[\w-]+)\s*=\s*"([^"]*)"', line.strip()) - if m: - print(f"[SUPPORT-DBG] PKGREV: {m.group(1)} = {m.group(2)}") - elif pkgrev_file: - print(f"[SUPPORT-DBG] PKGREV: pkgrev_file exists but support_repo not found: {pkgrev_file}") - else: - print(f"[SUPPORT-DBG] PKGREV: generic-pkgrev.inc file not found, skipping support layer update.") + + # Update PV in support layer for all entservices-* components + if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + tag_to_use = tag + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() + file_changed = False + found_pv = False + new_lines = [] + for idx, line in enumerate(old_lines): + if line.strip().startswith(f'{pkgrev_pv_field} ='): + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + found_pv = True + else: + new_lines.append(line) + if not found_pv: + print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + if old_lines != new_lines: + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + support_changed = True + print(f"Updated {pkgrev_file}") + else: + print(f"No change needed for {pkgrev_file}") + elif pkgrev_file: + print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") + # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- + # Informational: update_bb_and_pkgrev status + tag_to_use = tag + if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + # Opening pkgrev_file: {pkgrev_file} + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() + file_changed = False + found_pv = False + new_lines = [] + for idx, line in enumerate(old_lines): + # pkgrev_file line {idx}: {line.strip()} + if line.strip().startswith(f'{pkgrev_pv_field} ='): + # Updating PV in {pkgrev_file} to {tag_to_use} (line {idx}) + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + found_pv = True + else: + new_lines.append(line) + if not found_pv: + print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + file_changed = True + # Print diff for debugging + # Diff and content change info removed + if old_lines != new_lines: + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + support_changed = True + print(f"Updated {pkgrev_file}") + else: + print(f"No change needed for {pkgrev_file}") + elif pkgrev_file: + print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") print(f"update_bb_and_pkgrev completed") + #print the changed status and diff + if not support_changed: + print("[DEBUG] No changes made to support layer.") + else: + print(f"[DEBUG] Changes made to support layer in the branch: {support_repo.active_branch.name}") + #print the new lines in the support layer + for line in new_lines: + print(f"[DEBUG] {line.strip()}") + # --- DEBUG: Print the diff of support layer changes for debugging --- + if old_lines != new_lines: + print("[DEBUG] Support layer changes detected:") + for old_line, new_line in zip(old_lines, new_lines): + if old_line != new_line: + print(f"[DEBUG] - {old_line.strip()} -> {new_line.strip()}") + # Print the diff of support layer changes for debugging return changed, support_changed, support_repo #Build the PR list description def build_pr_list_description(prs): @@ -350,7 +362,6 @@ def build_pr_list_description(prs): #Commit the changes to the manifest files and push to the feature branch def commit_and_push(manifest_repo_path, commit_message): repo = Repo(manifest_repo_path) - print(f"[DBG] Current branch before commit: {repo.active_branch.name}") if repo.is_dirty(): # Ensure git user.name and user.email are set config_writer = repo.config_writer() @@ -371,17 +382,10 @@ def commit_and_push(manifest_repo_path, commit_message): config_writer.set_value('user', 'email', committer_email) config_writer.release() repo.git.commit('-m', commit_message) - print(f"[DBG] Branch after commit: {repo.active_branch.name}") repo.git.push('origin', repo.active_branch.name) - print(f"[DBG] Branch after push: {repo.active_branch.name}") else: - print(f"[DBG] Current branch before commit: {repo.active_branch.name}") print("No changes to commit.") - print("[DBG] Git status output:") - print(repo.git.status()) - print("[DBG] Git diff output:") - print(repo.git.diff()) - print(f"[DBG] Branch after commit: {repo.active_branch.name}") + #Create a new PR for the updated manifest files def create_pull_request(github_token, repo_name, head_branch, base_branch, title, description): @@ -406,12 +410,6 @@ def create_pull_request(github_token, repo_name, head_branch, base_branch, title def create_summary_issue(github_token, repo_name, issue_title, issue_body): g = Github(github_token) repo = g.get_repo(repo_name) - # Check for existing open issue with the same title - for issue in repo.get_issues(state='open'): - if issue.title == issue_title: - print(f"Summary issue already exists: {issue.html_url}") - return issue - # If not found, create new issue = repo.create_issue(title=issue_title, body=issue_body) print(f"Issue created: {issue.html_url}") return issue From 5081a3526ba4a8208c08f858e487fb8b6bf0b54a Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 18:59:45 +0530 Subject: [PATCH 75/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 313a13f..f06b3dd 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -624,6 +624,15 @@ def main(): meta_pr_title = f"[Auto] Update meta layer for {ticket_number}" meta_pr_description = build_pr_list_description(updates) create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) + # Checkout support topic branch BEFORE making changes + support_branch = f"topic/auto-support-{ticket_number.lower()}-issue-{issue_number}" + support_repo = None + if os.path.isdir(generic_support_path): + try: + support_repo = Repo(generic_support_path) + create_or_checkout_branch(support_repo, support_branch, base_branch) + except Exception as e: + print(f"[DEBUG] Could not open support repo at {generic_support_path}: {e}") changes_made, support_changed, support_repo = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) if changes_made: commit_and_push( @@ -684,7 +693,16 @@ def main(): meta_pr_title = f"[Auto] Update meta layer for {ticket_number} (PR {pr_number})" meta_pr_description = build_pr_list_description(updates) create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) - changes_made, support_changed, support_repo = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) + # Checkout support topic branch BEFORE making changes + support_branch = f"topic/auto-support-{ticket_number.lower()}-pr-{pr_number}" + support_repo = None + if os.path.isdir(generic_support_path): + try: + support_repo = Repo(generic_support_path) + create_or_checkout_branch(support_repo, support_branch, base_branch) + except Exception as e: + print(f"[DEBUG] Could not open support repo at {generic_support_path}: {e}") + changes_made, support_changed, _ = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") if changes_made: commit_and_push( From fe1af62547e625d989dba2168aff773c16848587 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 19:18:04 +0530 Subject: [PATCH 76/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 170 +++++++++--------- 1 file changed, 89 insertions(+), 81 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index f06b3dd..cecde2d 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -618,22 +618,49 @@ def main(): meta_pr_obj = None support_pr_obj = None comp_name = updates[0]['repo'].split('/')[-1] if updates else "unknown" + auto_pr_links = [] + # --- Refactored PV update logic for support layer --- if issue_number: - # Branch name for issue-linked PRs + # Issue-linked PR: update PV for only the merged component in the shared topic branch feature_branch = f"topic/auto-{ticket_number.lower()}-issue-{issue_number}" meta_pr_title = f"[Auto] Update meta layer for {ticket_number}" meta_pr_description = build_pr_list_description(updates) create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) - # Checkout support topic branch BEFORE making changes support_branch = f"topic/auto-support-{ticket_number.lower()}-issue-{issue_number}" support_repo = None if os.path.isdir(generic_support_path): try: support_repo = Repo(generic_support_path) create_or_checkout_branch(support_repo, support_branch, base_branch) + # Only update PV field for the current merged component in generic-pkgrev.inc + pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') + if os.path.exists(pkgrev_file): + comp = updates[0]['repo'].split('/')[-1] + pv_field = f'PV:pn-{comp}' + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() + new_lines = [] + found_pv = False + for line in old_lines: + if line.strip().startswith(f'{pv_field} ='): + new_lines.append(f'{pv_field} = "{updates[0]['tag']}"\n') + found_pv = True + else: + new_lines.append(line) + if not found_pv: + new_lines.append(f'{pv_field} = "{updates[0]['tag']}"\n') + if old_lines != new_lines: + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + support_repo.git.commit('-m', f"Update PV for {comp} for {ticket_number} issue {issue_number}") + support_repo.git.push('origin', support_branch) + print(f"[DEBUG] Updated PV field for {comp} in {pkgrev_file}") + else: + print(f"[DEBUG] No PV changes needed for {pkgrev_file}") except Exception as e: - print(f"[DEBUG] Could not open support repo at {generic_support_path}: {e}") - changes_made, support_changed, support_repo = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) + print(f"[DEBUG] Could not open or update support repo at {generic_support_path}: {e}") + changes_made, support_changed, _ = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) if changes_made: commit_and_push( meta_repo_path, @@ -649,59 +676,60 @@ def main(): ) else: print("[DEBUG] No changes detected, PR will not be created for meta layer.") - - # Support layer PR - support_branch = f"topic/auto-support-{ticket_number.lower()}-issue-{issue_number}" - support_pr_title = f"[Auto] Update support layer for {ticket_number}" - support_pr_description = build_pr_list_description(updates) + # Add support PR link if created + # Create support layer PR if support_changed if support_changed: - if support_repo: - create_or_checkout_branch(support_repo, support_branch, base_branch) - commit_and_push( - generic_support_path, - "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) - ) - support_pr_obj = create_pull_request( - github_token, - 'rdkcentral/meta-middleware-generic-support', - support_branch, - base_branch, - support_pr_title, - support_pr_description - ) - else: - print("[DEBUG] No support_repo found for PR creation.") - # Create summary issue if at least one PR was created - if meta_pr_obj or support_pr_obj: - pr_links = [] - if meta_pr_obj: - pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") - if support_pr_obj: - pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") - issue_title = f"{ticket_number} - Auto PR for rdkcentral/{comp_name} {issue_number}" - issue_body = ( - f"## Automated Update Summary for {ticket_number}\n\n" - f"### PRs Created:\n" + - "\n".join(pr_links) + - "\n\n### Details:\n" + - build_pr_list_description(updates) + support_pr_title = f"[Auto] Update support layer for {ticket_number}" + support_pr_description = build_pr_list_description(updates) + support_pr_obj = create_pull_request( + github_token, + 'rdkcentral/meta-middleware-generic-support', + support_branch, + base_branch, + support_pr_title, + support_pr_description ) - create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) + # ...existing code for summary issue... else: - # Branch name for single PRs + # Single PR: update PV for only its component in the topic branch feature_branch = f"topic/auto-{ticket_number.lower()}-pr-{pr_number}" meta_pr_title = f"[Auto] Update meta layer for {ticket_number} (PR {pr_number})" meta_pr_description = build_pr_list_description(updates) create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) - # Checkout support topic branch BEFORE making changes support_branch = f"topic/auto-support-{ticket_number.lower()}-pr-{pr_number}" support_repo = None if os.path.isdir(generic_support_path): try: support_repo = Repo(generic_support_path) create_or_checkout_branch(support_repo, support_branch, base_branch) + # Only update PV field for the single component in generic-pkgrev.inc + pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') + if os.path.exists(pkgrev_file): + comp = updates[0]['repo'].split('/')[-1] + pv_field = f'PV:pn-{comp}' + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() + new_lines = [] + found_pv = False + for line in old_lines: + if line.strip().startswith(f'{pv_field} ='): + new_lines.append(f'{pv_field} = "{updates[0]['tag']}"\n') + found_pv = True + else: + new_lines.append(line) + if not found_pv: + new_lines.append(f'{pv_field} = "{updates[0]['tag']}"\n') + if old_lines != new_lines: + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + support_repo.git.commit('-m', f"Update PV for {comp} for {ticket_number} PR {pr_number}") + support_repo.git.push('origin', support_branch) + print(f"[DEBUG] Updated PV field for {comp} in {pkgrev_file}") + else: + print(f"[DEBUG] No PV changes needed for {pkgrev_file}") except Exception as e: - print(f"[DEBUG] Could not open support repo at {generic_support_path}: {e}") + print(f"[DEBUG] Could not open or update support repo at {generic_support_path}: {e}") changes_made, support_changed, _ = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") if changes_made: @@ -717,45 +745,25 @@ def main(): meta_pr_title, meta_pr_description ) + if meta_pr_obj: + auto_pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") else: print("[DEBUG] No changes detected, PR will not be created for meta layer.") - - # Support layer PR - support_branch = f"topic/auto-support-{ticket_number.lower()}-pr-{pr_number}" - support_pr_title = f"[Auto] Update support layer for {ticket_number} (PR {pr_number})" - support_pr_description = build_pr_list_description(updates) - if support_changed: - if support_repo: - create_or_checkout_branch(support_repo, support_branch, base_branch) - commit_and_push( - generic_support_path, - "Update support layer entservices SRCREV for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) - ) - support_pr_obj = create_pull_request( - github_token, - 'rdkcentral/meta-middleware-generic-support', - support_branch, - base_branch, - support_pr_title, - support_pr_description - ) - else: - print("[DEBUG] No support_repo found for PR creation.") - # Create summary issue if at least one PR was created - if meta_pr_obj or support_pr_obj: - pr_links = [] - if meta_pr_obj: - pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") - if support_pr_obj: - pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") - issue_title = f"{ticket_number} - Auto PR for rdkcentral/{comp_name} {pr_number}" - issue_body = ( - f"## Automated Update Summary for {ticket_number} (PR {pr_number})\n\n" - f"### PRs Created:\n" + - "\n".join(pr_links) + - "\n\n### Details:\n" + - build_pr_list_description(updates) - ) - create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) + # Add support PR link if created + # --- Create summary issue only if more than one auto PR exists --- + # Create summary issue only if both meta and support layer auto PRs exist + if meta_pr_obj and support_pr_obj: + auto_pr_links = [] + auto_pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") + auto_pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") + issue_title = f"{ticket_number} - Auto PRs for rdkcentral/{comp_name}" + issue_body = ( + f"## Automated Update Summary for {ticket_number}\n\n" + f"### PRs Created:\n" + + "\n".join(auto_pr_links) + + "\n\n### Details:\n" + + build_pr_list_description(updates) + ) + create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) if __name__ == '__main__': main() From cb9efb7a4b8d9bf155a754f0bc328b4b70f1bf1d Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 19:32:15 +0530 Subject: [PATCH 77/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index cecde2d..91ce22e 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -294,7 +294,20 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): support_changed = True print(f"Updated {pkgrev_file}") else: - print(f"No change needed for {pkgrev_file}") + # Check if PV field for the component matches the desired value + pv_line = None + for line in old_lines: + if line.strip().startswith(f'{pkgrev_pv_field} ='): + pv_line = line.strip() + break + if pv_line: + current_value = pv_line.split('=')[1].strip().strip('"') + if current_value == str(tag_to_use): + print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} already matches the desired value '{tag_to_use}'.") + else: + print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} is '{current_value}', expected '{tag_to_use}'. File unchanged due to logic error.") + else: + print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} not found; file unchanged.") elif pkgrev_file: print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- From 8411b888950afde92cd9db15fe95b21e0c95fcf9 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 19:37:54 +0530 Subject: [PATCH 78/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 91ce22e..1a5df15 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -275,39 +275,29 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): old_lines = f.readlines() file_changed = False found_pv = False - new_lines = [] + previous_value = None for idx, line in enumerate(old_lines): if line.strip().startswith(f'{pkgrev_pv_field} ='): - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True + previous_value = line.strip().split('=')[1].strip().strip('"') found_pv = True - else: - new_lines.append(line) - if not found_pv: - print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - file_changed = True - if old_lines != new_lines: + # Only update if previous_value is different from tag_to_use + if previous_value != str(tag_to_use): + new_lines = [] + for idx, line in enumerate(old_lines): + if line.strip().startswith(f'{pkgrev_pv_field} ='): + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + else: + new_lines.append(line) + if not found_pv: + print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') with open(pkgrev_file, 'w', newline='\n') as f: f.writelines(new_lines) support_repo.git.add(pkgrev_file) support_changed = True - print(f"Updated {pkgrev_file}") + print(f"Updated {pkgrev_file}. Previous value: '{previous_value}', new value: '{tag_to_use}'") else: - # Check if PV field for the component matches the desired value - pv_line = None - for line in old_lines: - if line.strip().startswith(f'{pkgrev_pv_field} ='): - pv_line = line.strip() - break - if pv_line: - current_value = pv_line.split('=')[1].strip().strip('"') - if current_value == str(tag_to_use): - print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} already matches the desired value '{tag_to_use}'.") - else: - print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} is '{current_value}', expected '{tag_to_use}'. File unchanged due to logic error.") - else: - print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} not found; file unchanged.") + print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} already matches the desired value '{tag_to_use}'.") elif pkgrev_file: print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- From 6a3d5bf4c7173a3feb20e56c683c39104c531646 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 19:43:44 +0530 Subject: [PATCH 79/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 1a5df15..1c73d78 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -276,28 +276,28 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): file_changed = False found_pv = False previous_value = None - for idx, line in enumerate(old_lines): + for line in old_lines: if line.strip().startswith(f'{pkgrev_pv_field} ='): previous_value = line.strip().split('=')[1].strip().strip('"') found_pv = True - # Only update if previous_value is different from tag_to_use - if previous_value != str(tag_to_use): - new_lines = [] - for idx, line in enumerate(old_lines): - if line.strip().startswith(f'{pkgrev_pv_field} ='): - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - else: - new_lines.append(line) - if not found_pv: - print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_changed = True - print(f"Updated {pkgrev_file}. Previous value: '{previous_value}', new value: '{tag_to_use}'") + break + if found_pv: + if previous_value != str(tag_to_use): + new_lines = [] + for line in old_lines: + if line.strip().startswith(f'{pkgrev_pv_field} ='): + new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') + else: + new_lines.append(line) + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + support_changed = True + print(f"Updated {pkgrev_file}. Previous value: '{previous_value}', new value: '{tag_to_use}'") + else: + print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} already matches the desired value. Previous value: '{previous_value}', new value: '{tag_to_use}'") else: - print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} already matches the desired value '{tag_to_use}'.") + print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}. No update performed.") elif pkgrev_file: print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- From 46b5dbdf8b62997cc1f9596715791a27f8b4020f Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 19:56:01 +0530 Subject: [PATCH 80/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 1c73d78..d043baa 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -277,8 +277,12 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): found_pv = False previous_value = None for line in old_lines: - if line.strip().startswith(f'{pkgrev_pv_field} ='): - previous_value = line.strip().split('=')[1].strip().strip('"') + print(f"[DEBUG] pkgrev_file line: {line.strip()}") + # Use regex to extract PV value + pv_match = re.match(rf'^{re.escape(pkgrev_pv_field)}\s*=\s*"([^"]+)"', line.strip()) + if pv_match: + previous_value = pv_match.group(1) + print(f"[DEBUG] Found previous PV value: {previous_value}") found_pv = True break if found_pv: From af873f0cb53d0c1b5cf5c3073b94be0f4d0b3a1d Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 20:03:07 +0530 Subject: [PATCH 81/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index d043baa..56b488d 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -276,20 +276,23 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): file_changed = False found_pv = False previous_value = None + # Extract previous value from original file content for line in old_lines: print(f"[DEBUG] pkgrev_file line: {line.strip()}") - # Use regex to extract PV value pv_match = re.match(rf'^{re.escape(pkgrev_pv_field)}\s*=\s*"([^"]+)"', line.strip()) if pv_match: previous_value = pv_match.group(1) print(f"[DEBUG] Found previous PV value: {previous_value}") found_pv = True break + # Now build new_lines only after extracting previous_value if found_pv: if previous_value != str(tag_to_use): new_lines = [] for line in old_lines: - if line.strip().startswith(f'{pkgrev_pv_field} ='): + # Replace only the matching PV field line + pv_match = re.match(rf'^{re.escape(pkgrev_pv_field)}\s*=\s*"([^"]+)"', line.strip()) + if pv_match: new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') else: new_lines.append(line) @@ -705,36 +708,48 @@ def main(): create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) support_branch = f"topic/auto-support-{ticket_number.lower()}-pr-{pr_number}" support_repo = None + pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') + comp = updates[0]['repo'].split('/')[-1] + pv_field = f'PV:pn-{comp}' + old_lines = [] + previous_value = None + found_pv = False + if os.path.exists(pkgrev_file): + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() + # Extract previous PV value before branch checkout + for line in old_lines: + pv_match = re.match(rf'^{re.escape(pv_field)}\s*=\s*"([^"]+)"', line.strip()) + if pv_match: + previous_value = pv_match.group(1) + found_pv = True + break if os.path.isdir(generic_support_path): try: support_repo = Repo(generic_support_path) create_or_checkout_branch(support_repo, support_branch, base_branch) - # Only update PV field for the single component in generic-pkgrev.inc - pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') + # Now perform the update after branch checkout if os.path.exists(pkgrev_file): - comp = updates[0]['repo'].split('/')[-1] - pv_field = f'PV:pn-{comp}' - with open(pkgrev_file, 'r', newline='') as f: - old_lines = f.readlines() new_lines = [] - found_pv = False + pv_updated = False for line in old_lines: - if line.strip().startswith(f'{pv_field} ='): - new_lines.append(f'{pv_field} = "{updates[0]['tag']}"\n') - found_pv = True + pv_match = re.match(rf'^{re.escape(pv_field)}\s*=\s*"([^"]+)"', line.strip()) + if pv_match: + new_lines.append(f'{pv_field} = "{updates[0]["tag"]}"\n') + pv_updated = True else: new_lines.append(line) - if not found_pv: - new_lines.append(f'{pv_field} = "{updates[0]['tag']}"\n') + if not pv_updated: + new_lines.append(f'{pv_field} = "{updates[0]["tag"]}"\n') if old_lines != new_lines: with open(pkgrev_file, 'w', newline='\n') as f: f.writelines(new_lines) support_repo.git.add(pkgrev_file) support_repo.git.commit('-m', f"Update PV for {comp} for {ticket_number} PR {pr_number}") support_repo.git.push('origin', support_branch) - print(f"[DEBUG] Updated PV field for {comp} in {pkgrev_file}") + print(f"[DEBUG] Updated PV field for {comp} in {pkgrev_file}. Previous value: '{previous_value}', new value: '{updates[0]["tag"]}'") else: - print(f"[DEBUG] No PV changes needed for {pkgrev_file}") + print(f"[DEBUG] No PV changes needed for {pkgrev_file}. Previous value: '{previous_value}', new value: '{updates[0]["tag"]}'") except Exception as e: print(f"[DEBUG] Could not open or update support repo at {generic_support_path}: {e}") changes_made, support_changed, _ = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) From 919b96daaab47a17b972c8ecb00e7067a90a12a7 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 20:07:26 +0530 Subject: [PATCH 82/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 56b488d..a825b6c 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -714,45 +714,41 @@ def main(): old_lines = [] previous_value = None found_pv = False + new_lines = [] + pv_updated = False if os.path.exists(pkgrev_file): with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() - # Extract previous PV value before branch checkout + # Extract previous PV value before any branch checkout for line in old_lines: pv_match = re.match(rf'^{re.escape(pv_field)}\s*=\s*"([^"]+)"', line.strip()) if pv_match: previous_value = pv_match.group(1) found_pv = True - break - if os.path.isdir(generic_support_path): + # Build new_lines for update + if pv_match: + new_lines.append(f'{pv_field} = "{updates[0]["tag"]}"\n') + pv_updated = True + else: + new_lines.append(line) + if not pv_updated: + new_lines.append(f'{pv_field} = "{updates[0]["tag"]}"\n') + # Only checkout and update if changes are needed + if old_lines and old_lines != new_lines and os.path.isdir(generic_support_path): try: support_repo = Repo(generic_support_path) create_or_checkout_branch(support_repo, support_branch, base_branch) - # Now perform the update after branch checkout - if os.path.exists(pkgrev_file): - new_lines = [] - pv_updated = False - for line in old_lines: - pv_match = re.match(rf'^{re.escape(pv_field)}\s*=\s*"([^"]+)"', line.strip()) - if pv_match: - new_lines.append(f'{pv_field} = "{updates[0]["tag"]}"\n') - pv_updated = True - else: - new_lines.append(line) - if not pv_updated: - new_lines.append(f'{pv_field} = "{updates[0]["tag"]}"\n') - if old_lines != new_lines: - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_repo.git.commit('-m', f"Update PV for {comp} for {ticket_number} PR {pr_number}") - support_repo.git.push('origin', support_branch) - print(f"[DEBUG] Updated PV field for {comp} in {pkgrev_file}. Previous value: '{previous_value}', new value: '{updates[0]["tag"]}'") - else: - print(f"[DEBUG] No PV changes needed for {pkgrev_file}. Previous value: '{previous_value}', new value: '{updates[0]["tag"]}'") + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + support_repo.git.commit('-m', f"Update PV for {comp} for {ticket_number} PR {pr_number}") + support_repo.git.push('origin', support_branch) + print(f"[DEBUG] Updated PV field for {comp} in {pkgrev_file}. Previous value: '{previous_value}', new value: '{updates[0]["tag"]}'") except Exception as e: print(f"[DEBUG] Could not open or update support repo at {generic_support_path}: {e}") - changes_made, support_changed, _ = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) + elif old_lines: + print(f"[DEBUG] No PV changes needed for {pkgrev_file}. Previous value: '{previous_value}', new value: '{updates[0]["tag"]}'") + changes_made, support_changed, support_repo = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") if changes_made: commit_and_push( From f94aad8e18e78e0f75828fceffc4d2f59b024a8e Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 20:15:12 +0530 Subject: [PATCH 83/94] Update auto_pr_generation_meta.py --- build_health_check_workflow_scripts/auto_pr_generation_meta.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index a825b6c..d7f802f 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -641,7 +641,6 @@ def main(): if os.path.isdir(generic_support_path): try: support_repo = Repo(generic_support_path) - create_or_checkout_branch(support_repo, support_branch, base_branch) # Only update PV field for the current merged component in generic-pkgrev.inc pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') if os.path.exists(pkgrev_file): @@ -649,6 +648,8 @@ def main(): pv_field = f'PV:pn-{comp}' with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() + # Now checkout branch after reading old_lines + create_or_checkout_branch(support_repo, support_branch, base_branch) new_lines = [] found_pv = False for line in old_lines: From f5a13222f22c6e18c7807850e249b7272754274a Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 20:18:34 +0530 Subject: [PATCH 84/94] Update auto_pr_generation_meta.py --- build_health_check_workflow_scripts/auto_pr_generation_meta.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index d7f802f..afbae43 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -646,6 +646,8 @@ def main(): if os.path.exists(pkgrev_file): comp = updates[0]['repo'].split('/')[-1] pv_field = f'PV:pn-{comp}' + # Print current branch name before reading old_lines + print(f"[DEBUG] Current branch before reading pkgrev_file: {support_repo.active_branch.name}") with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() # Now checkout branch after reading old_lines From 4ac9a11996c5f2ac1b90d17f9011ff3079d457a1 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 21:34:04 +0530 Subject: [PATCH 85/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 350 +++++++----------- 1 file changed, 133 insertions(+), 217 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index afbae43..8bc03f6 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -195,31 +195,37 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"[DEBUG] Could not open support repo at {support_repo_path}: {e}") changed = False support_changed = False + pkgrev_file = None + # Find generic-pkgrev.inc once + for root, dirs, files in os.walk(generic_support_path): + for f in files: + if f == "generic-pkgrev.inc": + pkgrev_file = os.path.join(root, f) + break + if pkgrev_file: + break + if not pkgrev_file: + print(f"[WARNING] generic-pkgrev.inc file not found in {generic_support_path}") for update in updates: repo_name = update['repo'] sha = update['sha'] tag = update.get('tag') print(f"[DEBUG] Processing update: repo={repo_name}, sha={sha}, tag={tag}") - # Determine .bb paths (meta and support layer) bb_file = None - support_bb_file = None - pkgrev_file = None + comp = None pkgrev_pv_field = None if repo_name.startswith('rdkcentral/entservices-'): comp = repo_name.split('/')[-1] - # Determine .bb file location for entservices-apis and other entservices-* components - if comp == 'entservices-apis': - bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'wpe-framework', 'entservices-apis.bb') - else: - bb_file = os.path.join(manifest_repo_path, 'recipes-extended', 'entservices', f'{comp}.bb') - # For support layer PR (if support .bb files exist, keep logic, else skip) - support_entservices_dir = os.path.join(generic_support_path, 'recipes-extended', 'entservices') - support_bb_file = os.path.join(support_entservices_dir, f'{comp}.bb') - pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') + # Find .bb file + for root, dirs, files in os.walk(manifest_repo_path): + for f in files: + if f == f"{comp}.bb": + bb_file = os.path.join(root, f) + break + if bb_file: + break + # Set PV field for generic-pkgrev.inc pkgrev_pv_field = f'PV:pn-{comp}' - else: - print(f"[DEBUG] Skipping repo {repo_name} (not handled)") - continue # Informational: bb_file and pkgrev_file # Update .bb file SRCREV and PV in meta layer if bb_file and os.path.exists(bb_file): @@ -267,60 +273,17 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: print(f"[DEBUG] .bb file does not exist: {bb_file}") - - # Update PV in support layer for all entservices-* components - if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: + # Update PV:pn- in generic-pkgrev.inc for all components + if pkgrev_file and os.path.exists(pkgrev_file) and support_repo and pkgrev_pv_field: + print(f"[DEBUG] Attempting to update PV field {pkgrev_pv_field} in {pkgrev_file}") tag_to_use = tag with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() file_changed = False found_pv = False - previous_value = None - # Extract previous value from original file content - for line in old_lines: - print(f"[DEBUG] pkgrev_file line: {line.strip()}") - pv_match = re.match(rf'^{re.escape(pkgrev_pv_field)}\s*=\s*"([^"]+)"', line.strip()) - if pv_match: - previous_value = pv_match.group(1) - print(f"[DEBUG] Found previous PV value: {previous_value}") - found_pv = True - break - # Now build new_lines only after extracting previous_value - if found_pv: - if previous_value != str(tag_to_use): - new_lines = [] - for line in old_lines: - # Replace only the matching PV field line - pv_match = re.match(rf'^{re.escape(pkgrev_pv_field)}\s*=\s*"([^"]+)"', line.strip()) - if pv_match: - new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') - else: - new_lines.append(line) - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_changed = True - print(f"Updated {pkgrev_file}. Previous value: '{previous_value}', new value: '{tag_to_use}'") - else: - print(f"No change needed for {pkgrev_file}. Reason: PV field for {pkgrev_pv_field} already matches the desired value. Previous value: '{previous_value}', new value: '{tag_to_use}'") - else: - print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}. No update performed.") - elif pkgrev_file: - print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") - # --- DEBUG: Print comp, pkgrev_pv_field, and tag for every update attempt --- - # Informational: update_bb_and_pkgrev status - tag_to_use = tag - if pkgrev_file and os.path.exists(pkgrev_file) and support_repo: - # Opening pkgrev_file: {pkgrev_file} - with open(pkgrev_file, 'r', newline='') as f: - old_lines = f.readlines() - file_changed = False - found_pv = False new_lines = [] for idx, line in enumerate(old_lines): - # pkgrev_file line {idx}: {line.strip()} if line.strip().startswith(f'{pkgrev_pv_field} ='): - # Updating PV in {pkgrev_file} to {tag_to_use} (line {idx}) new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True found_pv = True @@ -330,8 +293,6 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): print(f"PV field {pkgrev_pv_field} not found in {pkgrev_file}, appending new line.") new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True - # Print diff for debugging - # Diff and content change info removed if old_lines != new_lines: with open(pkgrev_file, 'w', newline='\n') as f: f.writelines(new_lines) @@ -341,23 +302,10 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): else: print(f"No change needed for {pkgrev_file}") elif pkgrev_file: - print(f"pkgrev_file does not exist or support_repo not found: {pkgrev_file}") + print(f"[WARNING] pkgrev_file exists but support_repo not found: {pkgrev_file}") + else: + print(f"[WARNING] generic-pkgrev.inc file not found, skipping support layer update.") print(f"update_bb_and_pkgrev completed") - #print the changed status and diff - if not support_changed: - print("[DEBUG] No changes made to support layer.") - else: - print(f"[DEBUG] Changes made to support layer in the branch: {support_repo.active_branch.name}") - #print the new lines in the support layer - for line in new_lines: - print(f"[DEBUG] {line.strip()}") - # --- DEBUG: Print the diff of support layer changes for debugging --- - if old_lines != new_lines: - print("[DEBUG] Support layer changes detected:") - for old_line, new_line in zip(old_lines, new_lines): - if old_line != new_line: - print(f"[DEBUG] - {old_line.strip()} -> {new_line.strip()}") - # Print the diff of support layer changes for debugging return changed, support_changed, support_repo #Build the PR list description def build_pr_list_description(prs): @@ -420,6 +368,12 @@ def create_pull_request(github_token, repo_name, head_branch, base_branch, title def create_summary_issue(github_token, repo_name, issue_title, issue_body): g = Github(github_token) repo = g.get_repo(repo_name) + # Check for existing open issue with the same title + for issue in repo.get_issues(state='open'): + if issue.title == issue_title: + print(f"Summary issue already exists: {issue.html_url}") + return issue + # If not found, create new issue = repo.create_issue(title=issue_title, body=issue_body) print(f"Issue created: {issue.html_url}") return issue @@ -628,160 +582,122 @@ def main(): meta_pr_obj = None support_pr_obj = None comp_name = updates[0]['repo'].split('/')[-1] if updates else "unknown" - auto_pr_links = [] - # --- Refactored PV update logic for support layer --- + # --- Refactored support layer PV update logic --- + # Branch setup if issue_number: - # Issue-linked PR: update PV for only the merged component in the shared topic branch feature_branch = f"topic/auto-{ticket_number.lower()}-issue-{issue_number}" - meta_pr_title = f"[Auto] Update meta layer for {ticket_number}" - meta_pr_description = build_pr_list_description(updates) - create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) support_branch = f"topic/auto-support-{ticket_number.lower()}-issue-{issue_number}" - support_repo = None - if os.path.isdir(generic_support_path): - try: - support_repo = Repo(generic_support_path) - # Only update PV field for the current merged component in generic-pkgrev.inc - pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') - if os.path.exists(pkgrev_file): - comp = updates[0]['repo'].split('/')[-1] - pv_field = f'PV:pn-{comp}' - # Print current branch name before reading old_lines - print(f"[DEBUG] Current branch before reading pkgrev_file: {support_repo.active_branch.name}") - with open(pkgrev_file, 'r', newline='') as f: - old_lines = f.readlines() - # Now checkout branch after reading old_lines - create_or_checkout_branch(support_repo, support_branch, base_branch) - new_lines = [] - found_pv = False - for line in old_lines: - if line.strip().startswith(f'{pv_field} ='): - new_lines.append(f'{pv_field} = "{updates[0]['tag']}"\n') - found_pv = True - else: - new_lines.append(line) - if not found_pv: - new_lines.append(f'{pv_field} = "{updates[0]['tag']}"\n') - if old_lines != new_lines: - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_repo.git.commit('-m', f"Update PV for {comp} for {ticket_number} issue {issue_number}") - support_repo.git.push('origin', support_branch) - print(f"[DEBUG] Updated PV field for {comp} in {pkgrev_file}") - else: - print(f"[DEBUG] No PV changes needed for {pkgrev_file}") - except Exception as e: - print(f"[DEBUG] Could not open or update support repo at {generic_support_path}: {e}") - changes_made, support_changed, _ = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) - if changes_made: - commit_and_push( - meta_repo_path, - "Update meta and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) - ) - meta_pr_obj = create_pull_request( - github_token, - meta_repo_name, - feature_branch, - base_branch, - meta_pr_title, - meta_pr_description - ) - else: - print("[DEBUG] No changes detected, PR will not be created for meta layer.") - # Add support PR link if created - # Create support layer PR if support_changed - if support_changed: - support_pr_title = f"[Auto] Update support layer for {ticket_number}" - support_pr_description = build_pr_list_description(updates) - support_pr_obj = create_pull_request( - github_token, - 'rdkcentral/meta-middleware-generic-support', - support_branch, - base_branch, - support_pr_title, - support_pr_description - ) - # ...existing code for summary issue... else: - # Single PR: update PV for only its component in the topic branch feature_branch = f"topic/auto-{ticket_number.lower()}-pr-{pr_number}" - meta_pr_title = f"[Auto] Update meta layer for {ticket_number} (PR {pr_number})" - meta_pr_description = build_pr_list_description(updates) - create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) support_branch = f"topic/auto-support-{ticket_number.lower()}-pr-{pr_number}" - support_repo = None - pkgrev_file = os.path.join(generic_support_path, 'conf', 'include', 'generic-pkgrev.inc') - comp = updates[0]['repo'].split('/')[-1] - pv_field = f'PV:pn-{comp}' - old_lines = [] - previous_value = None - found_pv = False - new_lines = [] - pv_updated = False - if os.path.exists(pkgrev_file): - with open(pkgrev_file, 'r', newline='') as f: - old_lines = f.readlines() - # Extract previous PV value before any branch checkout - for line in old_lines: - pv_match = re.match(rf'^{re.escape(pv_field)}\s*=\s*"([^"]+)"', line.strip()) - if pv_match: - previous_value = pv_match.group(1) + + meta_pr_title = f"[Auto] Update meta layer for {ticket_number}" + (f" (PR {pr_number})" if not issue_number else "") + meta_pr_description = build_pr_list_description(updates) + create_or_checkout_branch(Repo(meta_repo_path), feature_branch, base_branch) + + # --- Update meta layer as before --- + changes_made, _, _ = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) + if changes_made: + commit_and_push( + meta_repo_path, + "Update meta and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + ) + meta_pr_obj = create_pull_request( + github_token, + meta_repo_name, + feature_branch, + base_branch, + meta_pr_title, + meta_pr_description + ) + else: + print("[DEBUG] No changes detected, PR will not be created for meta layer.") + + # --- Support layer PV update logic --- + support_repo = None + if os.path.isdir(generic_support_path): + try: + support_repo = Repo(generic_support_path) + except Exception as e: + print(f"[DEBUG] Could not open support repo at {generic_support_path}: {e}") + + pkgrev_file = None + # Find generic-pkgrev.inc once + for root, dirs, files in os.walk(generic_support_path): + for f in files: + if f == "generic-pkgrev.inc": + pkgrev_file = os.path.join(root, f) + break + if pkgrev_file: + break + if not pkgrev_file: + print(f"[WARNING] generic-pkgrev.inc file not found in {generic_support_path}") + else: + # Prepare PV updates + pv_updates = [] + if issue_number: + # Update PV for all components in updates + for update in updates: + comp = update['repo'].split('/')[-1] + pv_field = f'PV:pn-{comp}' + pv_updates.append((pv_field, update['tag'])) + else: + # Update PV for only the single PR's component + comp = updates[0]['repo'].split('/')[-1] + pv_field = f'PV:pn-{comp}' + pv_updates.append((pv_field, updates[0]['tag'])) + + # Read old pkgrev_file lines + with open(pkgrev_file, 'r', newline='') as f: + old_lines = f.readlines() + new_lines = old_lines.copy() + changed = False + for pv_field, tag in pv_updates: + found_pv = False + for idx, line in enumerate(new_lines): + if line.strip().startswith(f'{pv_field} ='): + new_lines[idx] = f'{pv_field} = "{tag}"\n' found_pv = True - # Build new_lines for update - if pv_match: - new_lines.append(f'{pv_field} = "{updates[0]["tag"]}"\n') - pv_updated = True - else: - new_lines.append(line) - if not pv_updated: - new_lines.append(f'{pv_field} = "{updates[0]["tag"]}"\n') - # Only checkout and update if changes are needed - if old_lines and old_lines != new_lines and os.path.isdir(generic_support_path): - try: - support_repo = Repo(generic_support_path) - create_or_checkout_branch(support_repo, support_branch, base_branch) - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - support_repo.git.commit('-m', f"Update PV for {comp} for {ticket_number} PR {pr_number}") - support_repo.git.push('origin', support_branch) - print(f"[DEBUG] Updated PV field for {comp} in {pkgrev_file}. Previous value: '{previous_value}', new value: '{updates[0]["tag"]}'") - except Exception as e: - print(f"[DEBUG] Could not open or update support repo at {generic_support_path}: {e}") - elif old_lines: - print(f"[DEBUG] No PV changes needed for {pkgrev_file}. Previous value: '{previous_value}', new value: '{updates[0]["tag"]}'") - changes_made, support_changed, support_repo = update_bb_and_pkgrev(meta_repo_path, generic_support_path, updates) - print(f"[DEBUG] changes_made: {changes_made}, support_changed: {support_changed}") - if changes_made: + if not found_pv: + new_lines.append(f'{pv_field} = "{tag}"\n') + # Mark as changed if any PV field was updated or added + if not found_pv or any(line != old_lines[idx] for idx, line in enumerate(new_lines) if line.strip().startswith(f'{pv_field} =')): + changed = True + + # If any PV field changed, update file and commit/push + support_pr_obj = None + if changed and support_repo: + create_or_checkout_branch(support_repo, support_branch, base_branch) + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) commit_and_push( - meta_repo_path, - "Update meta and pkgrev for {}".format(', '.join([f"{u['repo'].split('/')[-1]}:{u['sha'][:7]}:{u['tag']}" for u in updates])) + generic_support_path, + "Update support layer PV fields for {}".format(', '.join([f"{pv}" for pv, _ in pv_updates])) ) - meta_pr_obj = create_pull_request( + support_pr_obj = create_pull_request( github_token, - meta_repo_name, - feature_branch, + 'rdkcentral/meta-middleware-generic-support', + support_branch, base_branch, - meta_pr_title, - meta_pr_description + f"[Auto] Update support layer for {ticket_number}" + (f" (PR {pr_number})" if not issue_number else ""), + build_pr_list_description(updates) ) - if meta_pr_obj: - auto_pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") + elif not support_repo: + print("[DEBUG] No support_repo found for PR creation.") else: - print("[DEBUG] No changes detected, PR will not be created for meta layer.") - # Add support PR link if created - # --- Create summary issue only if more than one auto PR exists --- - # Create summary issue only if both meta and support layer auto PRs exist + print("[DEBUG] No PV changes needed for support layer.") + + # --- Create summary issue only if both meta and support PRs are created --- if meta_pr_obj and support_pr_obj: - auto_pr_links = [] - auto_pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") - auto_pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") - issue_title = f"{ticket_number} - Auto PRs for rdkcentral/{comp_name}" + pr_links = [] + pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") + pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") + issue_title = f"{ticket_number} - Auto PR for rdkcentral/{comp_name} " + (f"{issue_number}" if issue_number else f"{pr_number}") issue_body = ( - f"## Automated Update Summary for {ticket_number}\n\n" + f"## Automated Update Summary for {ticket_number}" + (f" (PR {pr_number})" if not issue_number else "") + "\n\n" f"### PRs Created:\n" + - "\n".join(auto_pr_links) + + "\n".join(pr_links) + "\n\n### Details:\n" + build_pr_list_description(updates) ) From ba9bb7d9cffda5229d0aa2e8c380158bd11a11c8 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 21:46:19 +0530 Subject: [PATCH 86/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 8bc03f6..7beac78 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -571,10 +571,10 @@ def main(): updates = [] for pr in prs: tag = get_tag_for_sha(github_token, pr['repo'], pr['sha']) - print(f"[DEBUG] Tag for {pr['repo']} at {pr['sha']}: {tag}") if not tag: print(f"[WARNING] No tag found that contains commit {pr['sha']} for repo {pr['repo']}. Setting tag as None.") tag = None + print(f"[DEBUG] Tag for {pr['repo']} at {pr['sha']}: {tag}") updates.append({'repo': pr['repo'], 'sha': pr['sha'], 'tag': tag}) print("Updates to be pushed to topic branch: {}".format(updates)) @@ -649,6 +649,9 @@ def main(): # Read old pkgrev_file lines with open(pkgrev_file, 'r', newline='') as f: + print(f"[DEBUG] Reading pkgrev_file: {pkgrev_file}") + #print the lines for debugging + print(f"[DEBUG] Old pkgrev_file lines: {f.readlines()}") old_lines = f.readlines() new_lines = old_lines.copy() changed = False From a872bf879d487d756f08eafabfa348d36e1ffb23 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 22:04:04 +0530 Subject: [PATCH 87/94] Update auto_pr_generation_meta.py --- build_health_check_workflow_scripts/auto_pr_generation_meta.py | 1 + 1 file changed, 1 insertion(+) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 7beac78..79b5517 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -662,6 +662,7 @@ def main(): new_lines[idx] = f'{pv_field} = "{tag}"\n' found_pv = True if not found_pv: + print(f"[DEBUG] Adding new PV field: {pv_field} = {tag}") new_lines.append(f'{pv_field} = "{tag}"\n') # Mark as changed if any PV field was updated or added if not found_pv or any(line != old_lines[idx] for idx, line in enumerate(new_lines) if line.strip().startswith(f'{pv_field} =')): From 88542a23e97452dbcb0ede515a29c3251ec95a8c Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 22:24:37 +0530 Subject: [PATCH 88/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 79b5517..e1ddcd6 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -279,11 +279,13 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): tag_to_use = tag with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() + new_lines = old_lines.copy() file_changed = False found_pv = False - new_lines = [] for idx, line in enumerate(old_lines): + print("pkgrev_pv_field:", pkgrev_pv_field) if line.strip().startswith(f'{pkgrev_pv_field} ='): + print("Updating existing PV field") new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') file_changed = True found_pv = True @@ -647,25 +649,32 @@ def main(): pv_field = f'PV:pn-{comp}' pv_updates.append((pv_field, updates[0]['tag'])) - # Read old pkgrev_file lines + + # Read all lines from pkgrev_file with open(pkgrev_file, 'r', newline='') as f: - print(f"[DEBUG] Reading pkgrev_file: {pkgrev_file}") - #print the lines for debugging - print(f"[DEBUG] Old pkgrev_file lines: {f.readlines()}") old_lines = f.readlines() - new_lines = old_lines.copy() + new_lines = [] changed = False + # Track which PV fields are updated + updated_fields = {pv_field: False for pv_field, _ in pv_updates} + # Update only relevant PV fields, preserve all other lines + for line in old_lines: + line_stripped = line.strip() + updated = False + for pv_field, tag in pv_updates: + if line_stripped.startswith(f'{pv_field} ='): + new_lines.append(f'{pv_field} = "{tag}"\n') + changed = True + updated_fields[pv_field] = True + updated = True + break + if not updated: + new_lines.append(line) + # Add any missing PV fields for pv_field, tag in pv_updates: - found_pv = False - for idx, line in enumerate(new_lines): - if line.strip().startswith(f'{pv_field} ='): - new_lines[idx] = f'{pv_field} = "{tag}"\n' - found_pv = True - if not found_pv: + if not updated_fields[pv_field]: print(f"[DEBUG] Adding new PV field: {pv_field} = {tag}") new_lines.append(f'{pv_field} = "{tag}"\n') - # Mark as changed if any PV field was updated or added - if not found_pv or any(line != old_lines[idx] for idx, line in enumerate(new_lines) if line.strip().startswith(f'{pv_field} =')): changed = True # If any PV field changed, update file and commit/push From c520b8842569588ea8ae8e7d52aeac0813fdfb9e Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 22:29:08 +0530 Subject: [PATCH 89/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index e1ddcd6..06ccf96 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -653,22 +653,25 @@ def main(): # Read all lines from pkgrev_file with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() + new_lines = [] changed = False # Track which PV fields are updated updated_fields = {pv_field: False for pv_field, _ in pv_updates} - # Update only relevant PV fields, preserve all other lines + # Only keep the first occurrence of each PV field, and replace it for line in old_lines: line_stripped = line.strip() - updated = False + replaced = False for pv_field, tag in pv_updates: if line_stripped.startswith(f'{pv_field} ='): - new_lines.append(f'{pv_field} = "{tag}"\n') - changed = True - updated_fields[pv_field] = True - updated = True + if not updated_fields[pv_field]: + new_lines.append(f'{pv_field} = "{tag}"\n') + changed = True + updated_fields[pv_field] = True + # If already updated, skip this duplicate line + replaced = True break - if not updated: + if not replaced: new_lines.append(line) # Add any missing PV fields for pv_field, tag in pv_updates: From d1982e24f300cea6345b8c0932225447f8e52164 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Tue, 15 Jul 2025 22:32:14 +0530 Subject: [PATCH 90/94] Update auto_pr_generation_meta.py --- build_health_check_workflow_scripts/auto_pr_generation_meta.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 06ccf96..3a16789 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -279,11 +279,10 @@ def update_bb_and_pkgrev(manifest_repo_path, generic_support_path, updates): tag_to_use = tag with open(pkgrev_file, 'r', newline='') as f: old_lines = f.readlines() - new_lines = old_lines.copy() + new_lines = [] file_changed = False found_pv = False for idx, line in enumerate(old_lines): - print("pkgrev_pv_field:", pkgrev_pv_field) if line.strip().startswith(f'{pkgrev_pv_field} ='): print("Updating existing PV field") new_lines.append(f'{pkgrev_pv_field} = "{tag_to_use}"\n') From ca52fccca85f8d78ceadb16a1818733dd3ae84a2 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 16 Jul 2025 11:15:32 +0530 Subject: [PATCH 91/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 3a16789..bd91d88 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -708,14 +708,42 @@ def main(): pr_links = [] pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") pr_links.append(f"- [Meta Support Auto PR]({support_pr_obj.html_url})") - issue_title = f"{ticket_number} - Auto PR for rdkcentral/{comp_name} " + (f"{issue_number}" if issue_number else f"{pr_number}") + # Compose a unique summary issue title for the topic branch/issue + if issue_number: + comp_names = ', '.join([u['repo'].split('/')[-1] for u in updates]) + issue_title = f"[Auto] {ticket_number} - Meta Layer Updates for Issue {issue_number} ({comp_names})" + else: + comp_names = updates[0]['repo'].split('/')[-1] if updates else "unknown" + issue_title = f"[Auto] {ticket_number} - Meta Layer Updates for PR {pr_number} ({comp_names})" issue_body = ( - f"## Automated Update Summary for {ticket_number}" + (f" (PR {pr_number})" if not issue_number else "") + "\n\n" + f"## Automated Update Summary for {ticket_number} " + (f"(Issue {issue_number})" if issue_number else f"(PR {pr_number})") + "\n\n" f"### PRs Created:\n" + "\n".join(pr_links) + "\n\n### Details:\n" + build_pr_list_description(updates) ) - create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) + # Only create the summary issue if it does not already exist for this topic branch/issue + g = Github(github_token) + repo = g.get_repo(meta_repo_name) + existing_issue = None + if issue_number: + # Look for any open issue with the ticket number and 'Meta Layer Updates for Issue ' in the title + search_phrase = f"{ticket_number}" in issue.title and f"Meta Layer Updates for Issue {issue_number}" in issue.title + else: + # For PR-only, match the PR number and 'Meta Layer Updates for PR ' + search_phrase = f"{ticket_number}" in issue.title and f"Meta Layer Updates for PR {pr_number}" in issue.title + for issue in repo.get_issues(state='open'): + if issue_number: + if f"{ticket_number}" in issue.title and f"Meta Layer Updates for Issue {issue_number}" in issue.title: + print(f"Summary issue already exists: {issue.html_url}") + existing_issue = issue + break + else: + if f"{ticket_number}" in issue.title and f"Meta Layer Updates for PR {pr_number}" in issue.title: + print(f"Summary issue already exists: {issue.html_url}") + existing_issue = issue + break + if not existing_issue: + create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) if __name__ == '__main__': main() From 8444afa87487aed114674e3f1f42e7d942b83f11 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 16 Jul 2025 11:23:14 +0530 Subject: [PATCH 92/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index bd91d88..2b9ed01 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -726,12 +726,7 @@ def main(): g = Github(github_token) repo = g.get_repo(meta_repo_name) existing_issue = None - if issue_number: - # Look for any open issue with the ticket number and 'Meta Layer Updates for Issue ' in the title - search_phrase = f"{ticket_number}" in issue.title and f"Meta Layer Updates for Issue {issue_number}" in issue.title - else: - # For PR-only, match the PR number and 'Meta Layer Updates for PR ' - search_phrase = f"{ticket_number}" in issue.title and f"Meta Layer Updates for PR {pr_number}" in issue.title + # No need to assign search_phrase; checks are done inside the loop for issue in repo.get_issues(state='open'): if issue_number: if f"{ticket_number}" in issue.title and f"Meta Layer Updates for Issue {issue_number}" in issue.title: From 7c66e16480aee5b15332d959357cce3ee6a261e7 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 16 Jul 2025 14:24:11 +0530 Subject: [PATCH 93/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 2b9ed01..378d24a 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -411,8 +411,10 @@ def create_or_checkout_branch(repo, branch_name, base_branch): config_writer.release() # Check if the branch exists in the remote repository - existing_branches = repo.git.branch('-r') - if f'origin/{branch_name}' in existing_branches: + remote_branches = [b.strip() for b in repo.git.branch('-r').split('\n')] + remote_branch_full = f'origin/{branch_name}' + local_branches = [b.name for b in repo.branches] + if remote_branch_full in remote_branches: print(f"Branch {branch_name} already exists remotely. Checking out and updating it.") # Commit any outstanding changes before switching branches if repo.is_dirty(): @@ -424,13 +426,11 @@ def create_or_checkout_branch(repo, branch_name, base_branch): # If we are not already on the branch, check it out current_branch = repo.active_branch.name if current_branch != branch_name: - # If branch does not exist locally, create tracking branch - local_branches = [b.name for b in repo.branches] if branch_name not in local_branches: - repo.git.checkout('-b', branch_name, f'origin/{branch_name}') + repo.git.checkout('-b', branch_name, remote_branch_full) else: repo.git.checkout(branch_name) - # Pull latest changes from remote + # Always pull latest changes from remote repo.git.pull('origin', branch_name) else: # Switch to 'base_branch' and pull the latest changes to ensure local repo is up-to-date @@ -611,6 +611,8 @@ def main(): meta_pr_title, meta_pr_description ) + if meta_pr_obj: + print(f"[INFO] Meta layer PR created: {meta_pr_obj.html_url}") else: print("[DEBUG] No changes detected, PR will not be created for meta layer.") @@ -698,6 +700,8 @@ def main(): f"[Auto] Update support layer for {ticket_number}" + (f" (PR {pr_number})" if not issue_number else ""), build_pr_list_description(updates) ) + if support_pr_obj: + print(f"[INFO] Support layer PR created: {support_pr_obj.html_url}") elif not support_repo: print("[DEBUG] No support_repo found for PR creation.") else: @@ -730,15 +734,17 @@ def main(): for issue in repo.get_issues(state='open'): if issue_number: if f"{ticket_number}" in issue.title and f"Meta Layer Updates for Issue {issue_number}" in issue.title: - print(f"Summary issue already exists: {issue.html_url}") + print(f"[INFO] Summary issue already exists: {issue.html_url}") existing_issue = issue break else: if f"{ticket_number}" in issue.title and f"Meta Layer Updates for PR {pr_number}" in issue.title: - print(f"Summary issue already exists: {issue.html_url}") + print(f"[INFO] Summary issue already exists: {issue.html_url}") existing_issue = issue break if not existing_issue: - create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) + created_issue = create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) + if created_issue: + print(f"[INFO] Summary issue created: {created_issue.html_url}") if __name__ == '__main__': main() From 43f7079d6cd0b16c674e1f1813f888879a739356 Mon Sep 17 00:00:00 2001 From: ssitar583 Date: Wed, 16 Jul 2025 14:35:54 +0530 Subject: [PATCH 94/94] Update auto_pr_generation_meta.py --- .../auto_pr_generation_meta.py | 107 +++++++++++++----- 1 file changed, 79 insertions(+), 28 deletions(-) diff --git a/build_health_check_workflow_scripts/auto_pr_generation_meta.py b/build_health_check_workflow_scripts/auto_pr_generation_meta.py index 378d24a..d53ddb2 100644 --- a/build_health_check_workflow_scripts/auto_pr_generation_meta.py +++ b/build_health_check_workflow_scripts/auto_pr_generation_meta.py @@ -582,6 +582,9 @@ def main(): meta_pr_obj = None support_pr_obj = None + meta_pr_url = None + support_pr_url = None + summary_issue_url = None comp_name = updates[0]['repo'].split('/')[-1] if updates else "unknown" # --- Refactored support layer PV update logic --- # Branch setup @@ -612,9 +615,20 @@ def main(): meta_pr_description ) if meta_pr_obj: - print(f"[INFO] Meta layer PR created: {meta_pr_obj.html_url}") + meta_pr_url = meta_pr_obj.html_url + print(f"[INFO] Meta layer PR created: {meta_pr_url}") else: - print("[DEBUG] No changes detected, PR will not be created for meta layer.") + # Try to find existing PR for this branch + g = Github(github_token) + repo = g.get_repo(meta_repo_name) + pulls = repo.get_pulls(state='open', head=f"{repo.owner.login}:{feature_branch}") + for pr in pulls: + meta_pr_obj = pr + meta_pr_url = pr.html_url + print(f"[INFO] Existing Meta layer PR: {meta_pr_url}") + break + if not meta_pr_url: + print("[DEBUG] No changes detected, PR will not be created for meta layer.") # --- Support layer PV update logic --- support_repo = None @@ -682,32 +696,43 @@ def main(): changed = True # If any PV field changed, update file and commit/push - support_pr_obj = None - if changed and support_repo: - create_or_checkout_branch(support_repo, support_branch, base_branch) - with open(pkgrev_file, 'w', newline='\n') as f: - f.writelines(new_lines) - support_repo.git.add(pkgrev_file) - commit_and_push( - generic_support_path, - "Update support layer PV fields for {}".format(', '.join([f"{pv}" for pv, _ in pv_updates])) - ) - support_pr_obj = create_pull_request( - github_token, - 'rdkcentral/meta-middleware-generic-support', - support_branch, - base_branch, - f"[Auto] Update support layer for {ticket_number}" + (f" (PR {pr_number})" if not issue_number else ""), - build_pr_list_description(updates) - ) - if support_pr_obj: - print(f"[INFO] Support layer PR created: {support_pr_obj.html_url}") - elif not support_repo: - print("[DEBUG] No support_repo found for PR creation.") - else: + support_pr_obj = None + if changed and support_repo: + create_or_checkout_branch(support_repo, support_branch, base_branch) + with open(pkgrev_file, 'w', newline='\n') as f: + f.writelines(new_lines) + support_repo.git.add(pkgrev_file) + commit_and_push( + generic_support_path, + "Update support layer PV fields for {}".format(', '.join([f"{pv}" for pv, _ in pv_updates])) + ) + support_pr_obj = create_pull_request( + github_token, + 'rdkcentral/meta-middleware-generic-support', + support_branch, + base_branch, + f"[Auto] Update support layer for {ticket_number}" + (f" (PR {pr_number})" if not issue_number else ""), + build_pr_list_description(updates) + ) + if support_pr_obj: + support_pr_url = support_pr_obj.html_url + print(f"[INFO] Support layer PR created: {support_pr_url}") + elif not support_repo: + print("[DEBUG] No support_repo found for PR creation.") + else: + # Try to find existing PR for this branch + g = Github(github_token) + repo = g.get_repo('rdkcentral/meta-middleware-generic-support') + pulls = repo.get_pulls(state='open', head=f"{repo.owner.login}:{support_branch}") + for pr in pulls: + support_pr_obj = pr + support_pr_url = pr.html_url + print(f"[INFO] Existing Support layer PR: {support_pr_url}") + break + if not support_pr_url: print("[DEBUG] No PV changes needed for support layer.") - # --- Create summary issue only if both meta and support PRs are created --- + # --- Always print summary issue link if both PRs exist, or if summary issue exists --- if meta_pr_obj and support_pr_obj: pr_links = [] pr_links.append(f"- [Meta Video Auto PR]({meta_pr_obj.html_url})") @@ -730,21 +755,47 @@ def main(): g = Github(github_token) repo = g.get_repo(meta_repo_name) existing_issue = None - # No need to assign search_phrase; checks are done inside the loop for issue in repo.get_issues(state='open'): if issue_number: if f"{ticket_number}" in issue.title and f"Meta Layer Updates for Issue {issue_number}" in issue.title: print(f"[INFO] Summary issue already exists: {issue.html_url}") existing_issue = issue + summary_issue_url = issue.html_url break else: if f"{ticket_number}" in issue.title and f"Meta Layer Updates for PR {pr_number}" in issue.title: print(f"[INFO] Summary issue already exists: {issue.html_url}") existing_issue = issue + summary_issue_url = issue.html_url break if not existing_issue: created_issue = create_summary_issue(github_token, meta_repo_name, issue_title, issue_body) if created_issue: - print(f"[INFO] Summary issue created: {created_issue.html_url}") + summary_issue_url = created_issue.html_url + print(f"[INFO] Summary issue created: {summary_issue_url}") + else: + # Try to find existing summary issue and print its link + g = Github(github_token) + repo = g.get_repo(meta_repo_name) + for issue in repo.get_issues(state='open'): + if issue_number: + if f"{ticket_number}" in issue.title and f"Meta Layer Updates for Issue {issue_number}" in issue.title: + summary_issue_url = issue.html_url + print(f"[INFO] Summary issue (existing): {summary_issue_url}") + break + else: + if f"{ticket_number}" in issue.title and f"Meta Layer Updates for PR {pr_number}" in issue.title: + summary_issue_url = issue.html_url + print(f"[INFO] Summary issue (existing): {summary_issue_url}") + break + + # --- Print all links at the end for traceability --- + print("\n==== Traceability Links ====") + if meta_pr_url: + print(f"Meta PR: {meta_pr_url}") + if support_pr_url: + print(f"Support PR: {support_pr_url}") + if summary_issue_url: + print(f"Summary Issue: {summary_issue_url}") if __name__ == '__main__': main()