agent-orchestrator/.github/workflows/coverage.yml

112 lines
3.6 KiB
YAML

name: PR Coverage Report
on:
pull_request:
branches: [main]
concurrency:
group: coverage-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
coverage:
name: Coverage Report
runs-on: ubuntu-latest
# Non-blocking: never prevent merging even if this job fails
continue-on-error: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install tmux
run: sudo apt-get update && sudo apt-get install -y tmux
- name: Start tmux server
run: tmux start-server
- run: pnpm install --frozen-lockfile
- name: Build packages
run: pnpm -r --filter '!@composio/ao-web' build
- name: Get changed files
env:
BASE_REF: ${{ github.base_ref }}
run: |
git diff --name-only origin/$BASE_REF...HEAD -- '*.ts' '*.tsx' > changed-files.txt
echo "Changed TS files:"
cat changed-files.txt
- name: Run tests with coverage
continue-on-error: true
run: |
CHANGED=$(cat changed-files.txt)
# Only run coverage for packages that have changed files
if echo "$CHANGED" | grep -q '^packages/core/'; then
echo "::group::Core tests"
pnpm --filter @composio/ao-core exec vitest run --coverage.enabled --coverage.reporter=json || true
echo "::endgroup::"
fi
if echo "$CHANGED" | grep -q '^packages/cli/'; then
echo "::group::CLI tests"
pnpm --filter @composio/ao-cli exec vitest run --coverage.enabled --coverage.reporter=json || true
echo "::endgroup::"
fi
if echo "$CHANGED" | grep -q '^packages/web/'; then
echo "::group::Web tests"
pnpm --filter @composio/ao-web exec vitest run --coverage.enabled --coverage.reporter=json || true
echo "::endgroup::"
fi
if echo "$CHANGED" | grep -q '^packages/plugins/'; then
# Run coverage for each changed plugin
for plugin_dir in $(echo "$CHANGED" | grep '^packages/plugins/' | cut -d/ -f1-3 | sort -u); do
if [ -f "$plugin_dir/package.json" ]; then
pkg_name=$(node -e "console.log(require('./$plugin_dir/package.json').name)")
echo "::group::$pkg_name tests"
pnpm --filter "$pkg_name" exec vitest run --coverage.enabled --coverage.reporter=json || true
echo "::endgroup::"
fi
done
fi
- name: Generate coverage report
run: node .github/scripts/coverage-report.mjs
- name: Post or update PR comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
REPO=${{ github.repository }}
COMMENT_TAG="<!-- coverage-report -->"
# Find existing coverage comment
COMMENT_ID=$(gh api "repos/$REPO/issues/$PR_NUMBER/comments" \
--paginate --jq ".[] | select(.body | startswith(\"$COMMENT_TAG\")) | .id" \
| tail -1)
if [ -n "$COMMENT_ID" ]; then
gh api "repos/$REPO/issues/comments/$COMMENT_ID" \
-X PATCH \
-F body=@coverage-comment.md
echo "Updated existing comment $COMMENT_ID"
else
gh pr comment "$PR_NUMBER" --body-file coverage-comment.md
echo "Created new comment"
fi