GitHub Action
Keepalive Workflow
GitHub action to prevent GitHub from suspending your cronjob based triggers due to repository inactivity
GitHub will suspend the scheduled trigger for GitHub action workflows if there is no commit in the repository for the past 60 days. The cron based triggers won't run unless a new commit is made. It shows the message "This scheduled workflow is disabled because there hasn't been activity in this repository for at least 60 days" under the cronjob triggered action.
This workflow will automatically create a dummy commit (or use the GitHub API) in your repo if the last commit in your repo is 50 days (default) ago. This will keep the cronjob trigger active so that it will run indefinitely without getting suspended by GitHub for inactivity.
There are three ways you can consume this library in your GitHub actions
You can just include the library as a step after one of your favorite GitHub actions. Your workflow file should have the checkout action defined in one of your steps since this library needs git CLI to work.
name: Github Action with a cronjob trigger
on:
schedule:
- cron: "0 0 * * *"
jobs:
cronjob-based-github-action:
name: Cronjob based github action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# - step1
# - step 2
# - step n, use it as the last step
- uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
Go to repository settings, Click on Actions > General. Update the "Workflow permissions" to "Read and write permissions". Click on save.
Let's take an example of [Waka Readme](https://github.com/athul/waka-readme)
name: My awesome readme
on:
workflow_dispatch:
schedule:
# Runs at 12 am UTC
- cron: "0 0 * * *"
jobs:
update-readme:
name: Update this repo's README
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
- uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
If you do not want dummy commits in your repository's commit history, you can use the library's GitHub API mode.
- Make sure that you create a fine graded token with
actions:write
permission or a PAT withworkflow
permission. You can create it here and here respectively. - Go to settings page in your repo and create a secret with name
PAT_TOKEN
and use the previously created token as the value. Refer docs - Use the code from the following example. Your workflow file should have the checkout action defined in one of your steps since this library needs git CLI to work.
name: Github Action with a cronjob trigger
on:
schedule:
- cron: "0 0 * * *"
jobs:
cronjob-based-github-action:
name: Cronjob based github action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# - step 2
# - step n, use it as the last step
- uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow in api mode
with:
use_api: true
gh_token: ${{ secrets.PAT_TOKEN }}
For developers creating GitHub actions, you can consume the library in your javascript-based GitHub action by installing it from NPM. Make sure that your GitHub action uses checkout action since this library needs it as a dependency. You can also ask your users to include it as an additional step as mentioned in the first part.
Install via NPM:
npm i keepalive-workflow
Install via Yarn:
yarn add keepalive-workflow
const core = require('@actions/core');
const { KeepAliveWorkflow, APIKeepAliveWorkflow } = require('keepalive-workflow');
// Using the lib in Dummy commits mode
KeepAliveWorkflow(githubToken, committerUsername, committerEmail, commitMessage, timeElapsed)
.then((message) => {
core.info(message);
process.exit(0);
})
.catch((error) => {
core.error(error);
process.exit(1);
});
// Using the lib in GitHub API mode
APIKeepAliveWorkflow(githubToken, {
timeElapsed
}.then((message) => {
core.info(message);
process.exit(0);
})
.catch((error) => {
core.error(error);
process.exit(1);
});
If you use the workflow as mentioned via GitHub actions following are the options available to you to customize its behavior.
Option | Default Value | Description | Required |
---|---|---|---|
gh_token |
your default GitHub token with repo scope | GitHub access token with Repo scope | No |
commit_message |
Automated commit by Keepalive Workflow to keep the repository active |
Commit message used while committing to the repo | No |
committer_username |
gkr-bot |
Username used while committing to the repo | No |
committer_email |
[email protected] |
Email id used while committing to the repo | No |
time_elapsed |
50 |
Time elapsed from the previous commit to trigger a new automated commit (in days) | No |
auto_push |
true |
Defines if the workflow pushes the changes automatically | No |
auto_write_check |
false |
Specifies whether the workflow will verify the repository's write access privilege for the token before executing | No |
use_api |
false |
Instead of using dummy commits, workflow uses GitHub API to keep the repository active. This will keep your commit history clean. Make sure you set the gh_token parameter with a token which has actions:write permission enabled. This wont work with the default GitHub actions token |
No |
If you are using the JS Library version of the project, please consult the function's DocStrings in library.js to see the list of available parameters.
Thanks goes to these wonderful people (emoji key):
Abit 💻 |
Guillaume NICOLAS 📖 |
Daniel Maticzka 💻 |
iTrooz 💻 |
Louis-Guillaume MORAND 💻 |
Tiger Kaovilai 📖 |
Howard Wu 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
This project uses GNU GENERAL PUBLIC LICENSE
Hope you liked this project, don't forget to give it a star ⭐.