-
Notifications
You must be signed in to change notification settings - Fork 37
Create issues with agentic instructions when workflows need recompilation #9277
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2731c97
Initial plan
Copilot b4eb1f0
Add check_workflow_recompile_needed.cjs and update maintenance workflow
Copilot 3d4d942
Format JavaScript files with prettier
Copilot 886be20
Merge branch 'main' into copilot/update-agentics-maintenance-job
pelikhan ad25582
Merge branch 'main' into copilot/update-agentics-maintenance-job
pelikhan 2192c9e
Use sparse checkout of .github folder with persist-credentials: false
Copilot abd6e65
Update checkout strategy: full repo in dev mode, sparse .github in re…
Copilot c24aed2
Merge branch 'main' into copilot/update-agentics-maintenance-job
pelikhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| // @ts-check | ||
| /// <reference types="@actions/github-script" /> | ||
|
|
||
| const { getErrorMessage } = require("./error_helpers.cjs"); | ||
|
|
||
| /** | ||
| * Check if workflows need recompilation and create an issue if needed. | ||
| * This script: | ||
| * 1. Checks if there are out-of-sync workflow lock files | ||
| * 2. Searches for existing open issues about recompiling workflows | ||
| * 3. If workflows are out of sync and no issue exists, creates a new issue with agentic instructions | ||
| * | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async function main() { | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
|
|
||
| core.info("Checking for out-of-sync workflow lock files"); | ||
|
|
||
| // Execute git diff to check for changes in lock files | ||
| let diffOutput = ""; | ||
| let hasChanges = false; | ||
|
|
||
| try { | ||
| // Run git diff to check if there are any changes in lock files | ||
| await exec.exec("git", ["diff", "--exit-code", ".github/workflows/*.lock.yml"], { | ||
| ignoreReturnCode: true, | ||
| listeners: { | ||
| stdout: data => { | ||
| diffOutput += data.toString(); | ||
| }, | ||
| stderr: data => { | ||
| diffOutput += data.toString(); | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // If git diff exits with code 0, there are no changes | ||
| // If it exits with code 1, there are changes | ||
| // We need to check if there's actual diff output | ||
| hasChanges = diffOutput.trim().length > 0; | ||
| } catch (error) { | ||
| core.error(`Failed to check for workflow changes: ${getErrorMessage(error)}`); | ||
| throw error; | ||
| } | ||
|
|
||
| if (!hasChanges) { | ||
| core.info("✓ All workflow lock files are up to date"); | ||
| return; | ||
| } | ||
|
|
||
| core.info("⚠ Detected out-of-sync workflow lock files"); | ||
|
|
||
| // Capture the actual diff for the issue body | ||
| let detailedDiff = ""; | ||
| try { | ||
| await exec.exec("git", ["diff", ".github/workflows/*.lock.yml"], { | ||
| listeners: { | ||
| stdout: data => { | ||
| detailedDiff += data.toString(); | ||
| }, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| core.warning(`Could not capture detailed diff: ${getErrorMessage(error)}`); | ||
| } | ||
|
|
||
| // Search for existing open issue about workflow recompilation | ||
| const issueTitle = "Workflows need recompilation"; | ||
| const searchQuery = `repo:${owner}/${repo} is:issue is:open in:title "${issueTitle}"`; | ||
|
|
||
| core.info(`Searching for existing issue with title: "${issueTitle}"`); | ||
|
|
||
| try { | ||
| const searchResult = await github.rest.search.issuesAndPullRequests({ | ||
| q: searchQuery, | ||
| per_page: 1, | ||
| }); | ||
|
|
||
| if (searchResult.data.total_count > 0) { | ||
| const existingIssue = searchResult.data.items[0]; | ||
| core.info(`Found existing issue #${existingIssue.number}: ${existingIssue.html_url}`); | ||
| core.info("Skipping issue creation (avoiding duplicate)"); | ||
|
|
||
| // Add a comment to the existing issue with the new workflow run info | ||
| const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; | ||
| const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${context.runId}` : `${githubServer}/${owner}/${repo}/actions/runs/${context.runId}`; | ||
| const commentBody = `Workflows are still out of sync as of ${new Date().toISOString()}.\n\nSee [workflow run](${runUrl}) for details.`; | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| issue_number: existingIssue.number, | ||
| body: commentBody, | ||
| }); | ||
|
|
||
| core.info(`✓ Added comment to existing issue #${existingIssue.number}`); | ||
| return; | ||
| } | ||
| } catch (error) { | ||
| core.error(`Failed to search for existing issues: ${getErrorMessage(error)}`); | ||
| throw error; | ||
| } | ||
|
|
||
| // No existing issue found, create a new one | ||
| core.info("No existing issue found, creating a new issue with agentic instructions"); | ||
|
|
||
| const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; | ||
| const runUrl = context.payload.repository ? `${context.payload.repository.html_url}/actions/runs/${context.runId}` : `${githubServer}/${owner}/${repo}/actions/runs/${context.runId}`; | ||
|
|
||
| // Build the issue body with agentic instructions | ||
| const issueBody = `## Problem | ||
|
|
||
| The workflow lock files (\`.lock.yml\`) are out of sync with their source markdown files (\`.md\`). This means the workflows that run in GitHub Actions are not using the latest configuration. | ||
|
|
||
| ## What needs to be done | ||
|
|
||
| The workflows need to be recompiled to regenerate the lock files from the markdown sources. | ||
|
|
||
| ## Instructions for GitHub Copilot | ||
|
|
||
| Please recompile all workflows by running the following command: | ||
|
|
||
| \`\`\`bash | ||
| make recompile | ||
| \`\`\` | ||
|
|
||
| This will: | ||
| 1. Build the latest version of \`gh-aw\` | ||
| 2. Compile all workflow markdown files to YAML lock files | ||
| 3. Ensure all workflows are up to date | ||
|
|
||
| After recompiling, commit the changes with a message like: | ||
| \`\`\` | ||
| Recompile workflows to update lock files | ||
| \`\`\` | ||
|
|
||
| ## Detected Changes | ||
|
|
||
| The following workflow lock files have changes: | ||
|
|
||
| <details> | ||
| <summary>View diff</summary> | ||
|
|
||
| \`\`\`diff | ||
| ${detailedDiff.substring(0, 50000)}${detailedDiff.length > 50000 ? "\n\n... (diff truncated)" : ""} | ||
| \`\`\` | ||
|
|
||
| </details> | ||
|
|
||
| ## References | ||
|
|
||
| - **Failed Check:** [Workflow Run](${runUrl}) | ||
| - **Repository:** ${owner}/${repo} | ||
|
|
||
| --- | ||
|
|
||
| > This issue was automatically created by the agentics maintenance workflow. | ||
| `; | ||
|
|
||
| try { | ||
| const newIssue = await github.rest.issues.create({ | ||
| owner, | ||
| repo, | ||
| title: issueTitle, | ||
| body: issueBody, | ||
| labels: ["maintenance", "workflows"], | ||
| }); | ||
|
|
||
| core.info(`✓ Created issue #${newIssue.data.number}: ${newIssue.data.html_url}`); | ||
|
|
||
| // Write to job summary | ||
| await core.summary.addHeading("Workflow Recompilation Needed", 2).addRaw(`Created issue [#${newIssue.data.number}](${newIssue.data.html_url}) to track workflow recompilation.`).write(); | ||
| } catch (error) { | ||
| core.error(`Failed to create issue: ${getErrorMessage(error)}`); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| module.exports = { main }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.