0

My requirement is to iterate through checked in files in a loop and perform the action:

My GitHub Actions workflow is:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: checkout repo content
        uses: actions/checkout@v2
        with:
          fetch-depth: 2
         
      - name: identify different Configuration files
        run: |
          echo "Check-in configuration files are"
          files=$(git diff --name-only HEAD^..HEAD)
          echo $files
          echo "Stating exeuction"
          IFS=" "
          for i in $files
          do
            echo Hiiii
            echo $i
            echo Byeee
          done

However, it is returning output like:

Check-in configuration files are
.github/workflows/model_registry.yml config/approve/apprv_xgboost_model.ini config/register/modoel-1.ini config/update/updt_model-2.ini
Stating exeuction
Hiiii
.github/workflows/model_registry.yml
config/approve/apprv_xgboost_model.ini
config/register/model-1.ini
config/update/updt_model-2.ini
Byeee

Same command when I am executing in git bash:

$ files=".github/workflows/model_registry.yml config/approve/apprv_xgboost_model.ini config/register/model-1.ini config/update/updt_model-2.ini"

$ IFS=" "
$ for i in $files
> do
>   echo Hiiii
>   echo $i
>   echo byeee
> done
Hiiii
.github/workflows/model_registry.yml
byeee
Hiiii
config/approve/apprv_xgboost_model.ini
byeee
Hiiii
config/register/model-1.ini
byeee
Hiiii
config/update/updt_model-2.ini
byeee
Azeem
  • 11,148
  • 4
  • 27
  • 40
Karki
  • 7
  • 4
  • In your local testing, you are using a hardcoded string instead of using the `git diff` command. You should use the same steps and then compare both. – Azeem Mar 03 '23 at 04:51
  • Relevant: https://stackoverflow.com/questions/9293887/reading-a-space-delimited-string-into-an-array-in-bash – Azeem Mar 03 '23 at 04:52

1 Answers1

0

Looks like the issue might be how shell interprets the command. In github action code seems like the entire list of file names is being treated as single string instead of individual file names.

Try using double quotes.

for i in "$files"

This shoud make sure each file name behaves separately to the loop.

Rogg
  • 1
  • I tried this approach however this is also not working: - name: identify different Configuration files run: | echo "Check-in configuration files are" files=$(git diff --name-only HEAD^..HEAD) echo $files echo "Stating exeuction" IFS=" " for i in "$files" do echo Hiiii echo $i echo Byeee done This gave me exact same output as before. – Karki Mar 03 '23 at 08:52