Skip to main content

shellcheck-gha

PyPI Project Version Supported Python Versions Project Python Implementations

This Python script extracts shell scripts from GitHub workflows (jobs.<job_id>.steps[*].run) and runs them against ShellCheck.

Installation

Requirements:

  • Python ≥ 3.11
  • ShellCheck ≥ 0.9.0, available on apt, brew, cabal, dnf, and pkg.

Using GitHub Actions (recommended)

The shellcheck-gha project can be used as a GitHub Workflow step:

on:
  push:
    paths:
      - .github/**
  pull_request:
    paths:
      - .github/**

permissions:
  contents: read

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Run ShellCheck
        uses: saleor/shellcheck-gha@v0
        # Uncomment to customize the scan directory:
        # with:
        #   scan-directory-path: .github/

[!IMPORTANT]
By default only the ./.github directory is scanned (recursively). If some GitHub Composite actions are defined outside the .github directory, consider adding steps to scan the additional directories by changing the scan-directory-path parameter.

PyPI

The project is hosted on PyPI at https://pypi.org/project/shellcheck-gha/. To install the project, run:

$ pip install shellcheck-gha

From Source

Alternatively, the project can be cloned and installed using poetry.

$ git clone https://github.com/saleor/shellcheck-gha
$ pip install poetry
$ poetry install
$ shellcheck-gha --help

Usage

$ shellcheck-gha --help
usage: shellcheck-gha [-h] [--default-shell DEFAULT_SHELL] [--verbose] [--debug] [--skip-unknown-files | --no-skip-unknown-files] [directory]

positional arguments:
  directory

options:
  -h, --help            show this help message and exit
  --default-shell DEFAULT_SHELL
                        The default shell running in the workflow(s)
  --verbose             Show more details about the execution.
  --debug               Add debug information (takes precedence over --verbose).
  --skip-unknown-files, --no-skip-unknown-files
                        Whether to exit with an error on when parsing non-GitHub workflow or composite action YAML files. Skipping is useful when a directory
                        may be mixed with other YAML files (e.g. config files such as .github/dependabot.yaml). Unknown files are skipped by default.

Example

$ shellcheck-gha .
=== Results: 2 file(s) have findings ===
Scanned 5 files (16 shell scripts)
[INFO] In bad.yaml:
    Message: Double quote to prevent globbing and word splitting.
    More information: https://www.shellcheck.net/wiki/SC2086
    Code:
        test $USE_GITIGNORE == true
             ^^^^^^^^^^^^^^^
[INFO] In tests/sample_workflows/with-findings.yaml:
    Message: Double quote to prevent globbing and word splitting.
    More information: https://www.shellcheck.net/wiki/SC2086
    Code:
        echo $BAD_JOB1
             ^^^^^^^^^^
[INFO] In tests/sample_workflows/with-findings.yaml:
    Message: Double quote to prevent globbing and word splitting.
    More information: https://www.shellcheck.net/wiki/SC2086
    Code:
        echo $BAD_JOB2
             ^^^^^^^^^^

Goals

  • Only check *nix related shells (sh, bash, ksh)
  • Provide useful logs that allow the users to quickly find the problematic code in their workflow.

Non-Goals

  • Differential checking (base vs head commit)
  • Logical understanding of GitHub workflows, such as (but not limited to):
    • Handling defaults.run.shell
    • Support for string interpolation (${{ ... }})
  • Tracking down exact locations of the findings (line numbers, columns)

Release files for shellcheck-gha 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shellcheck-gha 0.1.2
File Size Uploaded
shellcheck_gha-0.1.2.tar.gz 9.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shellcheck-gha 0.1.2
File Interpreter ABI Platform
shellcheck_gha-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 21.1 kB

Release files / shellcheck_gha-0.1.2.tar.gz

Download URL shellcheck_gha-0.1.2.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
714eaf45c2dc544be5cb709b51220d9ca8ea5e8ea62c05844670432751eb2ee8
BLAKE2b-256 checksum
How to use checksums
eda63ebf2e72c1511c73c5e4c2dcdb5607f7a0ea148862780775ff463fcc4916
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.9

Release files / shellcheck_gha-0.1.2-py3-none-any.whl

Download URL shellcheck_gha-0.1.2-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6fcd645a34ba35801f00e0885ef0dc44adc36848c3b2a52c3fdf90bd05e5aac4
BLAKE2b-256 checksum
How to use checksums
2546fb8263215f03fba2d33843b9f773b8c663f346101f77dd1b29bf721ae49c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page