Skip to content

Commit

Permalink
Apply code formatting done by pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kokyhm committed Sep 20, 2024
1 parent c0a8b5f commit e69e0c5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/dependency-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,4 +59,3 @@ jobs:
break
fi
done
2 changes: 1 addition & 1 deletion .github/workflows/dependency-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF" >> $GITHUB_OUTPUT
echo "$pr_body" >> $GITHUB_OUTPUT
Expand Down
30 changes: 15 additions & 15 deletions scripts/dependency_updater.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ 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)
return current_version

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 {
Expand Down Expand Up @@ -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, {})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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'):
Expand Down Expand Up @@ -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:
Expand All @@ -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']
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
main(args.loglevel, args.component, args.max_workers)
16 changes: 8 additions & 8 deletions scripts/generate_pr_body.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_commits(tag, release, number_of_commits=5):
else:
# print('No commit history found.')
return None

pr_commits = '\n<details>\n<summary>Commits</summary>\n\n'
for commit in commits:
node = commit['node']
Expand Down Expand Up @@ -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}
<details>
Expand All @@ -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}'
Expand All @@ -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:
Expand All @@ -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)

0 comments on commit e69e0c5

Please # to comment.