Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to diff GitHub Actions job logs and update related documentation and tool definitions #748

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/src/components/BuiltinTools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<LinkCard title="github_actions_workflows_list" description="List all workflows as a list of 'id: name' pair." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_runs_list" description="List all runs for a workflow. Use 'git_actions_list_workflows' to list workflows." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_jobs_list" description="List all jobs for a run." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_job_log" description="Download job log." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
<LinkCard title="github_actions_job_log_get" description="Download workflow job log." href="/genaiscript/reference/scripts/system#systemgithub_actions" />

Check failure on line 23 in docs/src/components/BuiltinTools.mdx

View workflow job for this annotation

GitHub Actions / build

The tool name 'github_actions_job_log_get' should be 'github_actions_job_log' to maintain consistency with the existing documentation and tool naming conventions.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
<LinkCard title="github_actions_job_log_diff" description="Diffs two workflow job logs." href="/genaiscript/reference/scripts/system#systemgithub_actions" />
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool name 'github_actions_job_log_diff' should be 'github_actions_job_logs_diff' to maintain consistency in naming convention.

generated by pr-docs-review-commit incorrect_tool_name

<LinkCard title="github_files_get" description="Get a file from a repository." href="/genaiscript/reference/scripts/system#systemgithub_files" />
<LinkCard title="github_files_list" description="List all files in a repository." href="/genaiscript/reference/scripts/system#systemgithub_files" />
<LinkCard title="github_issues_list" description="List all issues in a repository." href="/genaiscript/reference/scripts/system#systemgithub_issues" />
Expand Down
36 changes: 33 additions & 3 deletions docs/src/content/docs/reference/scripts/system.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
type: "string",
description: "Query to answer",
},
required: ["query"],
},
async (args) => {
const { context, query } = args
Expand Down Expand Up @@ -178,6 +179,7 @@
type: "string",
description: "Query to answer",
},
required: ["query"],
},
async (args) => {
const { context, query } = args
Expand Down Expand Up @@ -234,6 +236,7 @@
type: "string",
description: "Query to answer",
},
required: ["query"],
},
async (args) => {
const { context, query } = args
Expand All @@ -246,8 +249,12 @@

Analyze and answer QUERY.

## Constraints

- Assume that your answer will be analyzed by an LLM, not a human.
- If you cannot answer the query, return an empty string.
- Prefer diffing job logs rather downloading entire logs which can be very large.

Check failure on line 256 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

The 'Constraints' section should not be added here as it is not consistent with the rest of the documentation format and may confuse the reader about its applicability.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

`
},
{
Expand Down Expand Up @@ -796,7 +803,8 @@
- tool `github_actions_workflows_list`: List all workflows as a list of 'id: name' pair.
- tool `github_actions_runs_list`: List all runs for a workflow. Use 'git_actions_list_workflows' to list workflows.
- tool `github_actions_jobs_list`: List all jobs for a run.
- tool `github_actions_job_log`: Download job log.
- tool `github_actions_job_log_get`: Download workflow job log.
- tool `github_actions_job_log_diff`: Diffs two workflow job logs.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tool name 'github_actions_job_log_diff' should be 'github_actions_job_logs_diff' to maintain consistency in naming convention.

generated by pr-docs-review-commit incorrect_tool_name


`````js wrap title="system.github_actions"
system({
Expand Down Expand Up @@ -881,8 +889,8 @@
)

defTool(
"github_actions_job_log",
"Download job log.",
"github_actions_job_log_get",
"Download workflow job log.",
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
{
job_id: {
type: "string",
Expand All @@ -900,6 +908,28 @@
}
)

defTool(
"github_actions_job_log_diff",
"Diffs two workflow job logs.",
{
job_id: {
type: "string",
description: "ID of the job to compare.",
},
other_job_id: {
type: "string",
description: "ID of the other job to compare.",
},
required: ["job_id", "other_job_id"],
},
async (args) => {
const { job_id, other_job_id, context } = args
context.log(`github action diff job logs ${job_id} ${other_job_id}`)
const log = await github.diffWorkflowJobLogs(job_id, other_job_id)
return log
}

Check failure on line 930 in docs/src/content/docs/reference/scripts/system.mdx

View workflow job for this annotation

GitHub Actions / build

The tool name 'github_actions_job_log_diff' should be 'github_actions_job_log' to maintain consistency with the existing documentation and tool naming conventions.
)
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

`````


Expand Down
8 changes: 7 additions & 1 deletion genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/auto/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/core/src/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/core/src/genaisrc/system.agent_github.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ defTool(

Analyze and answer QUERY.

## Constraints

- Assume that your answer will be analyzed by an LLM, not a human.
- If you cannot answer the query, return an empty string.
- Prefer diffing job logs rather downloading entire logs which can be very large.

`
},
{
Expand Down
26 changes: 24 additions & 2 deletions packages/core/src/genaisrc/system.github_actions.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ defTool(
)

defTool(
"github_actions_job_log",
"Download job log.",
"github_actions_job_log_get",
"Download workflow job log.",
{
job_id: {
type: "string",
Expand All @@ -98,3 +98,25 @@ defTool(
return log
}
)

defTool(
"github_actions_job_log_diff",
"Diffs two workflow job logs.",
{
job_id: {
type: "string",
description: "ID of the job to compare.",
},
other_job_id: {
type: "string",
description: "ID of the other job to compare.",
},
required: ["job_id", "other_job_id"],
},
async (args) => {
const { job_id, other_job_id, context } = args
context.log(`github action diff job logs ${job_id} ${other_job_id}`)
const log = await github.diffWorkflowJobLogs(job_id, other_job_id)
return log
}
)
24 changes: 24 additions & 0 deletions packages/core/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { isGlobMatch } from "./glob"
import { fetchText } from "./fetch"
import { concurrentLimit } from "./concurrency"
import { createDiff, llmifyDiff } from "./diff"

export interface GithubConnectionInfo {
token: string
Expand Down Expand Up @@ -706,6 +707,29 @@
return text
}

private async downladJob(job_id: number) {
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
const { client, owner, repo } = await this.client()
const { url: filename } =
await client.rest.actions.downloadJobLogsForWorkflowRun({
owner,
repo,
job_id,
})
const { text: content } = await fetchText(filename)
return { filename, content }
}

async diffWorkflowJobLogs(job_id: number, other_job_id: number) {
const job = await this.downladJob(job_id)
const other = await this.downladJob(other_job_id)

job.content = parseJobLog(job.content)
other.content = parseJobLog(other.content)

const diff = createDiff(job, other)
return llmifyDiff(diff)
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
}

Check failure on line 731 in packages/core/src/github.ts

View workflow job for this annotation

GitHub Actions / build

The new methods `downladJob` and `diffWorkflowJobLogs` do not have any error handling. If any of the API calls fail, the error will propagate up the call stack and could potentially crash the application. It would be better to wrap these calls in a try-catch block and handle the error appropriately. 😊

Check failure on line 731 in packages/core/src/github.ts

View workflow job for this annotation

GitHub Actions / build

There is a typo in the method name `downladJob`. It should be `downloadJob`. Typos in method names can lead to confusion and bugs in the future. 😅

Check failure on line 731 in packages/core/src/github.ts

View workflow job for this annotation

GitHub Actions / build

The functions `parseJobLog`, `createDiff`, and `llmifyDiff` are being used in `diffWorkflowJobLogs` method but they are not defined or imported in the visible diff. Please ensure these functions are properly defined and imported. 😇
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

async getFile(filename: string, ref: string): Promise<WorkspaceFile> {
const { client, owner, repo } = await this.client()
const { data: content } = await client.rest.repos.getContent({
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,11 @@ interface GitHub {
options?: { llmify?: boolean }
): Promise<string>

/**
* Diffs two GitHub Action workflow job logs
*/
diffWorkflowJobLogs(job_id: number, other_job_id: number): Promise<string>

/**
* Lists issues for a given repository
* @param options
Expand Down
8 changes: 7 additions & 1 deletion packages/sample/genaisrc/blog/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/sample/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/sample/genaisrc/node/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/sample/genaisrc/poem.genai.mts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
$`Write a short poem.`
x x x
8 changes: 7 additions & 1 deletion packages/sample/genaisrc/python/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion packages/sample/genaisrc/style/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading