Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run ruff format over charm pin update code #1278

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions .github/actions/update-charm-pins/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from httpx import Client
from ruamel.yaml import YAML

yaml = YAML(typ="rt")
yaml = YAML(typ='rt')
yaml.indent(mapping=2, sequence=4, offset=2)

github = Client(
base_url="https://api.github.com/repos",
base_url='https://api.github.com/repos',
headers={
"Authorization": f'token {os.getenv("GITHUB_TOKEN")}',
"Accept": "application/vnd.github.v3+json",
'Authorization': f'token {os.getenv("GITHUB_TOKEN")}',
'Accept': 'application/vnd.github.v3+json',
},
)

Expand All @@ -27,29 +27,27 @@ def update_charm_pins(workflow):
doc = yaml.load(file)

# Assume the workflow has a single job or the first job is parameterized with charm repos
job_name = next(iter(doc["jobs"]))

for idx, item in enumerate(doc["jobs"][job_name]["strategy"]["matrix"]["include"]):
charm_repo = item["charm-repo"]
commit = github.get(f"{charm_repo}/commits").raise_for_status().json()[0]
data = github.get(f"{charm_repo}/tags").raise_for_status().json()
comment = " ".join(
[tag["name"] for tag in data if tag["commit"]["sha"] == commit["sha"]]
+ [commit["commit"]["committer"]["date"]]
job_name = next(iter(doc['jobs']))

for idx, item in enumerate(doc['jobs'][job_name]['strategy']['matrix']['include']):
charm_repo = item['charm-repo']
commit = github.get(f'{charm_repo}/commits').raise_for_status().json()[0]
data = github.get(f'{charm_repo}/tags').raise_for_status().json()
comment = ' '.join(
[tag['name'] for tag in data if tag['commit']['sha'] == commit['sha']]
+ [commit['commit']['committer']['date']]
)

# A YAML node, as opposed to a plain value, can be updated in place to tweak comments
node = doc.mlget(
["jobs", job_name, "strategy", "matrix", "include", idx], list_ok=True
)
node["commit"] = commit["sha"]
node.yaml_add_eol_comment(comment, key="commit")
node = doc.mlget(['jobs', job_name, 'strategy', 'matrix', 'include', idx], list_ok=True)
node['commit'] = commit['sha']
node.yaml_add_eol_comment(comment, key='commit')

with open(workflow, "w") as file:
with open(workflow, 'w') as file:
yaml.dump(doc, file)


if __name__ == "__main__":
logging.basicConfig(level="INFO")
for workflow in " ".join(sys.argv[1:]).split():
if __name__ == '__main__':
logging.basicConfig(level='INFO')
for workflow in ' '.join(sys.argv[1:]).split():
update_charm_pins(workflow)
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ deps =
ruff==0.4.5
commands =
ruff check --preview
ruff format --preview --check

[testenv:static]
description = Run static type checker
Expand Down
Loading