Set GitHub Actions timeout-minutes

suzukishunsuke

Shunsuke Suzuki

Posted on July 3, 2024

Set GitHub Actions timeout-minutes

In this article I introduce a GitHub Actions' setting timeout-minutes and tools related to timeout-minutes.

  • What's timeout-minutes?
  • Why should you set timeout-minutes?
  • Linters to enforce timeout-minutes
  • A command line tool to set timeout-minutes to all GitHub Actions jobs
  • Set timeout-minutes to your all repositories

What's timeout-minutes?

timeout-minutes is the maximum number of minutes to let a job run before GitHub automatically cancels it.
The default value is 360.

Why should you set timeout-minutes?

The default value of timeout-minutes is 360, but this is too long for most GitHub Actions jobs.
Even if processes are stuck for some reason, jobs keeps running until the timeout.
This wastes resources uselessly.
By setting timeout-minutes properly, you can notice the issue and resolve it by retrying jobs quickly.

https://exercism.org/docs/building/github/gha-best-practices#h-set-timeouts-for-workflows

Linters to enforce timeout-minutes

There are linters to enforce timeout-minutes.

  1. ghalint is a GitHub Actions linter
  2. lintnet is a general purpose linter powered by Jsonnet

ghalint

From ghalint v0.2.12, ghalint enforces timeout-minutes.

https://github.com/suzuki-shunsuke/ghalint/blob/main/docs/policies/012.md

lintnet

ghalint is ported to lintnet as a module.

https://github.com/lintnet-modules/ghalint

So you can enforce timeout-minutes using the module.

https://github.com/lintnet-modules/ghalint/tree/main/workflow/job_timeout_minutes_is_required

A command line tool to set timeout-minutes to all GitHub Actions jobs

It is very bothersome to set timeout-minutes to a lot of jobs by hand.
But you can do it easily using a command line tool ghatm.
It finds GitHub Actions workflows and adds timeout-minutes to jobs which don't have the setting.
It edits workflow files while keeping YAML comments, indents, empty lines, and so on.

For details, please see https://github.com/suzuki-shunsuke/ghatm .

Set timeout-minutes to your all repositories

ghatm is useful, but it is very bothersome to run ghatm and create and merge pull requests to a lot of repositories by hand.
But you can do it easily using ghatm and multi-gitter.

  1. Create pull requests by multi-gitter run
multi-gitter run ./ghatm-set.sh \
    --config config.yaml \
    -O "$org" \
    -t "ci: set timeout-minutes using ghatm" \
    --skip-forks \
    -b "$body" \
    -B ci-set-timeout-minutes-by-ghatm
Enter fullscreen mode Exit fullscreen mode

ghatm-set.sh

ghatm set
Enter fullscreen mode Exit fullscreen mode

config.yaml

git-type: cmd # Use git to sign commits
Enter fullscreen mode Exit fullscreen mode
  1. Merge pull requests by multi-gitter merge
multi-gitter merge \
    -O "$org" \
    -B ci-set-timeout-minutes-by-ghatm \
    --skip-forks
Enter fullscreen mode Exit fullscreen mode
đź’– đź’Ş đź™… đźš©
suzukishunsuke
Shunsuke Suzuki

Posted on July 3, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related