From 5987d0d80879b0a88a38b8913becc0095785ac4c Mon Sep 17 00:00:00 2001 From: JEEVITHA KANNAN K S Date: Fri, 1 Nov 2024 22:51:49 +0530 Subject: [PATCH] refact(ci): bashisms.yml (#793) * Refact bashisms.yml * Update bashisms.yml --- .github/workflows/bashisms.yml | 52 ++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/.github/workflows/bashisms.yml b/.github/workflows/bashisms.yml index 7ce39ef1..ffbe983b 100644 --- a/.github/workflows/bashisms.yml +++ b/.github/workflows/bashisms.yml @@ -3,7 +3,7 @@ name: Check for bashisms on: pull_request: paths: - - core/tabs/** + - 'core/tabs/**/*.sh' merge_group: workflow_dispatch: @@ -15,31 +15,33 @@ jobs: - uses: actions/checkout@v4 - run: git fetch origin ${{ github.base_ref }} - - name: Get a list of changed script files - id: get_sh_files - run: | - sh_files=$(git diff --name-only origin/${{ github.base_ref }} HEAD core/tabs | grep '\.sh$' || true) - if [ -n "$sh_files" ]; then - echo "$sh_files" > changed_files - echo "changed=1" >> $GITHUB_OUTPUT - else - echo "changed=0" >> $GITHUB_OUTPUT - fi - - name: Install devscripts - if: steps.get_sh_files.outputs.changed == 1 - run: sudo apt-get update && sudo apt-get install devscripts + run: sudo apt-get update && sudo apt-get install -y devscripts + + - name: Get changed .sh files (PR only) + id: changed-sh-files + if: github.event_name == 'pull_request' + uses: tj-actions/changed-files@v45 + with: + files: '**/*.sh' + + - name: Get all .sh files (if workflow dispatched) + id: sh-files + if: github.event_name != 'pull_request' + run: | + files=$(find . -type f -name "*.sh" | tr '\n' ' ') + echo "files=${files:-none}" >> $GITHUB_ENV + + - name: Set FILES for bashism check + id: set-files + run: | + if [[ "${{ steps.changed-sh-files.outputs.any_changed }}" == 'true' ]]; then + echo "FILES=${{ steps.changed-sh-files.outputs.all_changed_files }}" >> $GITHUB_ENV + else + echo "FILES=${{ env.files }}" >> $GITHUB_ENV + fi - name: Check for bashisms - if: steps.get_sh_files.outputs.changed == 1 run: | - echo "Running for:\n$(cat changed_files)\n" - for file in $(cat changed_files); do - if [[ -f "$file" ]]; then - checkbashisms "$file" - fi - done - - - name: Remove the created file - if: steps.get_sh_files.outputs.changed == 1 - run: rm changed_files + IFS=' ' read -r -a file_array <<< "$FILES" + checkbashisms "${file_array[@]}"