Creating a while loop in workflow

I am trying to work out a basic ping-pong exchange between two boxes created from a single workflow. In each case I use @haythem public IP action, output the IP to a artifact and then import the other box’s artifact. I am getting both files and I used a simple file listing to show that both files are in place. The problem is that I have a race condition where one box may not finish writing before the other one starts reading. I need to use a while loop to act as a semaphore and wait for the other box to finish writing. I would check for the availability of the file and then both boxes could use the IPs to communicate. I’m not aware of any YML syntax that allows me to do this.

Possible solutions:
Option 1 - I need a while loop syntax example.
Option 2 - I’d like a better example for setting this up.

secondBox:
   runs-on: ubuntu-latest
   steps:
     - name: Public IP
       id: ip
       uses: haythem/public-ip@v1
     - name: Print Public IP
       run: |
         echo ${{ steps.ip.outputs.ipv4 }} > IP2.txt
     - name: Save IP
       uses: actions/upload-artifact@v2
       with:
         name: IPTwo
         path: IP2.txt
////Loop activity////
     - name: Get IP
       uses: actions/download-artifact@v2
       with:
         name: IPOne
////END Loop activity////
     - uses: actions/checkout@v1
     - name: Save File listing
       run: ls > out2.txt
     - name: Keep file listing artifact
       uses: actions/upload-artifact@v1
       with:
         name: file2_list
         path: out2.txt
     - name: box 2
       uses: ./.github/actions/box2

@bsdillon,

Currently, GitHub Actions workflow does not support executing steps in a loop in the job.

And you need to know that all the steps in a job are executed in order, the previous steps must complete successfully before the subsequent steps start.

If you are worried that the previous step has not completed before the next step starts, you can try to add a command step between these steps to execute a sleep command.

Thank you @brightran I tested using a 2 second sleep and that does resolve the race condition. Well… not really, but it does prevent the error. Thanks for the answer on loop.

You’re welcome, @bsdillon.