|
| 1 | +# GitHub Actions Examples |
| 2 | + |
| 3 | +> **Tip:** Always use `set -o pipefail` before piping through `tee` — without it, the pipeline returns `tee`'s exit code (0) even when your command fails, so `if: failure()` never triggers. |
| 4 | +
|
| 5 | +## Python / pytest |
| 6 | + |
| 7 | +```yaml |
| 8 | +jobs: |
| 9 | + test: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - uses: actions/checkout@v4 |
| 13 | + - uses: actions/setup-python@v5 |
| 14 | + with: |
| 15 | + python-version: '3.11' |
| 16 | + |
| 17 | + - name: Install dependencies |
| 18 | + run: pip install -r requirements.txt |
| 19 | + |
| 20 | + - name: Run tests |
| 21 | + run: | |
| 22 | + set -o pipefail |
| 23 | + pytest tests/ -v 2>&1 | tee "${{ runner.temp }}/pytest.log" |
| 24 | +
|
| 25 | + - name: Run OpsAgent RCA |
| 26 | + if: failure() |
| 27 | + uses: ChengaDev/opsagent@v1 |
| 28 | + with: |
| 29 | + log-path: ${{ runner.temp }}/pytest.log |
| 30 | + workspace: ${{ github.workspace }} |
| 31 | + slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 32 | + env: |
| 33 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 34 | +``` |
| 35 | +
|
| 36 | +## Node.js / npm |
| 37 | +
|
| 38 | +```yaml |
| 39 | +jobs: |
| 40 | + build: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + - uses: actions/setup-node@v4 |
| 45 | + with: |
| 46 | + node-version: '20' |
| 47 | + |
| 48 | + - name: Install and build |
| 49 | + run: | |
| 50 | + npm ci |
| 51 | + set -o pipefail |
| 52 | + npm run build 2>&1 | tee "${{ runner.temp }}/build.log" |
| 53 | +
|
| 54 | + - name: Run tests |
| 55 | + run: | |
| 56 | + set -o pipefail |
| 57 | + npm test 2>&1 | tee "${{ runner.temp }}/test.log" |
| 58 | +
|
| 59 | + - name: Run OpsAgent RCA |
| 60 | + if: failure() |
| 61 | + uses: ChengaDev/opsagent@v1 |
| 62 | + with: |
| 63 | + log-path: ${{ runner.temp }}/test.log |
| 64 | + workspace: ${{ github.workspace }} |
| 65 | + slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 66 | + env: |
| 67 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 68 | +``` |
| 69 | +
|
| 70 | +## Post RCA as a PR comment |
| 71 | +
|
| 72 | +```yaml |
| 73 | + - name: Run OpsAgent RCA |
| 74 | + if: failure() |
| 75 | + uses: ChengaDev/opsagent@v1 |
| 76 | + with: |
| 77 | + log-path: ${{ runner.temp }}/test.log |
| 78 | + workspace: ${{ github.workspace }} |
| 79 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + env: |
| 81 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 82 | +``` |
| 83 | +
|
| 84 | +OpsAgent posts the full RCA as a comment on the pull request that triggered the failure — no webhook configuration needed. |
| 85 | +
|
| 86 | +## Save the RCA to a file |
| 87 | +
|
| 88 | +```yaml |
| 89 | + - name: Run OpsAgent RCA |
| 90 | + if: failure() |
| 91 | + uses: ChengaDev/opsagent@v1 |
| 92 | + with: |
| 93 | + log-path: ${{ runner.temp }}/test.log |
| 94 | + workspace: ${{ github.workspace }} |
| 95 | + output: ${{ runner.temp }}/rca.md |
| 96 | + env: |
| 97 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 98 | + |
| 99 | + - name: Upload RCA report |
| 100 | + if: failure() |
| 101 | + uses: actions/upload-artifact@v4 |
| 102 | + with: |
| 103 | + name: rca-report |
| 104 | + path: ${{ runner.temp }}/rca.md |
| 105 | +``` |
| 106 | +
|
| 107 | +## Use a custom model |
| 108 | +
|
| 109 | +```yaml |
| 110 | + - name: Run OpsAgent RCA |
| 111 | + if: failure() |
| 112 | + uses: ChengaDev/opsagent@v1 |
| 113 | + with: |
| 114 | + log-path: ${{ runner.temp }}/test.log |
| 115 | + workspace: ${{ github.workspace }} |
| 116 | + model: claude-opus-4-6 |
| 117 | + investigate-model: claude-haiku-4-5-20251001 |
| 118 | + env: |
| 119 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 120 | +``` |
| 121 | +
|
| 122 | +## Use a different provider |
| 123 | +
|
| 124 | +```yaml |
| 125 | + # Google Gemini |
| 126 | + - name: Run OpsAgent RCA |
| 127 | + if: failure() |
| 128 | + uses: ChengaDev/opsagent@v1 |
| 129 | + with: |
| 130 | + log-path: ${{ runner.temp }}/test.log |
| 131 | + workspace: ${{ github.workspace }} |
| 132 | + provider: google |
| 133 | + env: |
| 134 | + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} |
| 135 | +``` |
| 136 | +
|
| 137 | +```yaml |
| 138 | + # OpenAI |
| 139 | + - name: Run OpsAgent RCA |
| 140 | + if: failure() |
| 141 | + uses: ChengaDev/opsagent@v1 |
| 142 | + with: |
| 143 | + log-path: ${{ runner.temp }}/test.log |
| 144 | + workspace: ${{ github.workspace }} |
| 145 | + provider: openai |
| 146 | + env: |
| 147 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 148 | +``` |
| 149 | +
|
| 150 | +## CD pipeline — Helm deploy |
| 151 | +
|
| 152 | +```yaml |
| 153 | + - name: Deploy |
| 154 | + run: | |
| 155 | + set -o pipefail |
| 156 | + helm upgrade --install my-service ./charts/my-service \ |
| 157 | + --namespace production \ |
| 158 | + --set image.tag=${{ github.sha }} \ |
| 159 | + --wait --timeout 5m 2>&1 | tee "${{ runner.temp }}/deploy.log" |
| 160 | +
|
| 161 | + - name: Run OpsAgent RCA |
| 162 | + if: failure() |
| 163 | + uses: ChengaDev/opsagent@v1 |
| 164 | + with: |
| 165 | + log-path: ${{ runner.temp }}/deploy.log |
| 166 | + workspace: ${{ github.workspace }} |
| 167 | + slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 168 | + webhook-url: ${{ secrets.WEBHOOK_URL }} |
| 169 | + env: |
| 170 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 171 | +``` |
| 172 | +
|
| 173 | +## CD pipeline — Terraform |
| 174 | +
|
| 175 | +```yaml |
| 176 | + - name: Terraform apply |
| 177 | + run: | |
| 178 | + set -o pipefail |
| 179 | + terraform apply -auto-approve 2>&1 | tee "${{ runner.temp }}/tf.log" |
| 180 | +
|
| 181 | + - name: Run OpsAgent RCA |
| 182 | + if: failure() |
| 183 | + uses: ChengaDev/opsagent@v1 |
| 184 | + with: |
| 185 | + log-path: ${{ runner.temp }}/tf.log |
| 186 | + workspace: ${{ github.workspace }} |
| 187 | + slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 188 | + webhook-url: ${{ secrets.WEBHOOK_URL }} |
| 189 | + env: |
| 190 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 191 | +``` |
| 192 | +
|
| 193 | +## GitLab CI |
| 194 | +
|
| 195 | +```yaml |
| 196 | +rca: |
| 197 | + stage: .post |
| 198 | + when: on_failure |
| 199 | + script: |
| 200 | + - pip install "git+https://github.com/ChengaDev/opsagent.git[all-providers]" |
| 201 | + - opsagent --log-path build.log --workspace . |
| 202 | + variables: |
| 203 | + ANTHROPIC_API_KEY: $ANTHROPIC_API_KEY |
| 204 | +``` |
| 205 | +
|
| 206 | +## Jenkins |
| 207 | +
|
| 208 | +```groovy |
| 209 | +post { |
| 210 | + failure { |
| 211 | + sh ''' |
| 212 | + pip install "git+https://github.com/ChengaDev/opsagent.git[all-providers]" |
| 213 | + opsagent --log-path build.log --workspace . |
| 214 | + ''' |
| 215 | + } |
| 216 | +} |
| 217 | +``` |
0 commit comments