CI/CD recipes
Page on a failed pipeline, gate deploys, and watch scheduled workflows.
All of these use the CLI. Put the key in your CI's secret store as TREASON_API_KEY (an alert-scoped key is enough) and TREASON_API_URL.
#Page when main is red
# .github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm test
page-on-failure:
needs: test
if: failure() && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- run: npm install -g @treason/sdk
- run: >
treason alert create "CI is red on main"
--alias ci-main --priority P3
--detail run=${{ github.run_id }} --detail commit=${{ github.sha }}
env:
TREASON_API_KEY: ${{ secrets.TREASON_API_KEY }}
TREASON_API_URL: ${{ secrets.TREASON_API_URL }}
resolve:
needs: test
if: success() && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- run: npm install -g @treason/sdk
- run: |
for id in $(treason alerts --alias ci-main --status open --json | jq -r '.alerts[].id'); do treason alert close "$id"; done
env:
TREASON_API_KEY: ${{ secrets.TREASON_API_KEY }}
TREASON_API_URL: ${{ secrets.TREASON_API_URL }}The alias means ten red commits in a row are one alert, not ten.
#Gate a production deploy
approve:
runs-on: ubuntu-latest
steps:
- run: npm install -g @treason/sdk
- run: treason alert create "Approve deploy of ${{ github.sha }}?" --alias "deploy:${{ github.sha }}" --priority P3 --wait 15m
env: { TREASON_API_KEY: "${{ secrets.TREASON_API_KEY }}", TREASON_API_URL: "${{ secrets.TREASON_API_URL }}" }
deploy:
needs: approve # runs only if `treason` exited 0: someone acknowledged
runs-on: ubuntu-latest
steps:
- run: ./deploy.sh--wait exits 0 when a person acknowledges and 2 when nobody does within the time; either way the job result is what gates the next job.
#Watch a scheduled workflow
A workflow that runs nightly and silently stops (a disabled schedule, an expired token) is the classic quiet failure:
on:
schedule: [{ cron: "0 3 * * *" }]
jobs:
nightly:
runs-on: ubuntu-latest
steps:
- run: npm install -g @treason/sdk
- run: treason run --heartbeat nightly-sync -- ./sync.sh
env: { TREASON_API_KEY: "${{ secrets.TREASON_API_KEY }}", TREASON_API_URL: "${{ secrets.TREASON_API_URL }}" }Create the heartbeat once with treason heartbeat set nightly-sync --every 1d --grace 1h (admin key). If GitHub never starts the run, or it fails, nothing pings and you are paged.
#Kubernetes CronJob
containers:
- name: backup
image: your/backup
command: ["treason", "run", "--heartbeat", "nightly-backup", "--alert", "Nightly backup failed", "--", "/backup.sh"]
envFrom: [{ secretRef: { name: treason } }]#Alertmanager and Grafana
These speak Opsgenie's protocol and need no SDK. See Migrating from Opsgenie.