diff --git a/.github/actions/shellcheck/action.yml b/.github/actions/shellcheck/action.yml deleted file mode 100644 index 8a3ff7db..00000000 --- a/.github/actions/shellcheck/action.yml +++ /dev/null @@ -1,64 +0,0 @@ -# This is a reusable action for running ShellCheck, -# a linter for shell scripts (https://shellcheck.net). - -# For more context, see: -# https://github.com/openedx/.github/blob/master/docs/decisions/0001-shellcheck.rst - -name: ShellCheck - -# For details on each of these input arguments, see: -# ../../../workflow-templates/shellcheck.yml -# which invokes this action. -inputs: - - root-dirs: - reqired: true - - shellcheck-version: - required: false - default: "v0.9.0" - - shellcheck-options: - required: false - default: "" - -runs: - - using: composite - - # Note: Unfortunately, GitHub will not print the names of steps in - # composite actions, so we must rely on comments and echo'ing to - # make it clear to the user what's going on on. - steps: - - - shell: bash - run: | - # Download, unpack & install ShellCheck ${{ inputs.shellcheck-version }}. - wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${{ inputs.shellcheck-version }}/shellcheck-${{ inputs.shellcheck-version }}.linux.x86_64.tar.xz" | tar -xJ - sudo cp "shellcheck-${{ inputs.shellcheck-version }}/shellcheck" /usr/bin - echo "Successfully installed:" - shellcheck -V - echo - - - shell: bash - run: | - # Ensure that at least one shell script will be checked & print helpful info - if [[ -z "$(find ${{ inputs.root-dirs }} -name '*.sh')" ]] ; then - echo "::error::Error: No .sh files found within any of the root-dirs: ${{ inputs.root-dirs }}" - exit 1 - fi - echo "The following shell scripts will be checked:" - find ${{ inputs.root-dirs }} -name '*.sh' - echo - echo "If ShellCheck passes, the next step will have no output." - echo "If ShellCheck fails, you should see a list of violations." - echo "Each violation type has an SCXXXX code which can be looked up at https://www.shellcheck.net/wiki/SCXXXX" - echo "We recommend that you try to resolve any violations." - echo "In the case where resolving the violation doesn't make sense, you can use directives (https://www.shellcheck.net/wiki/Directive) to ignore a single violation instance or an entire shell script." - echo - - # This step is intentionally a big one-line command so that - # devs can easily copy it and run it on their own machine. - - shell: bash - run: find ${{ inputs.root-dirs }} -name '*.sh' -print0 | xargs -0 shellcheck ${{ inputs.shellcheck-options }} - diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 00000000..bbc735ec --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,83 @@ +# This is a reusable workflow for running ShellCheck, +# a linter for shell scripts (https://shellcheck.net). + +# For more context, see: +# https://github.com/openedx/.github/blob/master/docs/decisions/0001-shellcheck.rst + +name: ShellCheck + +on: + workflow_call: + inputs: + + root-dirs: + type: string + required: true + description: | + Directories to search for .sh files, space-separated, each relative + to the root of the repository. Directories containing spaces or other + Bash delimiters must be wrapped in single quotes. + + shellcheck-version: + type: string + required: false + default: "v0.9.0" + description: + ShellCheck version to install. + Must be a tag or branch of https://github.com/koalaman/shellcheck. + By default, the upstream action will use a reasonable, stable shellcheck version, + which will be updated over time as new stable ShellCheck versions come out. + If you want your repositoriy's build to be totally deterministic, though, then + override with a specific version pin here, and manage updates ShellCheck yourself. + + # OPTIONAL: + shellcheck-options: + type: string + required: false + default: "" + description: | + Command-line options to forward to shellcheck. + For details of available options, run "shellcheck --help." + +jobs: + shellcheck: + runs-on: ubuntu-latest + + steps: + + - name: Download & unpack ShellCheck + wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${{ inputs.shellcheck-version }}/shellcheck-${{ inputs.shellcheck-version }}.linux.x86_64.tar.xz" | tar -xJ + + - name: Install ShellCheck + run: sudo cp "shellcheck-${{ inputs.shellcheck-version }}/shellcheck" /usr/bin + + - name: Show ShellCheck version + run: shellcheck -V + + - name: Check out repository branch + uses: actions/checkout@v3 + + - name: Ensure that at least one script will be checked + run: | + if [[ -z "$(find ${{ inputs.root-dirs }} -name '*.sh')" ]] ; then + echo "::error::Error: No .sh files found within any of the root-dirs: ${{ inputs.root-dirs }}" + exit 1 + fi + + - name: Print helpful information + run: | + echo "The following shell scripts will be checked:" + find ${{ inputs.root-dirs }} -name '*.sh' + echo + echo "If ShellCheck passes, the next step will have no output." + echo "If ShellCheck fails, you should see a list of violations." + echo "Each violation type has an SCXXXX code which can be looked up at https://www.shellcheck.net/wiki/SCXXXX" + echo "We recommend that you try to resolve any violations." + echo "In the case where resolving the violation doesn't make sense, you can use directives (https://www.shellcheck.net/wiki/Directive) to ignore a single violation instance or an entire shell script." + echo + + # This step is intentionally a big one-line command so that + # devs can easily copy it and run it on their own machine. + - name: Run ShellCheck + run: find ${{ inputs.root-dirs }} -name '*.sh' -print0 | xargs -0 shellcheck ${{ inputs.shellcheck-options }} +