# AutoGovern deployment gate: a GitLab CI/CD job template.
#
# 1. Put this file and autogovern-gate.sh in your repository, for example
#    under ci/.
# 2. Add AUTOGOVERN_API_KEY as a masked, protected CI/CD variable
#    (Settings -> CI/CD -> Variables). It is a Governance API key with the
#    gate:read scope.
# 3. Include the template and add a gate job before your deploy job:
#
#    include:
#      - local: ci/autogovern-gate.gitlab-ci.yml
#    stages: [build, gate, deploy]
#    autogovern_gate:
#      extends: .autogovern_gate
#      stage: gate
#      variables:
#        AUTOGOVERN_SYSTEM_ID: ws_abc123
#
# The job fails, and the pipeline stops before deploy, unless AutoGovern says
# the system may be deployed. See README.md
# (download: https://autogovern.io/download/ci/readme).
.autogovern_gate:
  image: alpine:3.20
  variables:
    AUTOGOVERN_URL: https://autogovern.io
    AUTOGOVERN_GATE_SCRIPT: ci/autogovern-gate.sh
  before_script:
    - command -v curl >/dev/null 2>&1 || apk add --no-cache curl
  script:
    - sh "$AUTOGOVERN_GATE_SCRIPT"
