feat(ci): use slack block kit with install command

This commit is contained in:
Greyson Lalonde
2026-03-13 02:41:52 -04:00
parent 29ef733dea
commit 2e2c645286

View File

@@ -94,35 +94,65 @@ jobs:
exit 1 exit 1
fi fi
- name: Extract version and release notes - name: Build Slack payload
if: success() if: success()
id: release-info id: slack
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ inputs.release_tag }}
run: | run: |
version=$(uv run python -c "import re; m = re.search(r'__version__\s*=\s*[\"\\x27]([^\"\\x27]+)', open('lib/crewai/src/crewai/__init__.py').read()); print(m.group(1))") payload=$(uv run python -c "
echo "version=$version" >> $GITHUB_OUTPUT import json, re, subprocess, sys
tag="${{ inputs.release_tag }}" with open('lib/crewai/src/crewai/__init__.py') as f:
if [ -z "$tag" ]; then m = re.search(r\"__version__\s*=\s*[\\\"']([^\\\"']+)\", f.read())
tag="$version" version = m.group(1) if m else 'unknown'
fi
# Fetch release body and convert GitHub markdown to Slack mrkdwn import os
notes=$(gh release view "$tag" --json body -q '.body' 2>/dev/null || echo "") tag = os.environ.get('RELEASE_TAG') or version
if [ -n "$notes" ]; then
notes=$(echo "$notes" \
| sed 's/^### \(.*\)/*\1*/g' \
| sed 's/^## \(.*\)/*\1*/g' \
| sed 's/\*\*\([^*]*\)\*\*/*\1*/g' \
| sed 's/^- /• /g')
fi
# Build JSON payload with proper escaping via jq try:
payload=$(jq -nc \ r = subprocess.run(['gh','release','view',tag,'--json','body','-q','.body'],
--arg version "$version" \ capture_output=True, text=True, check=True)
--arg notes "$notes" \ body = r.stdout.strip()
'{text: ":rocket: *crewAI v\($version)* published to <https://pypi.org/project/crewai/\($version)/|PyPI>\n\n\($notes)"}') except Exception:
body = ''
blocks = [
{'type':'section','text':{'type':'mrkdwn',
'text':f':rocket: \`crewai v{version}\` published to PyPI'}},
{'type':'section','text':{'type':'mrkdwn',
'text':f'<https://pypi.org/project/crewai/{version}/|View on PyPI> · <https://github.com/crewAIInc/crewAI/releases/tag/{version}|Release notes>'}},
{'type':'divider'},
]
if body:
heading, items = '', []
for line in body.split('\n'):
line = line.strip()
if not line: continue
hm = re.match(r'^#{2,3}\s+(.*)', line)
if hm:
if heading and items:
skip = heading in ('What\\'s Changed','') or 'Contributors' in heading
if not skip:
txt = f'*{heading}*\n' + '\n'.join(f'• {i}' for i in items)
blocks.append({'type':'section','text':{'type':'mrkdwn','text':txt}})
heading, items = hm.group(1), []
elif line.startswith('- '):
items.append(re.sub(r'\*\*([^*]*)\*\*', r'*\1*', line[2:]))
if heading and items:
skip = heading in ('What\\'s Changed','') or 'Contributors' in heading
if not skip:
txt = f'*{heading}*\n' + '\n'.join(f'• {i}' for i in items)
blocks.append({'type':'section','text':{'type':'mrkdwn','text':txt}})
blocks.append({'type':'divider'})
blocks.append({'type':'section','text':{'type':'mrkdwn',
'text':f'\`\`\`uv add \"crewai[tools]=={version}\"\`\`\`'}})
print(json.dumps({'blocks':blocks}))
")
echo "payload=$payload" >> $GITHUB_OUTPUT echo "payload=$payload" >> $GITHUB_OUTPUT
- name: Notify Slack - name: Notify Slack
@@ -131,4 +161,4 @@ jobs:
with: with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }} webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook webhook-type: incoming-webhook
payload: ${{ steps.release-info.outputs.payload }} payload: ${{ steps.slack.outputs.payload }}