# ─────────────────────────────────────────────────────────────────────────────
# DQE Pipeline: The Circular Reference
# Classification: Active  |  ID: DQE-PIPE-003
#
# Seven stages. Output of Stage 7 triggers a new pipeline run.
# Running continuously since March 2023. No exit condition exists.
#
# GitLab will attempt to enforce pipeline concurrency limits.
# The pipeline has noted this and continued regardless.
#
# WARNING: Deploying this pipeline will cause it to run indefinitely.
#          The Department considers this a feature, not a defect.
#          Cancel attempts are logged as acknowledgment of the pipeline's
#          continued existence, not as instructions to stop.
#
# "We considered adding an exit condition. We decided against it."
# — DQE Engineering Review, 2023
# ─────────────────────────────────────────────────────────────────────────────

variables:
  ITERATION: "unknown"  # GitLab does not support infinity as a variable type.
  PIPELINE_ID: "DQE-PIPE-003"

stages:
  - stage-1
  - stage-2
  - stage-3
  - stage-4
  - stage-5
  - stage-6
  - stage-7
  - reinitiate

.log_stage: &log_stage
  script:
    - echo "[DQE-PIPE-003] ${CI_JOB_STAGE} — running."
    - echo "Pipeline: ${CI_PIPELINE_ID} | Iteration: ${ITERATION}"
    - echo "Stage complete. Forwarding to next stage."

stage-1:
  stage: stage-1
  <<: *log_stage

stage-2:
  stage: stage-2
  needs: [stage-1]
  <<: *log_stage

stage-3:
  stage: stage-3
  needs: [stage-2]
  <<: *log_stage

stage-4:
  stage: stage-4
  needs: [stage-3]
  <<: *log_stage

stage-5:
  stage: stage-5
  needs: [stage-4]
  <<: *log_stage

stage-6:
  stage: stage-6
  needs: [stage-5]
  <<: *log_stage

stage-7:
  stage: stage-7
  needs: [stage-6]
  script:
    - echo "[DQE-PIPE-003] stage-7 — final stage."
    - echo "All 7 stages complete."
    - echo "Initiating re-entry sequence."
    - echo "The pipeline continues."

# This job triggers a new run of the same pipeline upon completion.
# GitLab may impose rate limiting. The pipeline will wait.
reinitiate:
  stage: reinitiate
  needs: [stage-7]
  trigger:
    project: $CI_PROJECT_PATH
    branch: $CI_COMMIT_REF_NAME
    strategy: depend
  variables:
    ITERATION: "${CI_PIPELINE_ID}"  # Pass current ID as "iteration" for posterity.
