From e69e0c50eb82d046d6526fe731cd161b3f0a5427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1o=20Koko=C5=A1ka?= Date: Fri, 20 Sep 2024 07:29:59 +0200 Subject: [PATCH] Apply code formatting done by pre-commit hook --- .github/workflows/dependency-check.yml | 5 ++-- .github/workflows/dependency-pull-request.yml | 2 +- scripts/dependency_updater.py | 30 +++++++++---------- scripts/generate_pr_body.py | 16 +++++----- 4 files changed, 26 insertions(+), 27 deletions(-) mode change 100755 => 100644 scripts/dependency_updater.py mode change 100755 => 100644 scripts/generate_pr_body.py diff --git a/.github/workflows/dependency-check.yml b/.github/workflows/dependency-check.yml index e262ab15289..c6f91541bdc 100644 --- a/.github/workflows/dependency-check.yml +++ b/.github/workflows/dependency-check.yml @@ -45,12 +45,12 @@ jobs: latest_version=$(_jq '.value.latest_version') echo "Triggering update for $component from $current_version to $latest_version" - + gh workflow run dependency-pull-request.yml \ -f component=$component \ -f current_version=$current_version \ -f latest_version=$latest_version \ - + count=$((count + 1)) # Stop after triggering 30 actions @@ -59,4 +59,3 @@ jobs: break fi done - diff --git a/.github/workflows/dependency-pull-request.yml b/.github/workflows/dependency-pull-request.yml index 4527e70f9f6..863f9ba9fea 100644 --- a/.github/workflows/dependency-pull-request.yml +++ b/.github/workflows/dependency-pull-request.yml @@ -49,7 +49,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | pr_body=$(python scripts/generate_pr_body.py --component ${{ github.event.inputs.component }}) - + # Escape any special characters (e.g., newlines) for the GITHUB_OUTPUT echo "pr_body<> $GITHUB_OUTPUT echo "$pr_body" >> $GITHUB_OUTPUT diff --git a/scripts/dependency_updater.py b/scripts/dependency_updater.py old mode 100755 new mode 100644 index 2cd457962dc..ebb455f2e1e --- a/scripts/dependency_updater.py +++ b/scripts/dependency_updater.py @@ -75,7 +75,7 @@ def get_current_version(component, component_data): placeholder_version = [kube_major_version if item == 'kube_major_version' else item for item in component_data['placeholder_version']] if component.startswith('kube'): current_version = main_yaml_data - else: + else: current_version = download_yaml_data for key in placeholder_version: current_version = current_version.get(key) @@ -83,7 +83,7 @@ def get_current_version(component, component_data): def get_release(component, component_data, session, number_of_releases=10): release = load_from_cache(component) - if not release: + if not release: try: query = """ query { @@ -231,10 +231,10 @@ def update_yaml_checksum(component_data, checksums, version): placeholder_checksum = component_data['placeholder_checksum'] checksum_structure = component_data['checksum_structure'] current = checksum_yaml_data[placeholder_checksum] - if checksum_structure == 'simple': + if checksum_structure == 'simple': # Simple structure (placeholder_checksum -> version -> checksum) current[(version)] = checksums[version] - elif checksum_structure == 'os_arch': + elif checksum_structure == 'os_arch': # OS structure (placeholder_checksum -> os -> arch -> version -> checksum) for os_name, arch_dict in checksums.items(): os_current = current.setdefault(os_name, {}) @@ -266,7 +266,7 @@ def update_yaml_version(component, component_data, version): placeholder_version = component_data['placeholder_version'] resolved_version = resolve_kube_dependent_component_version(component, component_data, version) updated_placeholder = [ - resolved_version if item == 'kube_major_version' else item + resolved_version if item == 'kube_major_version' else item for item in placeholder_version ] current = download_yaml_data @@ -326,7 +326,7 @@ def save_yaml_file(yaml_file, data): except Exception as e: logging.error(f'Failed to save {yaml_file}: {e}') return False - + def open_readme(path_readme): try: with open(path_readme, 'r') as f: @@ -342,7 +342,7 @@ def save_readme(path_readme): except Exception as e: logging.error(f'Failed to save {path_readme}: {e}') return False - + def process_version_string(component, version): if component in ['youki', 'nerdctl', 'cri_dockerd', 'containerd']: if version.startswith('v'): @@ -380,13 +380,13 @@ def process_component(component, component_data, session): latest_version = release.get('name') else: release = get_release(component, component_data, session) - latest_version = release.get('tagName') + latest_version = release.get('tagName') if not latest_version: logging.info(f'Stop processing component {component}, latest version unknown.') return - - + + latest_version = process_version_string(component, latest_version) if current_version == latest_version: @@ -396,7 +396,7 @@ def process_component(component, component_data, session): return else: logging.info(f'Component {component} version discrepancy, current={current_version}, latest={latest_version}') - + if args.ci_check: release['component'] = component release['owner'] = component_data['owner'] @@ -409,7 +409,7 @@ def process_component(component, component_data, session): 'release' : release # needed for generate_pr_body } return - + checksums = get_checksums(component, component_data, latest_version, session) update_yaml_checksum(component_data, checksums, latest_version) if component not in ['kubeadm', 'kubectl', 'kubelet']: # kubernetes dependent components @@ -466,7 +466,7 @@ def main(loglevel, component, max_workers): if args.ci_check: save_json_file(path_version_diff, version_diff) - + save_yaml_file(path_checksum, checksum_yaml_data) save_yaml_file(path_download, download_yaml_data) @@ -480,8 +480,8 @@ def main(loglevel, component, max_workers): parser.add_argument('--max-workers', type=int, default=4, help='Maximum number of concurrent workers, use with caution(sometimes less is more)') parser.add_argument('--skip-checksum', action='store_true', help='Skip checksum if the current version is up to date') parser.add_argument('--ci-check', action='store_true', help='Check versions, store discrepancies in version_diff.json') - + args = parser.parse_args() - main(args.loglevel, args.component, args.max_workers) \ No newline at end of file + main(args.loglevel, args.component, args.max_workers) diff --git a/scripts/generate_pr_body.py b/scripts/generate_pr_body.py old mode 100755 new mode 100644 index f726e9f8583..8357ee93b69 --- a/scripts/generate_pr_body.py +++ b/scripts/generate_pr_body.py @@ -16,7 +16,7 @@ def get_commits(tag, release, number_of_commits=5): owner = release['owner'] repo = release['repo'] repo_url = f'https://github.com/{owner}/{repo}' - + query = """ { repository(owner: "%s", name: "%s") { @@ -70,7 +70,7 @@ def get_commits(tag, release, number_of_commits=5): else: # print('No commit history found.') return None - + pr_commits = '\n
\nCommits\n\n' for commit in commits: node = commit['node'] @@ -99,11 +99,11 @@ def link_pull_requests(input, repo_url): def format_description(description, length=20): lines = description.splitlines() - + if len(lines) > length: first_part = '\n'.join(lines[:length]) collapsed_part = '\n'.join(lines[length:]) - + formatted_description = f"""{first_part}
@@ -129,7 +129,7 @@ def main(component): release = data['release'] owner = release['owner'] repo = release['repo'] - + if component in ['gvisor_containerd_shim','gvisor_runsc']: name = release.get('name') release_url = f'https://github.com/google/gvisor/releases/tag/{name}' @@ -153,8 +153,8 @@ def main(component): pr_body = f""" ### {name} -**Tag**: {tag_name} -**Published at**: {published_at} +**Tag**: {tag_name} +**Published at**: {published_at} **URL**: [Release {tag_name}]({release_url}) #### Description: @@ -169,5 +169,5 @@ def main(component): parser = argparse.ArgumentParser(description='Pull Request body generator') parser.add_argument('--component', required=True, help='Specify the component to process') args = parser.parse_args() - + main(args.component)