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
2
  • 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. Commented Mar 3, 2023 at 4:51
  • Relevant: stackoverflow.com/questions/9293887/… Commented Mar 3, 2023 at 4:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.