Is there any way to reuse workflows in a loop until we stop/disable the parent workflow manually?

92 Views Asked by At

I was implementing some workflows and faced an issue with reusable workflow depth limits.

Here is the requirement:

  1. WorkFlow1 (has two jobs) will take input and execute Job1 & will pass the input value to Job2, which actually calls WorkFlow2
  2. WorkFlow2 (has two jobs) will take input and execute Job1 & will pass the input value to Job2 which calls WorkFlow1

The above two steps should run in a loop until we stop/disable WorkFlow1 manually.

Is there any way to achieve this?

WorkFlow1.yml:

name: To run bat tests on mac.
on:
  workflow_dispatch:
    inputs:
      version:
        description: 'release version.'
        required: true
        default: '1.0.0'
        type: string

    workflow_call:
    inputs:
      version:
        required: true
        type: string

jobs:
  run-bat-tests: **#job1**
    runs-on:
      - self-hosted
      - label-1
    outputs:
      version: ${{ steps.version-no.outputs.version }}
    steps:
      - name: Checkout ️
        uses: actions/checkout@v3

      - name: Check the release version
        id: version-no
        run: |
          echo "version=${{ inputs.version }}" >> $GITHUB_ENV
          echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT

  uninstall-test: **#job2**
    if: ${{ always() }}
    needs: run-bat-tests
    uses: ./.github/workflows/WorkFlow2.yml
    with:
      version: ${{ needs.run-bat-tests.outputs.version }}

WorkFlow2.yml:

name: To run uninstall test on mac.

on:
  workflow_call:
    inputs:
      version:
        required: true
        type: string

jobs:
  run-mac-uninstall-test: **#job1**
    runs-on:
      - self-hosted
      - label-1
    outputs:
      version: ${{ steps.version-no.outputs.environment }}

    steps:
      - name: Checkout ️
        uses: actions/checkout@v3

      - name: Check the release version
        id: version-no
        run: |
          echo "version=${{ inputs.version }}" >> $GITHUB_ENV
          echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT


  trigger-bat-tests: **#job2**
    if: ${{ success() }}
    needs: run-mac-uninstall-test
    uses: ./.github/workflows/WorkFlow1.yml
    with:
      version: ${{ needs.run-mac-bat-tests.outputs.version }}

I tried looping the jobs, but I ended up with the issue mentioned above.

0

There are 0 best solutions below