Prevent scheduled GitHub Actions from becoming disabled
Asked Answered
H

3

22

I am a maintainer of a few Julia GitHub repositories which use GitHub Actions for nightly CI runs, via cron. Some of these packages do not get maintenance for months but are used within the ecosystem and I'd like to keep them active. GitHub's current policy is to disable these actions when no repository activity has occurred in 60 days.

I'm wondering if there is a definition for what repository activity is to prevent actions from being disabled. Is this something as simple as commenting on an issue? Or do commits need to be pushed to the main branch?

Secondly, has anyone found a good solution for keeping repositories active? I was thinking of creating a Lambda function which runs every 59 days, and performs some form of repository activity to keep things alive. I've only found this HackerNews post which brings this up, however there are no comments:

Scheduled workflows will be disabled by default in forks of public repos and in public repos with no activity for 60 consecutive days. W e’re making two changes to the usage policy for GitHub Actions. These changes will enable GitHub Actions to scale with the incredible adoption we’ve seen from the GitHub community. Here’s a quick overview:

  1. Starting today, scheduled workflows will be disabled by default in new forks of public repositories.

  2. Scheduled workflows will be disabled in public repos with no activity for 60 consecutive days.

Hoot answered 20/4, 2021 at 18:23 Comment(2)
I wrote some automations that pushes a pointless commit every couple months to resolve this at the moment, but I would love to have an official solution for this issue as well.Dash
For anyone curious, it seems like currently only commits (and only commits to the main branch) are considered "activity": github.community/t/…Abode
H
1

I was unable to find a resolution to this issue. Instead I've implemented a hopefully temporary solution to this problem.

https://github.com/invenia/KeepActionsAlive

This package uses AWS SAM to deploy a Lambda function. The function runs every 59 days, gathering all non-forked, non-archived repos for your organization. It will then hit the enable workflow REST API endpoint for all non-manually disabled workflows. There is functionality built in to support repos outside of an organization.

It's very rudimentary, but for those already using AWS this should help fix the problem.

Hoot answered 30/7, 2021 at 13:14 Comment(2)
Dumb questions... this seems like it's supposed to sort of reset the 60 day timeout before it happens, since you've set it to 59 days. I guess sending the enable command resets it, even if it's currently still enabled? Also, if that's the case, could you just run this Python script from the repo itself as another action to reset all the actions, or is GitHub smart enough to prevent that from working.Abode
You definitely could go the route of another action keeping itself and others alive. The reason why I created this as an AWS solution is to have an easier time maintaining it. Modifying one single script is a lot easier to do than mass updating/installing scripts in every repository that we own. We've done this previous when migrating off of TravisCI and onto GHA and it was a very slow and painful process. However, if you only have one or two repositories that you're working on this would be a better (and free) solution to have another GHA that keeps everything alive.Hoot
P
6

I too was looking for a solution to this and I encountered a plugin on the GitHub Marketplace that may be what you're looking for. The only downside is it creates "dummy commits" to your repo, which depending on your preference, you may or may not be happy with.

Keepalive Workflow: https://github.com/marketplace/actions/keepalive-workflow

Pigment answered 14/10, 2021 at 11:25 Comment(2)
Also, see this issue about dummy commits on the above Keepalive Workflow: github.com/gautamkrishnar/keepalive-workflow/issues/…Pigment
Here's an alternative that doesn't use dummy commits, only GitHub API: github.com/liskin/gh-workflow-keepaliveMewl
H
1

I was unable to find a resolution to this issue. Instead I've implemented a hopefully temporary solution to this problem.

https://github.com/invenia/KeepActionsAlive

This package uses AWS SAM to deploy a Lambda function. The function runs every 59 days, gathering all non-forked, non-archived repos for your organization. It will then hit the enable workflow REST API endpoint for all non-manually disabled workflows. There is functionality built in to support repos outside of an organization.

It's very rudimentary, but for those already using AWS this should help fix the problem.

Hoot answered 30/7, 2021 at 13:14 Comment(2)
Dumb questions... this seems like it's supposed to sort of reset the 60 day timeout before it happens, since you've set it to 59 days. I guess sending the enable command resets it, even if it's currently still enabled? Also, if that's the case, could you just run this Python script from the repo itself as another action to reset all the actions, or is GitHub smart enough to prevent that from working.Abode
You definitely could go the route of another action keeping itself and others alive. The reason why I created this as an AWS solution is to have an easier time maintaining it. Modifying one single script is a lot easier to do than mass updating/installing scripts in every repository that we own. We've done this previous when migrating off of TravisCI and onto GHA and it was a very slow and painful process. However, if you only have one or two repositories that you're working on this would be a better (and free) solution to have another GHA that keeps everything alive.Hoot
M
0

Let me answer your first question (apparently nobody bothered to answer) first:

What's going on?

I'm wondering if there is a definition for what repository activity is to prevent actions from being disabled. Is this something as simple as commenting on an issue? Or do commits need to be pushed to the main branch?

According to the GitHub docs workflows are "automatically disabled when no repository activity has occurred in 60 days". The GitHub docs don't elaborate on what this means exactly, thus the exact definition might change.

From observation we know that GitHub requires you to push commits. Just commenting on issues is not sufficient to keep workflows alive.

How to fix it

Secondly, has anyone found a good solution for keeping repositories active?

Yes, there are numerous solutions to keep a repository's workflows alive despite the 60 days limit. A few have been mentioned in this question already, but there are some more and new one's pop up from time to time. However, since you only need one, I don't see much reason to create a complete list.

All solutions can be boiled down to basically two approaches:

  1. Using the GitHub API to re-enable disabled GitHub workflows. Since GitHub introduced this limitation it was believed that this approach only works when the GitHub workflow has been disabled already, thus it was believed that only another server could do this (like with Matthew's recommended invenia/KeepActionsAlive). However, this isn't true - see below.

  2. Add empty "ghost/dummy" commits to the repo to spoof activity. This has many disadvantages, like cluttering your repo with useless empty commits possibly triggering other workflows, issues with protected branches, requiring way to powerful access (i.e. security risks), etc. This approach (as used by e.g. Jack's recommended gautamkrishnar/keepalive-workflow till 2024) was predominant since GitHub introduced this limitation.

AFAIK I was the first one to notice in 2022 that the supposed limitation of the API approach isn't really true (but I might be wrong, I just did extensive research back then and looked into all existing solutions at that time and didn't find a single one using that approach): Enabling a workflow even if it hasn't been disabled yet resets the 60 days timer.

I therefore created my own, fully configurable solution back in 2022 requiring neither an external server, nor to create "ghost/dummy" commits. Since it has some more advantages (better configurability, better logging, support for multiple repos, support for execution on the local machine, …) I want to present it below as my recommended solution nevertheless.

My recommendation

As explained earlier I've created a GitHub action ("GitHub Workflow Immortality") to solve this task back in 2022.

https://github.com/marketplace/actions/github-workflow-immortality

Using the GitHub action is pretty straight-forward:

  1. First create a personal access token (PAT). A classic PAT is simplest and always works, but fine-grained PATs are supported to. See the action's docs to learn about the differences of fine-grained and classic PATs.

  2. Then create an encrypted secret called PERSONAL_ACCESS_TOKEN in either some (new) meta repo, or the repo whose workflows you want to keep alive.

  3. Last but not least create the GitHub workflow .github/gh-workflow-immortality.yml (i.e. just create and push that new file to your repo) like the following and incorporate the GitHub action as its only step:

    name: GitHub Workflow Immortality
    
    on:
      schedule:
        # run once a month on the first day of the month at 00:20 UTC
        - cron: '20 0 1 * *'
      workflow_dispatch: {}
    
    jobs:
      keepalive:
        name: GitHub Workflow Immortality
    
        runs-on: ubuntu-latest
        permissions: {}
    
        steps:
          - name: Keep cronjob based triggers of GitHub workflows alive
            uses: PhrozenByte/gh-workflow-immortality@v1
            with:
              secret: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
              repos: ${{ github.repository }}
    

    If you want to use a meta repo to keep the workflows of multiple repos alive, you might want to replace repos: ${{ github.repository }} by either a list of repos, or by the users and/or orgs config taking GitHub usernames resp. organization names. See the GitHub action's docs for more info about that.

Unlike the other solutions this GitHub action is fully configurable and allows not just to keep the workflows of the same repo alive, but of arbitrary repos as well (as long as the configured PAT has permission to do so). This e.g. allows one to use a single "keep alive" workflow (e.g. in the user's or organization's meta repository) to keep all workflows of a GitHub user and/or organization alive. Just do so and you don't have to ever think about the matter again.

As final note, the GitHub action wraps a simple Bash script, thus you can run it locally for testing purposes, too. However, the script provides some pretty decent logging and tells what's going on, so you likely don't have to; but if you have to, you can. The script doesn't depend on any external tools besides the usually pre-installed curl and jq (i.e. you don't have to install the huge GitHub CLI just to perform such small task).

Manos answered 7/8, 2024 at 11:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.