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

fix #234: GitHub action api verification #246

Merged
merged 20 commits into from
Jul 20, 2022

Conversation

rorour
Copy link
Contributor

@rorour rorour commented Jul 12, 2022

fix #234: GitHub Action verification that HEAD's SHA has passed all actions

Here is something functional. Looking forward to feedback.

  • Vars owner and branch are just temporary while I'm developing. I'm testing with rorour/pykern because it has workflow runs on master.
  • In order to get the commit sha matching HEAD from the API, I changed the post-merge action to run on master/main instead of the merged branch.
  • Using requests because the github3 python library doesn't support actions (add support for actions api sigmavirus24/github3.py#1006)
  • Issues to consider:
    • How to handle repos that use main instead of master? I tried to make 'branch' a parameter with default value but that didn't seem to work with pkcli, I got pykern github: error: unrecognized arguments: main
    • How to get the HEAD sha that we're checking against the api? my approach assumes that we have a local copy of the repo, and checks out and pulls master.
    • How to authenticate with github - for now I'm using os.environ['GITHUB_PAT']

@rorour rorour requested a review from robnagler July 12, 2022 19:53
pykern/pkcli/github.py Outdated Show resolved Hide resolved
pykern/pkcli/github.py Outdated Show resolved Hide resolved
.github/workflows/ci-pull-request.yml Outdated Show resolved Hide resolved
@rorour rorour requested a review from robnagler July 15, 2022 18:51
@rorour
Copy link
Contributor Author

rorour commented Jul 15, 2022

@robnagler ready for review

pykern/pkcli/github.py Show resolved Hide resolved
pykern/pkcli/github.py Show resolved Hide resolved
pykern/pkcli/github.py Outdated Show resolved Hide resolved
pykern/pkcli/github.py Outdated Show resolved Hide resolved
pykern/pkcli/github.py Outdated Show resolved Hide resolved
@rorour rorour requested a review from robnagler July 19, 2022 20:38
Copy link
Member

@robnagler robnagler left a comment

Choose a reason for hiding this comment

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

I think this is ok, but I would like to resolve the conditional complexity.

pykern/pkcli/github.py Outdated Show resolved Hide resolved
@rorour rorour requested a review from robnagler July 19, 2022 22:59
pykern/pkcli/github.py Outdated Show resolved Hide resolved
s = b.commit.sha
c = [c.conclusion for c in b.commit.check_runs()]
if not c:
pkcli.command_error("No workflow runs for commit")
Copy link
Member

Choose a reason for hiding this comment

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

Include branch name and sha. Watch for repetition when you do this to the next error message to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by watch for repetition? Should I just print branch name and sha once before all the error checking?

Copy link
Member

Choose a reason for hiding this comment

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

First step is add the branch and sha to all messages. Then, see what patterns repeat. Then, simplify the repetition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pksubprocess_test keeps randomly failing on this pr. Do you know what might be causing it?

=================================== FAILURES ===================================
_________________________ test_check_call_with_signals _________________________
Traceback (most recent call last):
  File "/home/runner/work/pykern/pykern/tests/pksubprocess_test.py", line 65, in test_check_call_with_signals
    pksubprocess.check_call_with_signals(cmd, output=o, msg=msg)
  File "/home/vagrant/.pyenv/versions/3.7.2/envs/py3/lib/python3.7/site-packages/_pytest/python_api.py", line 966, in __exit__
    fail(self.message)
  File "/home/vagrant/.pyenv/versions/3.7.2/envs/py3/lib/python3.7/site-packages/_pytest/outcomes.py", line 196, in fail
    raise Failed(msg=reason, pytrace=pytrace)
Failed: DID NOT RAISE <class 'RuntimeError'>
============================== 1 failed in 10.15s ==============================
error: FAILED=1 passed=37

Copy link
Member

Choose a reason for hiding this comment

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

No, I don't. How would you instrument pksubrocess_test to debug this? How would you debug this more easily?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the failing test is unrelated to the changes in this pr, so I can make an issue for it. This pr is ready for re-review. ea3c408

@rorour rorour requested a review from robnagler July 20, 2022 20:30
Copy link
Member

@robnagler robnagler left a comment

Choose a reason for hiding this comment

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

That's what I was looking for.

@robnagler robnagler merged commit 912bfae into master Jul 20, 2022
@robnagler robnagler deleted the 234-github-action-api-verification branch July 20, 2022 20:42
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.

GitHub Action verification that HEAD's SHA has passed all actions
2 participants