1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-04 13:48:56 +02:00

chore: AI flag cleanup action trigger workflows (#10288)

https://linear.app/unleash/issue/2-3671/adapt-ai-flag-cleanup-action-to-use-our-unleash-bot-gh-app

Adapts our AI flag cleanup action to use our Unleash-Bot GH app. The
main side-effect we're interested in is that this now automatically
triggers the PR checks.

Example PR: https://github.com/Unleash/unleash/pull/10287
This commit is contained in:
Nuno Góis 2025-07-03 08:48:28 +01:00 committed by GitHub
parent bed467520d
commit 2abbf976fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 75 additions and 46 deletions

View File

@ -29,6 +29,10 @@ on:
api_key_env_value: api_key_env_value:
description: "The API key" description: "The API key"
required: true required: true
UNLEASH_BOT_APP_ID:
required: true
UNLEASH_BOT_PRIVATE_KEY:
required: true
permissions: permissions:
pull-requests: write pull-requests: write
@ -40,15 +44,27 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Generate GitHub App token
id: app_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.UNLEASH_BOT_APP_ID }}
private-key: ${{ secrets.UNLEASH_BOT_PRIVATE_KEY }}
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.ref }} ref: ${{ github.ref }}
token: ${{ steps.app_token.outputs.token }}
fetch-depth: 0
persist-credentials: true
- name: Get issue - name: Get issue
uses: actions/github-script@v7 uses: actions/github-script@v7
id: get_issue id: get_issue
with: with:
github-token: ${{ steps.app_token.outputs.token }}
script: | script: |
console.log('Fetching issue #${{ inputs.issue-number }}') console.log('Fetching issue #${{ inputs.issue-number }}')
const { owner, repo } = context.repo; const { owner, repo } = context.repo;
@ -82,6 +98,7 @@ jobs:
env: env:
FLAG_NAME: ${{ steps.extract_flag.outputs.flag-name }} FLAG_NAME: ${{ steps.extract_flag.outputs.flag-name }}
with: with:
github-token: ${{ steps.app_token.outputs.token }}
result-encoding: string result-encoding: string
script: | script: |
const kebab = (s) => s const kebab = (s) => s
@ -121,13 +138,15 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: ${{ steps.create_branch.outputs.result }} ref: ${{ steps.create_branch.outputs.result }}
token: ${{ steps.app_token.outputs.token }}
fetch-depth: 0 fetch-depth: 0
persist-credentials: true
- name: Configure Git - name: Configure Git
run: | run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --global user.email "194219037+unleash-bot[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]" git config --global user.name "unleash-bot"
- name: Install ripgrep - name: Install ripgrep
run: sudo apt-get update && sudo apt-get install -y ripgrep run: sudo apt-get update && sudo apt-get install -y ripgrep
@ -145,17 +164,16 @@ jobs:
echo "file_list=./file_list.bin" >> $GITHUB_OUTPUT echo "file_list=./file_list.bin" >> $GITHUB_OUTPUT
- name: Create prompt - name: Create prompt
uses: actions/github-script@v7
id: create_prompt id: create_prompt
with: run: |
result-encoding: string ISSUE_BODY="${{ fromJson(steps.get_issue.outputs.result).body }}"
script: | cat <<'EOF' > cleanup_prompt.txt
const body = `${{ fromJson(steps.get_issue.outputs.result).body }}`; Based on the issue description below, refactor the codebase to permanently apply the desired outcome for this feature flag (e.g. enable, keep variant, or discard), by removing all conditional checks and dead branches, preserving only the correct code path.
return `Based on the issue description below, refactor the codebase to permanently apply the desired outcome for this feature flag (e.g. enable, keep variant, or discard), by removing all conditional checks and dead branches, preserving only the correct code path.
After making the changes, provide a **Markdown summary** of what was changed, written for a developer reviewing the PR. Keep it clear, focused, and readable. Use the exact following format (including start & end separator lines, headings, bullets, emojis): After making the changes, provide a **Markdown summary** of what was changed, written for a developer reviewing the PR. Keep it clear, focused, and readable. Use the exact following format (including start & end separator lines, headings, bullets, emojis):
\`\`\`md \`\`\`md
=== AI Flag Cleanup Summary Start === === AI Flag Cleanup Summary Start ===
## 🧹 AI Flag Cleanup Summary ## 🧹 AI Flag Cleanup Summary
@ -176,18 +194,15 @@ jobs:
(Your reasoning for the changes made, including any relevant context or decisions that do not belong at the top of the summary.) (Your reasoning for the changes made, including any relevant context or decisions that do not belong at the top of the summary.)
=== AI Flag Cleanup Summary End === === AI Flag Cleanup Summary End ===
\`\`\` \`\`\`
--- Issue Description --- --- Issue Description ---
${body}`; $ISSUE_BODY
- name: Write prompt
run: |
cat <<'EOF' > cleanup_prompt.txt
${{ steps.create_prompt.outputs.result }}
EOF EOF
echo "prompt-file=cleanup_prompt.txt" >> $GITHUB_OUTPUT
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v4 uses: actions/setup-python@v4
with: with:
@ -202,10 +217,20 @@ jobs:
id: run_aider id: run_aider
timeout-minutes: ${{ inputs.chat-timeout }} timeout-minutes: ${{ inputs.chat-timeout }}
env: env:
GIT_AUTHOR_NAME: 'unleash-bot'
GIT_AUTHOR_EMAIL: '194219037+unleash-bot[bot]@users.noreply.github.com'
GIT_COMMITTER_NAME: 'unleash-bot'
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: |
mapfile -d '' FILES < <(cat "${{ steps.find_files.outputs.file_list }}") mapfile -d '' FILES < <(cat "${{ steps.find_files.outputs.file_list }}")
aider --model "${{ inputs.model }}" --yes "${FILES[@]}" --message-file cleanup_prompt.txt \ aider --model "${{ inputs.model }}" \
--yes \
--message-file cleanup_prompt.txt \
--no-attribute-author \
--no-attribute-committer \
--no-attribute-co-authored-by \
"${FILES[@]}" \
| tee aider_output.txt | tee aider_output.txt
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 ===/{
@ -224,6 +249,7 @@ jobs:
- name: Create Pull Request - name: Create Pull Request
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
github-token: ${{ steps.app_token.outputs.token }}
result-encoding: string result-encoding: string
script: | script: |
const { owner, repo } = context.repo; const { owner, repo } = context.repo;
@ -248,6 +274,8 @@ jobs:
pull_number: existing.number, pull_number: existing.number,
body body
}); });
console.log(`Updated PR #${existing.number}: ${existing.html_url}`);
return existing; return existing;
} }
@ -268,5 +296,4 @@ jobs:
}); });
console.log(`Created PR #${pr.number}: ${pr.html_url}`); console.log(`Created PR #${pr.number}: ${pr.html_url}`);
return pr; return pr;

View File

@ -22,3 +22,5 @@ jobs:
api_key_env_name: GEMINI_API_KEY api_key_env_name: GEMINI_API_KEY
secrets: secrets:
api_key_env_value: ${{ secrets.GEMINI_API_KEY }} api_key_env_value: ${{ secrets.GEMINI_API_KEY }}
UNLEASH_BOT_APP_ID: ${{ secrets.UNLEASH_BOT_APP_ID }}
UNLEASH_BOT_PRIVATE_KEY: ${{ secrets.UNLEASH_BOT_PRIVATE_KEY }}