From bfe6551f436848d0e81f2d4e16555884e608a331 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 26 Sep 2024 22:28:38 +0000 Subject: [PATCH 1/6] Fix typo in function call within gai.genai.mts file --- packages/sample/genaisrc/gai.genai.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sample/genaisrc/gai.genai.mts b/packages/sample/genaisrc/gai.genai.mts index e8881e0117..7035bebefb 100644 --- a/packages/sample/genaisrc/gai.genai.mts +++ b/packages/sample/genaisrc/gai.genai.mts @@ -42,7 +42,7 @@ const gitDiff = await host.exec( console.log(`> source diff: ${(gitDiff.stdout.length / 1000) | 0}kb`) // download logs -const lsjobs = await downloadRunLog(ls.id) +const lsjobs = await downlo adRunLog(ls.id) const lsjob = lsjobs[0] const lslog = lsjob.text console.log( From 088b3a6fbc6771ec687651a9ba99b79a6a207350 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 26 Sep 2024 22:33:19 +0000 Subject: [PATCH 2/6] Handle missing last success run and match logs by job name. --- packages/sample/genaisrc/gai.genai.mts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/sample/genaisrc/gai.genai.mts b/packages/sample/genaisrc/gai.genai.mts index 7035bebefb..79774b6ccd 100644 --- a/packages/sample/genaisrc/gai.genai.mts +++ b/packages/sample/genaisrc/gai.genai.mts @@ -26,6 +26,7 @@ const lsi = lsid ? runs.findIndex(({ id }) => id === lsid) : runs.findIndex(({ conclusion }) => conclusion === "success") const ls = runs[lsi] +if (!ls) cancel("last success run not found") console.log( `> last success: ${ls.id}, ${ls.created_at}, ${ls.head_sha}, ${ls.html_url}` ) @@ -42,19 +43,20 @@ const gitDiff = await host.exec( console.log(`> source diff: ${(gitDiff.stdout.length / 1000) | 0}kb`) // download logs -const lsjobs = await downlo adRunLog(ls.id) -const lsjob = lsjobs[0] -const lslog = lsjob.text -console.log( - `> last success log: ${(lslog.length / 1000) | 0}kb ${lsjob.logUrl}` -) const ffjobs = await downloadRunLog(ff.id) -const ffjob = ffjobs[0] +const ffjob = ffjobs.find(({ conclusion }) => conclusion === "failure") const fflog = ffjob.text console.log( `> first failure log: ${(fflog.length / 1000) | 0}kb ${ffjob.logUrl}` ) +const lsjobs = await downloadRunLog(ls.id) +const lsjob = lsjobs.find(({ name }) => ffjob.name === name) +const lslog = lsjob.text +console.log( + `> last success log: ${(lslog.length / 1000) | 0}kb ${lsjob.logUrl}` +) + const logDiff = diffJobLogs(lslog, fflog) console.log(`> log diff: ${(logDiff.length / 1000) | 0}kb`) From c17b6db60cbc59f8a7821881ecf357c95a0d0bc7 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 26 Sep 2024 22:37:21 +0000 Subject: [PATCH 3/6] fault injection --- packages/sample/genaisrc/gai.genai.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sample/genaisrc/gai.genai.mts b/packages/sample/genaisrc/gai.genai.mts index 79774b6ccd..2b607d3b8d 100644 --- a/packages/sample/genaisrc/gai.genai.mts +++ b/packages/sample/genaisrc/gai.genai.mts @@ -50,7 +50,7 @@ console.log( `> first failure log: ${(fflog.length / 1000) | 0}kb ${ffjob.logUrl}` ) -const lsjobs = await downloadRunLog(ls.id) +const lsjobs = await downlo adRunLog(ls.id) const lsjob = lsjobs.find(({ name }) => ffjob.name === name) const lslog = lsjob.text console.log( From 558d19355f5c9446e1c110936c8fd954e817d9d7 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 26 Sep 2024 22:40:53 +0000 Subject: [PATCH 4/6] missing secrets --- .github/workflows/genai-investigator.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/genai-investigator.yml b/.github/workflows/genai-investigator.yml index fd5f9bfdf1..568dfd3800 100644 --- a/.github/workflows/genai-investigator.yml +++ b/.github/workflows/genai-investigator.yml @@ -25,3 +25,8 @@ jobs: 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 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + OPENAI_API_TYPE: ${{ secrets.OPENAI_API_TYPE }} + OPENAI_API_BASE: ${{ secrets.OPENAI_API_BASE }} From 2f3634a22c96d160388c6e57f5b9e0604ba573a2 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 26 Sep 2024 22:52:03 +0000 Subject: [PATCH 5/6] Update workflow to use genaiscript for running GAi tasks and adjust permissions --- .github/workflows/genai-investigator.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/genai-investigator.yml b/.github/workflows/genai-investigator.yml index 568dfd3800..7c4475e6fb 100644 --- a/.github/workflows/genai-investigator.yml +++ b/.github/workflows/genai-investigator.yml @@ -5,6 +5,7 @@ on: types: - completed permissions: + contents: read actions: read pull-requests: write jobs: @@ -23,8 +24,8 @@ jobs: - 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 + - name: genaiscript gai + run: node packages/cli/built/genaiscript.cjs run gai -prc --vars "failure_run_id=${{ github.event.workflow_run.id }}" --out-trace $GITHUB_STEP_SUMMARY env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} From c71d8dd3e2db1231d3568aeaa5641cdf6fda9010 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 26 Sep 2024 23:17:48 +0000 Subject: [PATCH 6/6] Add script parameters and fix typo in function call --- packages/sample/genaisrc/gai.genai.mts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/sample/genaisrc/gai.genai.mts b/packages/sample/genaisrc/gai.genai.mts index 2b607d3b8d..9a0c6f66a3 100644 --- a/packages/sample/genaisrc/gai.genai.mts +++ b/packages/sample/genaisrc/gai.genai.mts @@ -2,6 +2,15 @@ import { Octokit } from "octokit" import { createPatch } from "diff" +script({ + parameters: { + workflow: { type: "string" }, + failure_run_id: { type: "number" }, + success_run_id: { type: "number" }, + branch: { type: "string" }, + }, +}) + const workflow = env.vars.workflow || "build.yml" const ffid = env.vars.failure_run_id const lsid = env.vars.success_run_id @@ -50,7 +59,7 @@ console.log( `> first failure log: ${(fflog.length / 1000) | 0}kb ${ffjob.logUrl}` ) -const lsjobs = await downlo adRunLog(ls.id) +const lsjobs = await downloadRunLog(ls.id) const lsjob = lsjobs.find(({ name }) => ffjob.name === name) const lslog = lsjob.text console.log(