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

Automatically trigger mirror job from upstream #17

Closed
pmbarrett314 opened this issue Jan 16, 2023 · 11 comments
Closed

Automatically trigger mirror job from upstream #17

pmbarrett314 opened this issue Jan 16, 2023 · 11 comments

Comments

@pmbarrett314
Copy link
Contributor

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
Copy link
Member

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

@pmbarrett314
Copy link
Contributor Author

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
Copy link
Member

This is great! And hugely appreciated.

@charliermarsh
Copy link
Member

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

@charliermarsh
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

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

@pmbarrett314
Copy link
Contributor Author

@charliermarsh
Copy link
Member

👍 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
Copy link
Contributor Author

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
Copy link
Member

Yeah I think a sleep is the move :)

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

No branches or pull requests

2 participants