astral-sh / ruff-pre-commit

A pre-commit hook for Ruff.
Apache License 2.0
919 stars 41 forks source link

Automatically trigger mirror job from upstream #17

Closed pmbarrett314 closed 1 year ago

pmbarrett314 commented 1 year ago

It would be helpful if the mirror workflow triggered automatically when a new version was pushed to pypi rather than every 4 hours. Specifically I'm running ruff itself via a github action, but also locally via pre-commit, so if I try to push during those 4 hours it can break my workflows.

This github community thread looks like a solution.

charliermarsh commented 1 year ago

Would love to do this. Need to find time to dig into it.

pmbarrett314 commented 1 year ago

I'll make some PRs as I understand the process.

What you'd need to do (other than merge the PRs) is

  1. Settings > Developer Settings > Personal Access Tokens > Fine Grained Tokens
  2. Create a token with whatever expiration date feels appropriate, access to the ruff-pre-commit repo, and read/write permissions in the Contents category
  3. Set the PAT you get from that as a secret in the ruff repo named PAT_TOKEN

Feel free to check my work, here's some docs I referenced

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#repository_dispatch https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#create-a-repository-dispatch-event https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#repository_dispatch

No worries if you want to dig into it yourself and make sure everything is right, it's an extremely minor inconvenience.

charliermarsh commented 1 year ago

This is great! And hugely appreciated.

charliermarsh commented 1 year ago

(I'll merge the ruff side of this in a bit.)

charliermarsh commented 1 year ago

I just cut v0.0.224, and it looks like the trigger didn't run. It does seem like it POSTed without issue from the ruff side (https://github.com/charliermarsh/ruff/actions/runs/3936152413/jobs/6732625209).

pmbarrett314 commented 1 year ago

Oops, I think when I was making my PRs I accidentally made the event names inconsistent.

So either ruff.yaml:298 in ruff needs to end with --data '{"event_type": "pypi_release"}'

Or main.yaml:7 in this repo needs to say types: [build_pypi_release]

Not sure how that one slipped by me.

charliermarsh commented 1 year ago

Ahhh right. Ok. Will fix in the morning, thanks!

pmbarrett314 commented 1 year ago

Looks like it worked this time

charliermarsh commented 1 year ago

👍 It did, but I think I need to add some sort of timeout or wait, as that run didn't actually pick up the new release (it takes a second to propagate to PyPI and presumedly work through caches).

pmbarrett314 commented 1 year ago

Hmm, that makes sense. The hard but correctish way to do it would probably be something like polling pypi until the new version shows up. The easiest thing to do would probably be just inserting 30 seconds of sleep in the workflow 😂.

charliermarsh commented 1 year ago

Yeah I think a sleep is the move :)