# Required final check: one status that passes only when every job it lists
# succeeded.
#
# Why: GitHub reports a job skipped by its `if:` condition as successful, so a
# required job can be skipped and the pull request can still merge. The
# `required` job below always runs and fails when a job it lists failed, was
# cancelled or was skipped.
#
# To use it:
#   1. Copy the `required` job into the workflow that runs on pull requests.
#   2. Name every mandatory job of that workflow in `needs`. A job left off
#      the list is not checked.
#   3. In the branch ruleset, require the status check by its name:
#      "all required jobs passed".
#   4. Review changes to `needs` like any other change to the merge gate.
#
# Limit: the job sees only jobs in its own workflow. A whole workflow skipped
# by path or branch filters is a different case: its required checks stay
# pending.
#
# The first three jobs are placeholders; replace their steps with your own.
name: ci
on:
  pull_request:
permissions:
  contents: read
jobs:
  lint-types:
    runs-on: ubuntu-24.04
    steps:
      - run: echo "replace with your lint and type checks"
  test:
    runs-on: ubuntu-24.04
    steps:
      - run: echo "replace with your tests"
  build:
    runs-on: ubuntu-24.04
    steps:
      - run: echo "replace with your build"
  required:
    name: all required jobs passed
    if: always()
    needs: [lint-types, test, build]
    runs-on: ubuntu-24.04
    steps:
      - name: Reject failed, cancelled or skipped jobs
        env:
          NEEDS: ${{ toJSON(needs) }}
        run: echo "$NEEDS" | jq -e 'all(.[]; .result == "success")'
