Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shellcheck across RAPIDS #135

Open
25 tasks
gforsyth opened this issue Jan 16, 2025 · 4 comments
Open
25 tasks

Add shellcheck across RAPIDS #135

gforsyth opened this issue Jan 16, 2025 · 4 comments

Comments

@gforsyth
Copy link

gforsyth commented Jan 16, 2025

Description

shellcheck is a fast, static analysis tool for shell scripts. It's good at
flagging up unused variables, unintentional glob expansions, and other potential
execution and security headaches that arise from the wonders of bash (and other shlangs).

https://www.shellcheck.net/

Any shell script that is running in CI in a RAPIDS repo should be passing shellcheck.

Benefits of this work

  • Fewer chances for shell-scripts to go sideways, or for shell scripts that
    complete to be conflated with shell scripts that have executed correctly.
  • Reduction in manual review for the build team of new shell scripts or updated
    shell scripts in PRs, automating "linty" PR suggestions.

Notes

For the initial scope, I propose that we only run shellcheck on scripts in the
ci/ directory, or on any scripts that are called in GHA.

There are some repos with a lot of shell-scripts more related to local
build-process, and these are less critical to "get right" (although that can be
done incrementally in the future).

Further, making several small tweaks to existing local build scripts across
these packages may break things in subtle ways, so it's better to have buy-in
from project maintainers before delving too deeply beyond ci/

Acceptance Criteria

  • shellcheck is run in CI against the ci/ directory in all RAPIDS repos that have shell scripts
  • All shell scripts in-scope pass shellcheck or have explicit (individual)
    exceptions noted. (No blanket exemptions)

Approach

These repos can be updated in any order, since these updates are all self-contained.

The goal is to have each repo running shellcheck in GHA, similar to https://github.com/rapidsai/gha-tools/blob/main/.github/workflows/prs.yaml#L20-L24

Tasks

Preview Give feedback
@gforsyth gforsyth changed the title Add ~shellcheck~ across ~RAPIDS~ Add shellcheck across RAPIDS Jan 16, 2025
@jameslamb
Copy link
Member

jameslamb commented Jan 16, 2025

Hey thanks for putting this up! I totally support it.

But instead of invoking a separate GitHub action, I think we should do this via the shellcheck-py pre-commit hook.

repos:
  - repo: https://github.com/shellcheck-py/shellcheck-py
    rev: v0.10.0.1
    hooks:
      - id: shellcheck

I've been sprinkling that around some repos for the last couple months and have found it works great... lightweight to install, runs fast, exactly matches the behavior of other shellcheck packages like those from conda-forge or Homebrew.

For example:

https://github.com/rapidsai/deployment/blob/65e6acf22b7ade745c8822bda76bc535e4b53857/.pre-commit-config.yaml#L28

https://github.com/rapidsai/legate-boost/blob/b9462f8d77c2540ba44393bc04b9f75ad3103d9a/.pre-commit-config.yaml#L10-L13

Doing that via pre-commit means you can get local feedback instead of needing to wait for a CI run.

@gforsyth
Copy link
Author

Sounds good to me -- do we also run pre-commit in CI to ensure files are compliant?

@jameslamb
Copy link
Member

Yep!

By convention, every RAPIDS project uses a workflow called checks:

  checks:
    secrets: inherit
    needs: telemetry-setup
    uses: rapidsai/shared-workflows/.github/workflows/[email protected]
    with:
      enable_check_generated_files: false
      ignored_pr_jobs: "telemetry-summarize"

(example from cudf)

Which looks for a script named ci/check_style.sh (code link in rapidsai/shared-workflows). (a bit of a misnomer because lots of static analysis catches more than just style, like correctness, efficiency, deprecations, etc., but anyway....)

Most repos then have content in that check_style.sh that runs pre-commit run --all-files (example from cudf).

So that all happens by convention but you can generally safely assume that every RAPIDS repo is running pre-commit run --all-files on every pull request.

@gforsyth
Copy link
Author

I pushed up an example commit of what this might look like here for rmm: gforsyth/rmm@02f9758

rapids-bot bot pushed a commit to rapidsai/dask-cuda that referenced this issue Jan 22, 2025
shellcheck  is a fast, static analysis tool for shell scripts. It's good at                                  
flagging up unused variables, unintentional glob expansions, and other potential                              
execution and security headaches that arise from the wonders of  bash  (and other shlangs).                   
                                                                                                              
This PR adds a  pre-commit  hook to run  shellcheck  on all of the  sh-lang  files in the  ci/  directory, and
the changes requested by  shellcheck  to make the existing files pass the check.                              
                                                                                                              
xref: rapidsai/build-planning#135

Authors:
  - Gil Forsyth (https://github.com/gforsyth)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Peter Andreas Entschev (https://github.com/pentschev)

URL: #1427
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants