1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-04 13:48:56 +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:
Nuno Góis 2025-07-22 16:21:56 +01:00 committed by GitHub
parent 57ec5ce876
commit b663696bd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,6 +39,10 @@ permissions:
contents: write contents: write
issues: write issues: write
concurrency:
group: AI-flag-cleanup-${{ inputs.issue-number }}
cancel-in-progress: true
jobs: jobs:
create-pull-request: create-pull-request:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -88,7 +92,9 @@ jobs:
if [[ "$TITLE" =~ Flag[[:space:]]([a-zA-Z0-9_-]+)[[:space:]]marked ]]; then if [[ "$TITLE" =~ Flag[[:space:]]([a-zA-Z0-9_-]+)[[:space:]]marked ]]; then
echo "flag-name=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT echo "flag-name=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
else 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 exit 1
fi fi
@ -157,7 +163,9 @@ jobs:
FLAG="${{ steps.extract_flag.outputs.flag-name }}" FLAG="${{ steps.extract_flag.outputs.flag-name }}"
mapfile -d '' FILES < <(rg -0 -l "$FLAG" .) mapfile -d '' FILES < <(rg -0 -l "$FLAG" .)
if [[ -z "$FILES" ]]; then 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 exit 1
fi fi
printf '%s\0' "${FILES[@]}" > file_list.bin printf '%s\0' "${FILES[@]}" > file_list.bin
@ -208,13 +216,13 @@ jobs:
with: with:
python-version: '3.12' python-version: '3.12'
- name: Install build tools & Aider - name: Install tools
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install aider-chat pip install aider-chat
- name: Run Aider CLI and capture summary - name: Clean up flag and capture summary
id: run_aider id: flag_cleanup
timeout-minutes: ${{ inputs.chat-timeout }} timeout-minutes: ${{ inputs.chat-timeout }}
env: env:
GIT_AUTHOR_NAME: 'unleash-bot' GIT_AUTHOR_NAME: 'unleash-bot'
@ -223,6 +231,8 @@ jobs:
GIT_COMMITTER_EMAIL: '194219037+unleash-bot[bot]@users.noreply.github.com' GIT_COMMITTER_EMAIL: '194219037+unleash-bot[bot]@users.noreply.github.com'
${{ inputs.api_key_env_name }}: ${{ secrets.api_key_env_value }} ${{ inputs.api_key_env_name }}: ${{ secrets.api_key_env_value }}
run: | run: |
set -euo pipefail
mapfile -d '' FILES < <(cat "${{ steps.find_files.outputs.file_list }}") mapfile -d '' FILES < <(cat "${{ steps.find_files.outputs.file_list }}")
aider --model "${{ inputs.model }}" \ aider --model "${{ inputs.model }}" \
--yes \ --yes \
@ -231,13 +241,18 @@ jobs:
--no-attribute-committer \ --no-attribute-committer \
--no-attribute-co-authored-by \ --no-attribute-co-authored-by \
"${FILES[@]}" \ "${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 ===/{ SUMMARY=$(sed -n '/=== AI Flag Cleanup Summary Start ===/,/=== AI Flag Cleanup Summary End ===/{
/=== AI Flag Cleanup Summary Start ===/d /=== AI Flag Cleanup Summary Start ===/d
/=== AI Flag Cleanup Summary End ===/d /=== AI Flag Cleanup Summary End ===/d
p p
}' aider_output.txt) }' flag_cleanup.txt)
echo "summary<<EOF" >> $GITHUB_OUTPUT echo "summary<<EOF" >> $GITHUB_OUTPUT
echo "$SUMMARY" >> $GITHUB_OUTPUT echo "$SUMMARY" >> $GITHUB_OUTPUT
@ -255,7 +270,7 @@ jobs:
const { owner, repo } = context.repo; const { owner, repo } = context.repo;
const branch = '${{ steps.create_branch.outputs.result }}'; const branch = '${{ steps.create_branch.outputs.result }}';
const flag = '${{ steps.extract_flag.outputs.flag-name }}'; 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 = [ const body = [
`This PR cleans up the ${flag} flag. These changes were automatically generated by AI and should be reviewed carefully.`, `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}`); console.log(`Created PR #${pr.number}: ${pr.html_url}`);
return pr; 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
});