codeforIATI / iati-ideas

💡 Ideas for new codeforIATI projects and blogs
https://ideas.codeforiati.org
0 stars 0 forks source link

[PROJECT IDEA] Ensure cron jobs don’t switch off after 60 days of inactivity #47

Closed andylolz closed 2 years ago

andylolz commented 2 years ago

Rationale

Code for IATI has a number of repos with github actions that run on a schedule. Often, these actions are doing work that involves updating a non-default branch, but don’t necessarily make any changes to the default branch.

Github says:

In a public repository, scheduled workflows are automatically disabled when no repository activity has occurred in 60 days.

Updates to non-default branches does not count as "repository activity", so our scheduled actions are frequently being disabled. There’s no notification when an action is automatically disabled – it just stops running, and needs to be manually restarted.

Proposal

There are a few different ways to tackle this:

  1. We could change the default branch on these repos, so that the updated branch is default. This will involve some shuffling about, since the README and workflow will need to stay on the default branch. We’ll lose version control on these files for instances where we deliberately scrub the history. Also, there’s no guarantee that this will fix the problem, since in some cases updates are less frequent than every 60 days
  2. We could have some separate service that uses the github API to check if a workflow has stopped, and give it a kick if so (I think @markbrough proposed this). I’ve no idea how difficult this is (EDIT: here’s the relevant API endpoint), but it is much cleaner than the previous solution, and would work in all cases. It would still work on a schedule, so it would still need to be kept alive somehow.
  3. The scheduled action could make some other modification to the repo that ensures it is still considered active, e.g. post a comment on an issue. This feels very hacky, but it might actually be the easiest thing.

https://github.com/codeforIATI/status/issues/2 is somewhat related.

andylolz commented 2 years ago

Here’s a non-exhaustive list of scheduled actions:

I’ve probably missed some! I did this manually, but there’s probably some way to list them all using the github API.

matmaxgeds commented 2 years ago

Would it feel less hacky if the action just commented a thread to confirm that it had run, or even updated a timestamp visible to users of the service.....so the hack would at least be useful?

andylolz commented 2 years ago

Would it feel less hacky if the action just commented a thread to confirm that it had run, or even updated a timestamp visible to users of the service.....so the hack would at least be useful?

Yeah, I think both of those are nice ideas.

We first need to confirm what Github counts as “repository activity”. We know commits to a non-default branch don’t count. I assume comments on issues do count… But it’s worth confirming that.

andylolz commented 2 years ago

Hopefully fixed here: https://github.com/codeforIATI/workflow-restarter

This uses the github API to check for stopped workflows. If a workflow has stopped, it’s restarted. The repo keeps its own workflow alive by regularly committing to its own default branch.

markbrough commented 2 years ago

Amazing work, thanks @andylolz !