Skip to content

Commit

Permalink
Add failure handling and logging improvements in genai workflow and s…
Browse files Browse the repository at this point in the history
…cript
  • Loading branch information
pelikhan committed Sep 26, 2024
1 parent f48627d commit d753cba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/genai-investigator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Trigger on Action Failure
on:
workflow_run:
workflows: ["build"]
types:
- completed
permissions:
actions: read
pull-requests: write
jobs:
check_failure:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 10
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: yarn
- run: yarn install --frozen-lockfile
- name: compile
run: yarn compile
- name: genai investigator
run: yarn genai gai -prc --vars "failure_run_id=${{ github.event.workflow_run.id }}" --out-trace $GITHUB_STEP_SUMMARY
11 changes: 7 additions & 4 deletions packages/sample/genaisrc/gai.genai.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* spellchecker: disable */
import { Octokit } from "octokit"
import { createPatch, createTwoFilesPatch, diffArrays, formatPatch } from "diff"
import { createPatch } from "diff"

const workflow = env.vars.workflow || "build.yml"
const lsid: undefined = env.vars.success_run_id
const ffid = env.vars.failure_run_id
const lsid = env.vars.success_run_id
const branch =
env.vars.branch ||
(await host.exec("git branch --show-current")).stdout.trim()
Expand All @@ -28,18 +29,20 @@ const ls = runs[lsi]
console.log(
`> last success: ${ls.id}, ${ls.created_at}, ${ls.head_sha}, ${ls.html_url}`
)
const ff = runs[lsi - 1]
const ff = ffid ? runs.find(({ id }) => id === ffid) : runs[lsi - 1]
if (!ff) cancel("failure run not found")
console.log(
`> first failure: ${ff.id}, ${ff.created_at}, ${ff.head_sha}, ${ff.html_url}`
)
if (ff.conclusion !== "failure") cancel("failure run not found")

const gitDiff = await host.exec(
`git diff ${ls.head_sha} ${ff.head_sha} -- . :!**/genaiscript.d.ts`
)
console.log(`> source diff: ${(gitDiff.stdout.length / 1000) | 0}kb`)

// download logs
const lsjobs = await downloadRunLog(ls.id)
const lsjobs = await downloadRu nLog(ls.id)
const lsjob = lsjobs[0]
const lslog = lsjob.text
console.log(
Expand Down

0 comments on commit d753cba

Please sign in to comment.