diff --git a/.github/actions/shellcheck/action.yml b/.github/actions/shellcheck/action.yml new file mode 100644 index 00000000..6005947e --- /dev/null +++ b/.github/actions/shellcheck/action.yml @@ -0,0 +1,61 @@ +# 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 + +inputs: + + root-dirs: + description: "Directories to search for .sh files, space-separated." + reqired: true + + # We pin a reasonable default version here and will update it over time. + # However, repositories that are particuarly concerned about + # build stability should specify an override shellcheck-version + # and manage updates themselves. + shellcheck-version: + description: "ShellCheck version to install.Must be a tag or branch of https://github.com/koalaman/shellcheck." + required: false + default: "v0.9.0" + + shellcheck-options: + description: "Command-line options to pass through to shellcheck." + 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 + 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 + + # 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 deleted file mode 100644 index d0b6f6b2..00000000 --- a/.github/workflows/shellcheck.yml +++ /dev/null @@ -1,61 +0,0 @@ -# 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 - -defaults: - run: - shell: bash - -permissions: - contents: read - -# Repositories can provide overrides to these environment variables. -env: - - # ShellCheck version to install. - # Must be a tag or branch of https://github.com/koalaman/shellcheck. - # We pin a reasonable version here and will update it over time. - # However, repositories that are particuarly concerned about - # build stability should specify an override SHELLCHECK_VERSION - # and manage updates themselves. - SHELLCHECK_VERSION: "v0.9.0" - - # List of directories to check for .sh files, space-separated. - SHELLCHECK_ROOT_DIRS: "./scripts ./.github" - - # Options to pass to the shellcheck command. - SHELLCHECK_OPTIONS: "" - -jobs: - - shellcheck: - name: Run ShellCheck - runs-on: ubuntu-latest - - steps: - - - name: Download & unpack ShellCheck - run: wget -qO- "https://github.com/koalaman/shellcheck/releases/download/$SHELLCHECK_VERSION/shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz" | tar -xJv - - - name: Install ShellCheck - run: sudo cp "shellcheck-$SHELLCHECK_VERSION/shellcheck" /usr/bin - - - name: Show ShellCheck version - run: shellcheck -V - - - name: Check out repository branch - uses: actions/checkout@v3 - - - name: Show shell scripts that will be checked - run: find $SHELLCHECK_ROOT_DIRS -name '*.sh' - - - name: Check shell scripts - run: find $SHELLCHECK_ROOT_DIRS -name '*.sh' -print0 | xargs -0 shellcheck $SHELLCHECK_OPTIONS - diff --git a/workflow-templates/shellcheck.yml b/workflow-templates/shellcheck.yml index 218f3183..49145735 100644 --- a/workflow-templates/shellcheck.yml +++ b/workflow-templates/shellcheck.yml @@ -1,9 +1,8 @@ -# Run ShellCheck on PRs and $default-branch. +# Run ShellCheck on PRs and $default-branch # For more context, see: # https://github.com/openedx/.github/blob/master/docs/decisions/0001-shellcheck.rst - name: ShellCheck on: @@ -12,13 +11,30 @@ on: branches: - $default-branch +permissions: + contents: read + jobs: shellcheck: - # Call out to our predefined ShellCheck workflow. - uses: openedx/.github/.github/workflows/shellcheck.yml@master - env: - # The following environment variables can be used to configure - # the shared ShellCheck workflow: - #SHELLCHECK_VERSION: "v0.9.0" - #SHELLCHECK_ROOT_DIRS: "./scripts ./.github" - #SHELLCHECK_OPTIONS: "" + runs-on: ubuntu-latest + steps: + + - name: Check out this repository + uses: actions/checkout@v3 + + - name: Check out shared actions + uses: actions/checkout@v3 + with: + repository: openedx/.github + path: ./openedx-dot-github + + - name: Run ShellCheck! + uses: ./openedx-dot-github/.github/actions/shellcheck + with: + + # Required arguments for the ShellCheck action: + root-dirs: "./scripts ./.github" + + # Optional arguments: + #shellcheck-version: "v0.9.0" + #shellcheck-options: ""