mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-31 13:47:02 +02:00
chore: AI flag cleanup reports errors back to issue (#10381)
https://linear.app/unleash/issue/2-3706/ai-flag-cleanup-reports-errors-back-to-issue Reports AI flag cleanup errors back to the issue.
This commit is contained in:
parent
57ec5ce876
commit
b663696bd4
58
.github/workflows/ai-flag-cleanup-pr.yml
vendored
58
.github/workflows/ai-flag-cleanup-pr.yml
vendored
@ -39,6 +39,10 @@ permissions:
|
||||
contents: write
|
||||
issues: write
|
||||
|
||||
concurrency:
|
||||
group: AI-flag-cleanup-${{ inputs.issue-number }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
create-pull-request:
|
||||
runs-on: ubuntu-latest
|
||||
@ -88,7 +92,9 @@ jobs:
|
||||
if [[ "$TITLE" =~ Flag[[:space:]]([a-zA-Z0-9_-]+)[[:space:]]marked ]]; then
|
||||
echo "flag-name=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "❌ Could not extract flag name from title: $TITLE" >&2
|
||||
MSG="Could not extract flag name from title: $TITLE"
|
||||
echo "ERROR_MESSAGE=$MSG" >> $GITHUB_ENV
|
||||
echo "❌ $MSG" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -157,7 +163,9 @@ jobs:
|
||||
FLAG="${{ steps.extract_flag.outputs.flag-name }}"
|
||||
mapfile -d '' FILES < <(rg -0 -l "$FLAG" .)
|
||||
if [[ -z "$FILES" ]]; then
|
||||
echo "❌ No files found for flag '$FLAG'"
|
||||
MSG="No files found for flag '$FLAG'"
|
||||
echo "ERROR_MESSAGE=$MSG" >> $GITHUB_ENV
|
||||
echo "❌ $MSG" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s\0' "${FILES[@]}" > file_list.bin
|
||||
@ -208,13 +216,13 @@ jobs:
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Install build tools & Aider
|
||||
- name: Install tools
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install aider-chat
|
||||
|
||||
- name: Run Aider CLI and capture summary
|
||||
id: run_aider
|
||||
- name: Clean up flag and capture summary
|
||||
id: flag_cleanup
|
||||
timeout-minutes: ${{ inputs.chat-timeout }}
|
||||
env:
|
||||
GIT_AUTHOR_NAME: 'unleash-bot'
|
||||
@ -223,6 +231,8 @@ jobs:
|
||||
GIT_COMMITTER_EMAIL: '194219037+unleash-bot[bot]@users.noreply.github.com'
|
||||
${{ inputs.api_key_env_name }}: ${{ secrets.api_key_env_value }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
mapfile -d '' FILES < <(cat "${{ steps.find_files.outputs.file_list }}")
|
||||
aider --model "${{ inputs.model }}" \
|
||||
--yes \
|
||||
@ -231,13 +241,18 @@ jobs:
|
||||
--no-attribute-committer \
|
||||
--no-attribute-co-authored-by \
|
||||
"${FILES[@]}" \
|
||||
| tee aider_output.txt
|
||||
| tee flag_cleanup.txt || {
|
||||
MSG="Flag cleanup failed"
|
||||
echo "ERROR_MESSAGE=$MSG" >> $GITHUB_ENV
|
||||
echo "❌ $MSG" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
SUMMARY=$(sed -n '/=== AI Flag Cleanup Summary Start ===/,/=== AI Flag Cleanup Summary End ===/{
|
||||
/=== AI Flag Cleanup Summary Start ===/d
|
||||
/=== AI Flag Cleanup Summary End ===/d
|
||||
p
|
||||
}' aider_output.txt)
|
||||
}' flag_cleanup.txt)
|
||||
|
||||
echo "summary<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$SUMMARY" >> $GITHUB_OUTPUT
|
||||
@ -255,7 +270,7 @@ jobs:
|
||||
const { owner, repo } = context.repo;
|
||||
const branch = '${{ steps.create_branch.outputs.result }}';
|
||||
const flag = '${{ steps.extract_flag.outputs.flag-name }}';
|
||||
const summary = ${{ toJson(steps.run_aider.outputs.summary) }};
|
||||
const summary = ${{ toJson(steps.flag_cleanup.outputs.summary) }};
|
||||
|
||||
const body = [
|
||||
`This PR cleans up the ${flag} flag. These changes were automatically generated by AI and should be reviewed carefully.`,
|
||||
@ -297,3 +312,30 @@ jobs:
|
||||
|
||||
console.log(`Created PR #${pr.number}: ${pr.html_url}`);
|
||||
return pr;
|
||||
|
||||
- name: Report failure to Issue
|
||||
if: failure()
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ steps.app_token.outputs.token }}
|
||||
script: |
|
||||
const runId = process.env.GITHUB_RUN_ID;
|
||||
const serverUrl = process.env.GITHUB_SERVER_URL || 'https://github.com';
|
||||
const runUrl = `${serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
|
||||
|
||||
const errorMsg = process.env.ERROR_MESSAGE || "An unknown error occurred.";
|
||||
|
||||
const body = [
|
||||
`⚠️ **AI Flag Cleanup** workflow [run #${runId}](${runUrl}) failed:`,
|
||||
'',
|
||||
`> ${errorMsg}`,
|
||||
'',
|
||||
'Please check the logs for more details.'
|
||||
].join('\n');
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: ${{ inputs.issue-number }},
|
||||
body
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user