DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 967,911 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
TopTalentedDev
TopTalentedDev

Posted on

How to prevent GitHub from suspending your cronjob based triggers

I created a GitHub action to prevent GitHub from suspending your cronjob based action triggers due to repository inactivity.

GitHub logo TopTalentedDev / UniSwap-v3-core

๐Ÿฆ„ ๐Ÿฆ„ ๐Ÿฆ„ Core smart contracts of Uniswap v3

Uniswap V3

Lint Tests Fuzz Testing Mythx npm version

This repository contains the core smart contracts for the Uniswap V3 Protocol For higher level contracts, see the uniswap-v3-periphery repository.

Bug bounty

This repository is subject to the Uniswap V3 bug bounty program, per the terms defined here.

Local deployment

In order to deploy this code to a local testnet, you should install the npm package @uniswap/v3-core and import the factory bytecode located at @uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json For example:

import {
  abi as FACTORY_ABI,
  bytecode as FACTORY_BYTECODE,
} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'

// deploy the bytecode
Enter fullscreen mode Exit fullscreen mode

This will ensure that you are testing against the same bytecode that is deployed to mainnet and public testnets, and all Uniswap code will correctly interoperate with your local deployment.

Using solidity interfaces

The Uniswap v3 interfaces are available for import into solidity smart contracts via the npm artifact @uniswap/v3-core, e.g.:

import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol'
contract MyContract {
  IUniswapV3Pool pool;

  function doSomethingWithPool
โ€ฆ
Enter fullscreen mode Exit fullscreen mode

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.

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 create a dummy commit 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.

How to use

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

Via GitHub Actions (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 * * *"

jobs:
  cronjob-based-github-action:
    name: Cronjob based github action
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - # step1
      - # step 2
      - # step n, use it as the last step
      - uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
Enter fullscreen mode Exit fullscreen mode

Let's take an example of 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@v2
      - uses: athul/waka-readme@master
        with:
          WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
      - uses: gautamkrishnar/keepalive-workflow@v1 # using the workflow with default settings
Enter fullscreen mode Exit fullscreen mode

Via JavaScript library (For GitHub Actions developers)

For developers making awesome 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
Enter fullscreen mode Exit fullscreen mode

Install via Yarn:

yarn add keepalive-workflow
Enter fullscreen mode Exit fullscreen mode

Use it in your own GitHub action source code

const core = require('@actions/core');
const { KeepAliveWorkflow } = require('keepalive-workflow');

// Using the lib
KeepAliveWorkflow(githubToken, committerUsername, committerEmail, commitMessage, timeElapsed)
  .then((message) => {
    core.info(message);
    process.exit(0);
  })
  .catch((error) => {
    core.error(error);
    process.exit(1);
  });
Enter fullscreen mode Exit fullscreen mode

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 gkr@tuta.io 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

For Javascript Library

If you are using the JS Library version of the project, please consult the function's DocString in library.js to see the list of available parameters.

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 โญ.

Top comments (1)

Collapse
 
cicirello profile image
Vincent A. Cicirello

Neat idea. At the current time most of my workflows with crons at least occasionally commit on their own, or otherwise I'd consider using your action.

I do have one comment though on the impact of your chosen license on the library version though. First, I'm not one of those anti-GPL people. I use the GPL for several libraries I maintain. It is my favorite open source license.

However, if your intention with the JS library is so that other GitHub Actions developers can use your library in their actions, your choice of GPL as license will significantly limit adoption because the vast majority of GitHub Actions that are currently available use permissive licenses, primarily MIT. And GPL can't be used within something permissively licensed.

I don't see this as an issue for your action though (only for the library). As an action, it is a tool someone is using as part of their development process, and not actually integrated with whatever it is they are developing, so no impact on their own licensing.

I maintain 5 GitHub Actions, all of which I license with MIT. So I can't use your library within these unless I was willing to change to GPL for these, which I'm not.

Anyway, if you want others to use the library in the actions they develop, but if you also don't want to use a permissive license like MIT, you might at least consider using the LGPL instead. It maintains the copyleft clause of GPL for any derivative works of the library itself, but allows use of the unmodified library without impacting license of the application using it.

๐ŸŒš Friends don't let friends browse without dark mode.

Sorry, it's true.