name: ready to merge

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

jobs:
  all_jobs_passed:
    name: all jobs passed
    runs-on: ubuntu-latest
    steps:
      - name: "Check status of all required jobs"
        run: |-
          NEEDS_CONTEXT='${{ inputs.needs_context }}'
          JOB_IDS=$(echo "$NEEDS_CONTEXT" | jq -r 'keys[]')
          for JOB_ID in $JOB_IDS; do
            RESULT=$(echo "$NEEDS_CONTEXT" | jq -r ".[\"$JOB_ID\"].result")
            echo "$JOB_ID job result: $RESULT"
            if [[ $RESULT != "success" && $RESULT != "skipped" ]]; then
              echo "***"
              echo "Error: The $JOB_ID job did not pass."
              exit 1
            fi
          done
          echo "All jobs passed or were skipped."
