Skip to content

feat: provide option to run only on provided list of files (such as changed-files output) #115

@eripa

Description

@eripa

Checklist

  • This Feature Request only contains 1 request (if you have multiple open multiple feature requests).

The idea

I want to enable the shellcheck action on a repository that has many many scripts of varying quality. So I am trying to build a workflow that is using the changed-files action to gather only files that this change touches, and run shellcheck on those.

      - name: Get changed shell scripts
        id: changed-files
        uses: tj-actions/changed-files@v46
        with:
          files: |
            **/*.sh

Would it be possible to allow this action to take the input of the changed-files action and use that as the source for shellcheck?

Implementation

Something like:

- name: Run shellcheck on changed files
  uses: ludeeus/action-shellcheck@master
  with:
   only_files: ${{ steps.changed-files.outputs.all_changed_files }}

I could see that you might want to still respect the ignore options.

Alternatives

This is what I currently do as a workaround:

      - name: Copy changed scripts into a clean directory
        run: |
          set -euo pipefail
          mkdir -p changed-scripts
          echo "${{ steps.changed-files.outputs.all_changed_files }}" \
            | tr ' ' '\n' \
            | while read -r file; do
                [ -f "$file" ] || continue
                cp --parents "$file" changed-scripts/
              done

      - name: Run ShellCheck on only those scripts
        uses: ludeeus/action-shellcheck@master
        with:
          scandir: changed-scripts

The problem here is that the output/file dir doesn't match the actual source, so it shows changed-scripts/.. instead of the actual location.

It also makes the action setup a bit clunky.

ShellCheck - shell script analysis tool
version: 0.10.0
license: GNU General Public License, version 3
website: https://www.shellcheck.net
Run declare -a options
Run declare -a excludes
Run declare -a files
Run statuscode=0
changed-scripts/util/my-script.sh:3:8: note: Not following: ./deprecated.sh was not specified as input (see shellcheck -x). [SC1091]
changed-scripts/util/my-script.sh:21:41: note: Double quote to prevent globbing and word splitting. [SC2086]
changed-scripts/util/my-script.sh:24:13: warning: Quote this to prevent word splitting. [SC2046]
changed-scripts/util/my-script.sh:27:20: note: Double quote to prevent globbing and word splitting. [SC2086]
changed-scripts/util/my-script.sh:30:16: note: Double quote to prevent globbing and word splitting. [SC2086]
changed-scripts/util/my-script.sh:31:14: warning: Quote this to prevent word splitting. [SC2046]
Run exit 1
Error: Process completed with exit code 1.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions