npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

keepalive-workflow

v2.0.7

Published

GitHub action to prevent GitHub from suspending your cronjob based trigger due to repository inactivity

Downloads

20

Readme

Keepalive Workflow npm version

GitHub action to prevent GitHub from suspending your cronjob based triggers due to repository inactivity

Why

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.

preview

What

This workflow will automatically use the GitHub API (or create a dummy commit) in your repo if the last commit in your repo is 45 days (default) ago. This will keep the cronjob trigger active so that it will run indefinitely without getting suspended by GitHub for inactivity.

How to use

There are three ways you can consume this library in your GitHub actions

GitHub API Keepalive Workflow - Default (For GitHub Actions users)

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 * * *"
permissions:
  actions: write
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@v2 # using the workflow with default settings

Moving the keepalive workflow into its own distinct job is strongly recommended for better security. For example:

name: Github Action with a cronjob trigger
on:
  schedule:
    - cron: "0 0 * * *"
jobs:
  main-job:
    name: Main Job
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      # - step1
      # - step 2
      # - Step N
  keepalive-job:
    name: Keepalive Workflow
    runs-on: ubuntu-latest
    permissions:
      actions: write
    steps:
      - uses: actions/checkout@v4
      - uses: gautamkrishnar/keepalive-workflow@v2
Advanced use cases

Lets assume that you have some build workflows:

  • .github/workflows/build1.yml
name: Build 20

on:
  schedule:
    - cron: "0 0 * * *"

jobs:
  publish-npm:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: "20"
          cache: "yarn"
      - run: yarn install --frozen-lockfile
      - run: yarn build
  • .github/workflows/build2.yml
name: Build 19

on:
  schedule:
    - cron: "0 0 * * *"

jobs:
  publish-npm:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: "19"
          cache: "yarn"
      - run: yarn install --frozen-lockfile
      - run: yarn build

You can keep both of these workflows active using the following keepalive workflow code:

name: Keepalive Workflow
on:
  schedule:
    - cron: "0 0 * * *"
permissions:
  actions: write
jobs:
  cronjob-based-github-action:
    name: Keepalive Workflow
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: gautamkrishnar/keepalive-workflow@v2
        with:
          workflow_files: "build1.yml, build2.yml"
          time_elapsed: "0"

Dummy Commit Keepalive Workflow (For GitHub Actions users)

To use the workflow in auto commit mode you can use the following code, Please note that this will create empty commits in your repository every 45 days to keep it active. Use the default API based option instead for a clean Git commit history.

name: Github Action with a cronjob trigger
on:
  schedule:
    - cron: "0 0 * * *"
permissions:
  contents: write
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@v2
        with:
          use_api: false

Moving the keepalive workflow into its own distinct job is strongly recommended here as well, for better security:

name: Github Action with a cronjob trigger
on:
  schedule:
    - cron: "0 0 * * *"
jobs:
  main-job:
    name: Main Job
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      # - step1
      # - step 2
      # - Step N
  keepalive-job:
    name: Keepalive Workflow
    if: ${{ always() }}
    needs: main-job
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: gautamkrishnar/keepalive-workflow@v2
        with:
          use_api: false
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@v2 # using the workflow

Using via NPM (For GitHub Actions developers)

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 the package

Install via NPM:

npm i keepalive-workflow

Install via Yarn:

yarn add keepalive-workflow

Use it in your own GitHub action source code

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);
  });

Options

For GitHub Action

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 | 45 | Time elapsed from the previous commit to trigger a new automated commit or API call (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 | true | Instead of using dummy commits, workflow uses GitHub API to keep the repository active | No | | workflow_files | "" | Comma separated list of workflow files. You can use this to keepalive another workflow that's not a part of keepalive workflow's file. See example for more info. | No |

For Javascript Library

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.

Migrating from v1 to v2

If you are an existing user which used this workflow's v1 version, you can easily migrate to v2 by simply updating the permissions key in your workflow:

Change:

permissions:
  contents: write

to

permissions:
  actions: write

And change the workflow's version from gautamkrishnar/keepalive-workflow@v1 or gautamkrishnar/keepalive-workflow@master to gautamkrishnar/keepalive-workflow@v2. This will automatically start using the workflow's API based method. No more dummy commits 🕺 .

Workflow Versions

  • v1 version of project used dummy commit by default to keep the repository active, It will no longer be maintained except for security patches and bug fixes. You can view the source coe of v1 version at the master branch of this repository. This branch is kept intact for people who are using gautamkrishnar/keepalive-workflow@master.
  • v2 version will be developed and maintained by keeping the version2 branch as the source. Going forward, This will be the main branch.

FAQs and Common issues

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project uses GNU GENERAL PUBLIC LICENSE

Liked it?

Hope you liked this project, don't forget to give it a star ⭐.