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:
parent
bed467520d
commit
2abbf976fe
117
.github/workflows/ai-flag-cleanup-pr.yml
vendored
117
.github/workflows/ai-flag-cleanup-pr.yml
vendored
@ -29,6 +29,10 @@ on:
|
||||
api_key_env_value:
|
||||
description: "The API key"
|
||||
required: true
|
||||
UNLEASH_BOT_APP_ID:
|
||||
required: true
|
||||
UNLEASH_BOT_PRIVATE_KEY:
|
||||
required: true
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
@ -40,15 +44,27 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
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
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
ref: ${{ github.ref }}
|
||||
token: ${{ steps.app_token.outputs.token }}
|
||||
fetch-depth: 0
|
||||
persist-credentials: true
|
||||
|
||||
- name: Get issue
|
||||
uses: actions/github-script@v7
|
||||
id: get_issue
|
||||
with:
|
||||
github-token: ${{ steps.app_token.outputs.token }}
|
||||
script: |
|
||||
console.log('Fetching issue #${{ inputs.issue-number }}')
|
||||
const { owner, repo } = context.repo;
|
||||
@ -82,6 +98,7 @@ jobs:
|
||||
env:
|
||||
FLAG_NAME: ${{ steps.extract_flag.outputs.flag-name }}
|
||||
with:
|
||||
github-token: ${{ steps.app_token.outputs.token }}
|
||||
result-encoding: string
|
||||
script: |
|
||||
const kebab = (s) => s
|
||||
@ -120,14 +137,16 @@ jobs:
|
||||
- name: Check out new branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ steps.create_branch.outputs.result }}
|
||||
fetch-depth: 0
|
||||
ref: ${{ steps.create_branch.outputs.result }}
|
||||
token: ${{ steps.app_token.outputs.token }}
|
||||
fetch-depth: 0
|
||||
persist-credentials: true
|
||||
|
||||
- name: Configure Git
|
||||
run: |
|
||||
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.name "github-actions[bot]"
|
||||
git config --global user.email "194219037+unleash-bot[bot]@users.noreply.github.com"
|
||||
git config --global user.name "unleash-bot"
|
||||
|
||||
- name: Install ripgrep
|
||||
run: sudo apt-get update && sudo apt-get install -y ripgrep
|
||||
@ -145,49 +164,45 @@ jobs:
|
||||
echo "file_list=./file_list.bin" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create prompt
|
||||
uses: actions/github-script@v7
|
||||
id: create_prompt
|
||||
with:
|
||||
result-encoding: string
|
||||
script: |
|
||||
const body = `${{ fromJson(steps.get_issue.outputs.result).body }}`;
|
||||
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):
|
||||
|
||||
\`\`\`md
|
||||
=== AI Flag Cleanup Summary Start ===
|
||||
|
||||
## 🧹 AI Flag Cleanup Summary
|
||||
|
||||
(Short summary of the changes made)
|
||||
|
||||
(Include any details that you think are critical for the reviewer to know, if any, prefixing them with an appropriate emoji)
|
||||
|
||||
### 🚮 Removed
|
||||
- **(Category)**
|
||||
- (list of removed items)
|
||||
|
||||
### 🛠 Kept
|
||||
- **(Category)**
|
||||
- (list of kept items)
|
||||
|
||||
### 📝 Why
|
||||
(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 ===
|
||||
\`\`\`
|
||||
|
||||
|
||||
--- Issue Description ---
|
||||
${body}`;
|
||||
|
||||
- name: Write prompt
|
||||
run: |
|
||||
ISSUE_BODY="${{ fromJson(steps.get_issue.outputs.result).body }}"
|
||||
cat <<'EOF' > cleanup_prompt.txt
|
||||
${{ steps.create_prompt.outputs.result }}
|
||||
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):
|
||||
|
||||
\`\`\`md
|
||||
|
||||
=== AI Flag Cleanup Summary Start ===
|
||||
|
||||
## 🧹 AI Flag Cleanup Summary
|
||||
|
||||
(Short summary of the changes made)
|
||||
|
||||
(Include any details that you think are critical for the reviewer to know, if any, prefixing them with an appropriate emoji)
|
||||
|
||||
### 🚮 Removed
|
||||
- **(Category)**
|
||||
- (list of removed items)
|
||||
|
||||
### 🛠 Kept
|
||||
- **(Category)**
|
||||
- (list of kept items)
|
||||
|
||||
### 📝 Why
|
||||
(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 ===
|
||||
|
||||
\`\`\`
|
||||
|
||||
--- Issue Description ---
|
||||
$ISSUE_BODY
|
||||
EOF
|
||||
|
||||
echo "prompt-file=cleanup_prompt.txt" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
@ -202,10 +217,20 @@ jobs:
|
||||
id: run_aider
|
||||
timeout-minutes: ${{ inputs.chat-timeout }}
|
||||
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 }}
|
||||
run: |
|
||||
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
|
||||
|
||||
SUMMARY=$(sed -n '/=== AI Flag Cleanup Summary Start ===/,/=== AI Flag Cleanup Summary End ===/{
|
||||
@ -224,6 +249,7 @@ jobs:
|
||||
- name: Create Pull Request
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ steps.app_token.outputs.token }}
|
||||
result-encoding: string
|
||||
script: |
|
||||
const { owner, repo } = context.repo;
|
||||
@ -248,6 +274,8 @@ jobs:
|
||||
pull_number: existing.number,
|
||||
body
|
||||
});
|
||||
|
||||
console.log(`Updated PR #${existing.number}: ${existing.html_url}`);
|
||||
return existing;
|
||||
}
|
||||
|
||||
@ -268,5 +296,4 @@ jobs:
|
||||
});
|
||||
|
||||
console.log(`Created PR #${pr.number}: ${pr.html_url}`);
|
||||
|
||||
return pr;
|
||||
|
4
.github/workflows/ai-flag-cleanup.yml
vendored
4
.github/workflows/ai-flag-cleanup.yml
vendored
@ -21,4 +21,6 @@ jobs:
|
||||
model: gemini
|
||||
api_key_env_name: GEMINI_API_KEY
|
||||
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 }}
|
||||
|
Loading…
Reference in New Issue
Block a user