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

Adding CI workflow for annotations of specification property #742

Closed
wants to merge 32 commits into from

Conversation

suprith-hub
Copy link
Contributor

@suprith-hub suprith-hub commented Apr 24, 2024

Adressing this issue: #728
This work: I have some queries:

  1. Its printing in the run python script. Need help in printing in Annotations section
  2. I dont know whther the ::notice keyword suites this more
  3. for draft3 - The spec is a pdf, so do I have have to write exceptional case for it. I guess we can keep another property in front of ::notice
  4. And check on the folder structure needed

@suprith-hub suprith-hub requested a review from a team as a code owner April 24, 2024 17:08
@karenetheridge
Copy link
Member

There's a lot of correction commits in here that should be squashed together.

@suprith-hub
Copy link
Contributor Author

suprith-hub commented Apr 24, 2024

There's a lot of correction commits in here that should be squashed together.

I have squashed it into First Workflow2. I don't know if I have did it properly...😕

@suprith-hub
Copy link
Contributor Author

Hi.... should I reopen the PR?? or can tell me if this method is wrong too. I am ready for any changes...

@Julian
Copy link
Member

Julian commented Apr 29, 2024

I'm not sure about what we do in other repositories in the org, but we don't have any such policy in this repo to ask for squashed commits from newer contributors so as far as I'm concerned personally you're fine.

I haven't looked yet in detail at what to suggest but what I saw as the more important thing is you're still interacting with gitpython, which I wouldn't expect you to be doing -- you should rely on the workflow to check out the current version of the repo but then you should simply be able to interact with the filesystem (i.e. use Path.walk probably) to iterate over all the JSON files in the tests/ directory.

@Julian
Copy link
Member

Julian commented Apr 29, 2024

for draft3 - The spec is a pdf, so do I have have to write exceptional case for it. I guess we can keep another property in front of ::notice

That's odd, I could have sworn it didn't used to be but maybe I'm wrong. Anyways, it's almost certainly fine even if we leave draft 3 out entirely, we write in the readme that support for it here is frozen so certainly not worth your time I think.

@Julian
Copy link
Member

Julian commented Apr 29, 2024

And sorry for the triple post but as for

Its printing in the run python script. Need help in printing in Annotations section

You need to redirect your output when you run your python script.py thing, to >>$GITHUB_OUTPUT I think but I forget, check the docs I linked above.

@suprith-hub
Copy link
Contributor Author

I'm not sure about what we do in other repositories in the org, but we don't have any such policy in this repo to ask for squashed commits from newer contributors so as far as I'm concerned personally you're fine.

I haven't looked yet in detail at what to suggest but what I saw as the more important thing is you're still interacting with gitpython, which I wouldn't expect you to be doing -- you should rely on the workflow to check out the current version of the repo but then you should simply be able to interact with the filesystem (i.e. use Path.walk probably) to iterate over all the JSON files in the tests/ directory.

I felt the need of pygithub to identify new files and lines in the present PR,
Is it that by writing script to walk over all the files in /tests* automatically only those files or lines changed will run the script we write to print annotations.
If not, then by annotating all specifications it will be 100s of annotations.. so,
I understand that we cannot rely on pygithub as its a library and better to rely on shell scripts, can I get an example of some annotations anywhere which does similar task.

@Julian
Copy link
Member

Julian commented Apr 29, 2024

I felt the need of pygithub to identify new files and lines in the present PR,

What I was trying to mention before is I have to believe that functionality is going to be natively supported in GitHub Actions somehow, but as I said previously I know I'm not giving you where precisely (as I haven't researched it myself). But IIRC I pointed you at a place to look (and if not I can give it another few minutes to find it). I think I mentioned I'd try just outputting all of them, and seeing whether the GitHub UI then simply does the right thing and only shows the relevant ones for the PR.

If not, then by annotating all specifications it will be 100s of annotations

(There's nothing inherently wrong with this).

I understand that we cannot rely on pygithub as its a library and better to rely on shell scripts, can I get an example of some annotations anywhere which does similar task.

No, shell scripts are definitely not what we want to rely on, I simply am saying I think your script can be a third of the size if you rely on the above :)

@suprith-hub
Copy link
Contributor Author

Hi, @Julian I have made the changes, now it annotated without using pygithub,
It also creates a section unchanged files with annotations during all the PRs.. is that good like this
Screenshot 2024-04-30 123105

@Julian
Copy link
Member

Julian commented Apr 30, 2024

It also creates a section unchanged files with annotations during all the PRs.. is that good like this

That seems fine/good to me.

Can you share what it looks like in the "real" case? (I.e. for lines that do have changes)?

I'll have to leave you some comments on your script.

@@ -0,0 +1,23 @@
name: Specifications Annotation Workflow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: Specifications Annotation Workflow
name: Show Specification Annotations

And maybe rename the file to show_specification_annotations.yml.

- 'tests/**'

jobs:
run_tests:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
run_tests:
annotate:


jobs:
run_tests:
name: logging annotations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just remove this, the workflow name is/will be fine.


steps:
- name: Checkout Repository
uses: actions/checkout@v3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uses: actions/checkout@v3
uses: actions/checkout@v4

runs-on: ubuntu-latest

steps:
- name: Checkout Repository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the name here I think.

print(f"::warning file={file},line=1::Annotation: {url}")

# Read specification URLs from JSON file
with open("bin/specification_urls.json", "r") as f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pathlib.Path here and below instead of open or the os module.

# Iterate through JSON files in tests folder and subdirectories
for root, dirs, files in os.walk("tests"):
for file_name in files:
if file_name.endswith(".json"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you'll use Path.rglob(".json") instead of .walk.

elif spec in ["ecma262", "perl5"]:
print_github_action_notice(file_path, urls[spec] + section)
elif re.match("^rfc\\d+$", spec):
print_github_action_notice(file_path, urls["rfc"] + spec + ".txt#" + section)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit obtuse. Can you instead take a quick look into whether it's easy to use a URL template (which will likely mean adding a dependency on a Python URL template library), which will allow you to instead put this logic in specification_urls.json rather than special casing it here.

else:
print_github_action_notice(file_path, urls["iso"])
except json.JSONDecodeError:
print(f"Failed to parse JSON content for file: {file_path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your print I suspect will go nowhere here so no one will see it, even though other CI will fail anyhow. But ideally you need to instead emit an error message to GitHub actions, and probably also be exiting with non-zero status.

"perl5": "https://perldoc.perl.org/perlre#",
"rfc": "https://www.rfc-editor.org/rfc/",
"iso": "https://www.iso.org/obp/ui"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please configure your editor to make sure all files end in a newline or be sure you do so manually, one is missing here.

@suprith-hub
Copy link
Contributor Author

suprith-hub commented Apr 30, 2024

All done @Julian, also added line number by taking the description of the testcase ig if that's ok.
Can you review my PR
Screenshot 2024-05-01 022756
this is an Example of the annotations collection
Screenshot 2024-05-01 024442

Copy link
Member

@Julian Julian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the update, but looking nearly there, really nice. Left a (hopefully last) round of comments!

Print GitHub action notice with file path, URL, and line number.

Parameters:
file (str): File path.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good you added these! Though in modern Python they go in the signature, so here:

github_action_notice(file: str, url: str, line: int)

(though probably file should be a Path)


def github_action_notice(file, url, line):
"""
Print GitHub action notice with file path, URL, and line number.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Print GitHub action notice with file path, URL, and line number.
Return a GitHub action notice with file path, URL, and line number.

bin/annotation_workflow.py Outdated Show resolved Hide resolved
json_file_path = Path("bin/specification_urls.json")

# Read specification URLs from JSON file using pathlib.Path
with json_file_path.open("r", encoding="utf-8") as f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with json_file_path.open("r", encoding="utf-8") as f:
urls = json.loads(json_file_path.read_text())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(But see above)

bin/annotation_workflow.py Show resolved Hide resolved
else:
url = urls[spec].format(spec=spec, section=section)

clear_previous_annotations()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really correct? Why do we clear all annotations each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annotations were getting stacked up in the same place whenever commits were made on the same PR, so I found this solution

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this line clears them each test -- if that's the case, shouldn't we be clearing them simply once at the top of the run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me test it...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works even specified at the top. 👍

bin/annotation_workflow.py Show resolved Hide resolved
bin/annotation_workflow.py Outdated Show resolved Hide resolved
@suprith-hub
Copy link
Contributor Author

@Julian I have done the changes...

@Julian
Copy link
Member

Julian commented May 9, 2024

@Era-cell you had a few comments of mine that weren't addressed (fixing/adding type annotations instead of docstrings, fixing the relative paths, using Path.read_text).

I made those changes along with a few additional ones (adding docstrings in a place or two, along with slightly improved line information) in #746 which is on top of your commits. Going to close this, I'll merge your changes in that other PR after reverting the change to additionalProperties.json and then we can see how this goes.

Appreciate your work, well done!

@Julian Julian closed this May 9, 2024
@suprith-hub
Copy link
Contributor Author

@Era-cell you had a few comments of mine that weren't addressed (fixing/adding type annotations instead of docstrings, fixing the relative paths, using Path.read_text).

I made those changes along with a few additional ones (adding docstrings in a place or two, along with slightly improved line information) in #746 which is on top of your commits. Going to close this, I'll merge your changes in that other PR after reverting the change to additionalProperties.json and then we can see how this goes.

Appreciate your work, well done!

Okay.. I'll note it. I have got a lot to learn from here. Thank you ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants