Skip to content

Commit

Permalink
Merge pull request #67 from Azbagheri/release/0.7.0
Browse files Browse the repository at this point in the history
Release/0.7.0
  • Loading branch information
Azbagheri authored Feb 22, 2025
2 parents 6bbeaa8 + db82535 commit dd911b0
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/BUG_REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ about: Report a bug or something that is not working as expected

## New Issue Checklist

- [ ] Using the latest version of azohra/shell-linter
- [ ] Using the latest version of Azbagheri/shell-linter
- [ ] Able to reproduce error multiple times
- [ ] Provided information about the bug
- [ ] Attached additional information about the error including logs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI-workflow
name: CI Pipeline

on:
pull_request:
Expand All @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Install Shellcheck
run: ./src/install_shellcheck.sh
- name: Run tests
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ on:
push:
branches:
- master

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

- name: Get version
id: app-version
run: echo ::set-output name=VERSION::$(./docs/version)
run: echo ::set-output name=VERSION::$(./src/version)

- name: Tag commit and release
- name: Create tag and release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.app-version.outputs.VERSION }}
commit: master
name: Shell Linter ${{ steps.app-version.outputs.VERSION }}
bodyFile: ./docs/release_notes/v0.6.0.md
bodyFile: ./docs/release_notes/v0.7.0.md

- name: Update latest tag
run: ./src/tagging.sh ${{ secrets.GITHUB_TOKEN }}
Expand Down
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM alpine:3.13.6
ARG SHELLCHECK_VERSION=v0.10.0
FROM koalaman/shellcheck:${SHELLCHECK_VERSION} AS builder

RUN apk update && apk add --no-cache bash
RUN bash --version
FROM alpine:3.20.3

COPY ./src/install_shellcheck.sh ./install_shellcheck.sh
RUN ./install_shellcheck.sh
COPY --from=builder /bin/shellcheck /usr/local/bin/

RUN apk update && apk add --no-cache bash && \
shellcheck --version && \
bash --version

COPY entrypoint.sh /entrypoint.sh

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Azohra
Copyright (c) 2025 Azadeh Bagheri

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
67 changes: 43 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# Shell Linter

[![Release](https://img.shields.io/github/release/azohra/shell-linter.svg)](https://github.com/azohra/shell-linter/releases)
[![Release](https://img.shields.io/github/release/Azbagheri/shell-linter.svg)](https://github.com/Azbagheri/shell-linter/releases)
[![Marketplace](https://img.shields.io/badge/GitHub-Marketplace-red.svg)](https://github.com/marketplace/actions/shell-linter)
[![Actions Status](https://github.com/azohra/shell-linter/workflows/CI-workflow/badge.svg)](https://github.com/azohra/shell-linter/actions?query=branch%3Adevelop)
<!--[![Actions Status](https://github.com/Azbagheri/shell-linter/workflows/CI-workflow/badge.svg)](https://github.com/Azbagheri/shell-linter/actions?query=branch%3Adevelop)-->


A GitHub Action that performs static analysis for shell scripts using [ShellCheck](https://github.com/koalaman/shellcheck).

![](docs/images/preview.png)

## 🚨 Repository Transferred – Manual Update Required

This repository has moved from **`azohra/shell-linter`** to **`Azbagheri/shell-linter`**.

**Important:** Contrary to our understanding, GitHub is NOT automatically redirecting workflows. You must manually update your YAML configuration:

```diff
- uses: azohra/shell-linter@latest
+ uses: Azbagheri/shell-linter@latest
```

We sincerely apologize for any inconvenience this has caused.
<br>

# Usage

Shell Linter can perform static analysis in various ways. By default it scans all the Shellcheck-supported shell scripts (sh/bash/dash/ksh) in your project. However, you can use the `path` parameter to scan a specific file or folder or use the `exclude-paths` parameter to exclude files or folders from the scan. With Shell Linter, you can also specify the minimum severity of errors to consider using the `severity` parameter. Specific use cases along with examples are shown below:
Shell Linter can perform static analysis in various ways. By default it scans all the ShellCheck-supported shell scripts (sh/bash/dash/ksh) in your project. However, you can use the `path` parameter to scan a specific file or folder or use the `exclude-paths` parameter to exclude files or folders from the scan. With Shell Linter, you can also specify the minimum severity of errors to consider using the `severity` parameter. Specific use cases along with examples are shown below:

#### Run static analysis for all the supported shell scripts in your repository:
```yml
Expand All @@ -22,77 +34,84 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
- uses: actions/checkout@v1
- name: Run Shellcheck
uses: azohra/shell-linter@latest
uses: actions/checkout@v4
- name: Run ShellCheck
uses: Azbagheri/shell-linter@latest
```
#### Run static analysis for a single shell script:
```yml
- name: Run Shellcheck
uses: azohra/shell-linter@latest
- name: Run ShellCheck
uses: Azbagheri/shell-linter@latest
with:
path: "setup.sh"
```
#### Run static analysis for multiple shell scripts **with or without** extension:
```yml
- name: Run Shellcheck
uses: azohra/shell-linter@latest
- name: Run ShellCheck
uses: Azbagheri/shell-linter@latest
with:
path: "setup,deploy.sh"
```
#### Run static analysis for all the shell scripts in a folder:
```yml
- name: Run Shellcheck
uses: azohra/shell-linter@latest
- name: Run ShellCheck
uses: Azbagheri/shell-linter@latest
with:
path: "src"
```
#### Run static analysis using a **wildcard** path:
```yml
- name: Run Shellcheck
uses: azohra/shell-linter@latest
- name: Run ShellCheck
uses: Azbagheri/shell-linter@latest
with:
path: "src/*.sh"
```
#### Exclude files and folders from the static analysis:
```yml
- name: Run Shellcheck
uses: azohra/shell-linter@latest
- name: Run ShellCheck
uses: Azbagheri/shell-linter@latest
with:
exclude-paths: "src/setup.sh,tests/unit_tests"
```
Note that `exclude-paths` only accepts paths relative to your project's root directory. However, **do not** include `./` at the beginning of the paths.

To exclude a folder and it's content recursively just provide the path of the folder **without** a `/` at the end. In the example above, the entire folder at the path `tests/unit_tests` will be excluded from linting.

#### Run static analysis for all the shell scripts and only report issue with error severity:
#### Run static analysis for all the shell scripts and only report issues with error severity while excluding specific issues:
```yml
- name: Run Shellcheck
uses: azohra/shell-linter@latest
- name: Run ShellCheck
uses: Azbagheri/shell-linter@latest
with:
path: "src/*.sh"
severity: "error"
exclude-issues: "SC1068,SC1066"
```
Note that `exclude-issues` contains a comma-separated list of ShellCheck issues (example: "SC1068") to ignore.

#### Run analysis by using a specific version of Shell Linter:
```yml
- name: Run Shellcheck
uses: azohra/shell-linter@v0.5.0
- name: Run ShellCheck
uses: Azbagheri/shell-linter@v0.7.0
```

# Input

### `path`
Optional. Execute lint check on a specific file or folder. Default: `.`
### `exclude-issues`
Optional. Specify shellcheck issues to exclude during scan. For more information refer to [Checks](https://github.com/koalaman/shellcheck/wiki/Checks). Default: scan all issues.

### `exclude-paths`
Optional. Exclude files and folders from Shellcheck scan.
Optional. Exclude files and folders from ShellCheck scan.

### `path`
Optional. Execute lint check on a specific file or folder. Default: `.`

### `severity`
Optional. Specify minimum severity of errors to consider [style, info, warning, error]. Default: `style`

# License
This software is available as open source under the terms of the MIT License.

8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'Shell Linter'
description: 'Execute lint check on shell scripts using ShellCheck'
author: 'ep-mobile'
author: 'Azadeh Bagheri'
inputs:
path:
description: 'Execute lint check on a specific file or folder.'
Expand All @@ -14,14 +14,18 @@ inputs:
description: 'Specify files or folders to exclude during scan.'
required: false
default: ''

exclude-issues:
description: 'Specify shellcheck issues to exclude during scan.'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.path }}
- ${{ inputs.severity }}
- ${{ inputs.exclude-paths}}
- ${{ inputs.exclude-issues }}
branding:
icon: 'check-circle'
color: 'green'
Expand Down
7 changes: 7 additions & 0 deletions docs/release_notes/v0.7.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## New Features and Improvements
- Added support for excluding specific ShellCheck issues from static analysis, allowing users to suppress warnings or errors that are not relevant to their workflow.
- Improved the Shellcheck's installation process by pulling the binary from its official Docker image using a multi-stage build.

## Ownership Change Notice:

This is the first release after the ownership of this repository has changed. For important updates and instructions, please refer to the README file. If you have any questions or concerns regarding the action, feel free to open an issue. Thank you for your continued support!
12 changes: 9 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
input_paths="$1"
severity_mode="$2"
exclude_paths="$3"
execution_mode="$4"
exclude_issues="$4"
execution_mode="$5"
my_dir=$(pwd)
status_code="0"
find_path_clauses=(! -path "${my_dir}/.git/*")
Expand All @@ -31,6 +32,11 @@ process_input(){
done
fi

optional_params=""
if [[ -n "$exclude_issues" ]]; then
optional_params="--exclude $exclude_issues"
fi

if [[ -n "$input_paths" && "$input_paths" != "." ]]; then
for path in $(echo "$input_paths" | tr "," "\n"); do
if [ -d "$path" ]; then
Expand Down Expand Up @@ -58,7 +64,7 @@ scan_file(){
echo "###############################################"
echo " Scanning $file"
echo "###############################################"
shellcheck -x "$file_path" --severity="$severity_mode"
shellcheck -x "$file_path" --severity="$severity_mode" $optional_params
local exit_code=$?
if [ $exit_code -eq 0 ] ; then
printf "%b" "Successfully scanned ${file_path} 🙌\n"
Expand Down Expand Up @@ -91,7 +97,7 @@ log_invalid_files(){
printf "\n\t\e[33m %s \e[0m\n" "$file"
done
printf "\n\e[33m ShellCheck only supports sh/bash/dash/ksh scripts. For supported scripts to be scanned, make sure to add a proper shebang on the first line of the script.\n\n To fix the warning for the unsupported scripts or to ignore specific files, use the 'exclude-paths' input. For more information check:
https://github.com/azohra/shell-linter#input\e[0m\n"
https://github.com/Azbagheri/shell-linter#input\e[0m\n"
}

# To avoid execution when sourcing this script for testing
Expand Down
2 changes: 1 addition & 1 deletion src/install_shellcheck.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

scversion='v0.7.2'
scversion='v0.10.0'

wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv
cp "shellcheck-${scversion}/shellcheck" /usr/local/bin
Expand Down
2 changes: 1 addition & 1 deletion src/tagging.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash

token=$1
repo_owner="azohra"
repo_owner="Azbagheri"
repo_name="shell-linter"
tag_name="latest"
commit_sha=$(git log -n1 --format=format:"%H")
Expand Down
2 changes: 1 addition & 1 deletion docs/version → src/version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash

VERSION="v0.6.0"
VERSION="v0.7.0"
echo $VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

var=World; echo "Hello "
echo "$(date)"

$foo=42
3 changes: 3 additions & 0 deletions test_data/exclude_issues/test_script_exclude_none.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

echo "Hello $name"
3 changes: 3 additions & 0 deletions test_data/exclude_issues/test_script_exclude_one_error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
var = 42
echo -n 42
37 changes: 37 additions & 0 deletions tests/integration_tests/exclude_issues_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /bin/bash

source ./entrypoint.sh "" "" "" "" "--test"

test_exclude_no_error(){
input_paths="./test_data/exclude_issues/test_script_exclude_none.sh"
severity_mode="style"
exclude_issues=""
local expected_error="SC2154"
local actual_message=$(process_input)

assertContains "Actual messages:$actual_message Did not find the message.\n" "$actual_message" "$expected_error"
}

test_exclude_one_error(){
input_paths="./test_data/exclude_issues/test_script_exclude_one_error.sh"
severity_mode="style"
exclude_issues="SC2283"
local expected_error="SC3037"
local not_expected_error="SC2283"
local actual_message=$(process_input)

assertContains "Actual messages:$actual_message Did not find the message.\n" "$actual_message" "$expected_error"
assertNotContains "Actual messages:$actual_message contains the message.\n" "$actual_message" "$not_expected_error"
}

test_exclude_multiple_errors(){
input_paths="./test_data/exclude_issues/test_script_exclude_multiple_errors.sh"
severity_mode="style"
exclude_issues="SC1017,SC2281,SC2034,SC2154,SC2005"
local expected_message="Successfully scanned"
local actual_message=$(process_input)

assertContains "Actual messages:$actual_message Did not find the message.\n" "$actual_message" "$expected_message"
}

source ./tests/shunit2
2 changes: 1 addition & 1 deletion tests/integration_tests/ignored_path_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash
# shellcheck disable=SC2155

source ./entrypoint.sh "" "" "" "--test"
source ./entrypoint.sh "" "" "" "" "--test"

test_ignore_directories(){
local exclude_paths="test_dir,severity_mode"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/input_path_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/bash
# shellcheck disable=SC2155

source ./entrypoint.sh "" "" "" "--test"
source ./entrypoint.sh "" "" "" "" "--test"

test_execution_mode(){
local expected_path=./test_data
Expand Down
Loading

0 comments on commit dd911b0

Please # to comment.