Skip to content

Conversation

@YanxuanLiu
Copy link
Collaborator

@YanxuanLiu YanxuanLiu commented Jul 10, 2025

fix #41

Use bash -n and shellcheck to check shell script syntax.

bash -n

This is a built-in Bash option that performs a syntax check without executing the script.

It only verifies if the script’s syntax is correct.

It does not detect logical errors, unsafe practices, or style issues.

shellcheck

shellcheck is a dedicated static analysis tool for shell scripts.

It checks for syntax errors and detects logical mistakes, potential bugs, unsafe code patterns, and style inconsistencies.

Provides detailed warnings and suggestions to improve code quality, security, and portability.

Supports multiple shell dialects including Bash, sh, and others.

Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
@pxLi pxLi requested a review from Copilot July 11, 2025 05:52

This comment was marked as outdated.

fetch-depth: ${{ env.PR_FETCH_DEPTH }}

- name: shell-check
uses: YanxuanLiu/spark-rapids-common/shell-check@shellcheck
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use nvidia repo instead of the personal one

# Get changed files
BASE_REF=$(git --no-pager log --oneline -1 | awk '{ print $NF }')
echo "Base REF: ${BASE_REF}"
FILES=$(git diff --name-only --diff-filter=AM ${BASE_REF} HEAD) || (echo "Your base commit ID is too old, please try upmerge first." && exit 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please help explain why there will be an issue of 'base commit ID is too old',

This error is a little odd, so long as the PR can be submitted, there should not be such issue?

Another concern, we may only D(elete) files in a PR, but not A(dd) or M(odify) anything, then we should also not error out here, right?

@pxLi
Copy link
Member

pxLi commented Jul 11, 2025

Discussed offline, let's try to use the existing action if possible https://github.com/marketplace/actions/shellcheck

Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
@YanxuanLiu
Copy link
Collaborator Author

Tested with existing shellcheck action https://github.com/YanxuanLiu/spark-rapids-common/actions/runs/16281763725/job/45972660835.

The action is actually based on shellcheck tool, so the result is same as using shellcheck directly, but in better readability. It can report most syntax errors in test script .

One limitation is that it cannot detect [[ ... ]] issues, like if [[ "IS_SPARK_35X" -ne "1" ]]; then

@YanxuanLiu YanxuanLiu marked this pull request as ready for review July 16, 2025 04:11
@YanxuanLiu YanxuanLiu requested a review from a team as a code owner July 16, 2025 04:11
@YanxuanLiu YanxuanLiu marked this pull request as draft July 16, 2025 04:13
pxLi
pxLi previously approved these changes Jul 16, 2025
Signed-off-by: Yanxuan Liu <[email protected]>
Signed-off-by: Yanxuan Liu <[email protected]>
@YanxuanLiu YanxuanLiu marked this pull request as ready for review July 16, 2025 04:37
@pxLi pxLi requested a review from Copilot July 16, 2025 04:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a GitHub Actions workflow to automatically check shell script syntax and quality using both bash -n for syntax validation and shellcheck for comprehensive static analysis. The workflow aims to improve code quality by catching shell script issues early in the development process.

Key changes:

  • Introduces automated shell script checking on pull requests
  • Uses industry-standard tools for syntax and quality validation
  • Configures appropriate PR event triggers and bot exclusions

@pxLi
Copy link
Member

pxLi commented Jul 16, 2025

Going to merge this one first.

Please help update other repos and fix the existing issues if any in the same change thanks

@pxLi pxLi merged commit 372245a into NVIDIA:main Jul 16, 2025
3 checks passed
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

Successfully merging this pull request may close these issues.

[FEA] shared shellcheck action/workflow

3 participants