Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/actions/codecov-merge-upload/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 'Codecov Download and Upload'
description: 'Download coverage artifacts from previous PR runs and upload to Codecov'

inputs:
coverage-path:
description: 'Path to coverage files'
required: true
workflow-paths:
description: 'Comma-separated list of workflow paths for artifact lookup (e.g., ".github/workflows/router-ci.yaml,.github/workflows/cli-ci.yaml")'
required: true
override-commit:
description: 'Commit SHA to override in Codecov'
required: true
merge-commit-sha:
description: 'Merge commit SHA to look up the PR and find head SHA'
required: false
default: ''
codecov-token:
description: 'Codecov token for uploading'
required: true
github-token:
description: 'GitHub token for artifact operations'
required: true

runs:
using: 'composite'
steps:
- name: Find latest successful PR runs for this commit
id: find-artifacts
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
REPO: ${{ github.repository }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
MERGE_COMMIT_SHA: ${{ inputs.merge-commit-sha }}
CURRENT_RUN_ID: ${{ github.run_id }}
ARTIFACT_NAME_PATTERN: codecov
WORKFLOW_PATHS: ${{ inputs.workflow-paths }}
run: ./.github/scripts/find-codecov-artifact.sh
Comment thread
coderabbitai[bot] marked this conversation as resolved.

- name: Download coverage artifacts
if: steps.find-artifacts.outputs.has_artifacts == 'true'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
REPO: ${{ github.repository }}
ARTIFACTS_JSON: ${{ steps.find-artifacts.outputs.artifacts_json }}
COVERAGE_PATH: ${{ inputs.coverage-path }}
run: ./.github/scripts/download-codecov-artifacts.sh

- name: Upload results to Codecov
if: steps.find-artifacts.outputs.has_artifacts == 'true'
uses: codecov/codecov-action@v5
with:
token: ${{ inputs.codecov-token }}
override_commit: ${{ inputs.override-commit }}
override_branch: main
directory: ${{ inputs.coverage-path }}
34 changes: 34 additions & 0 deletions .github/actions/codecov-upload-pr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Codecov Upload PR'
description: 'Upload coverage artifacts during PR and send to Codecov'

inputs:
artifact-name:
description: 'Name of the coverage artifact'
required: false
default: 'pr-build'
coverage-path:
description: 'Path to coverage files'
required: true
retention-days:
description: 'Days to retain the artifact'
required: false
default: '7'
codecov-token:
description: 'Codecov token for uploading'
required: true

runs:
using: 'composite'
steps:
- name: Upload artifact for PR
uses: actions/upload-artifact@v4
with:
overwrite: true
name: codecov-pr-build-${{ inputs.artifact-name }}
path: ${{ inputs.coverage-path }}
retention-days: ${{ inputs.retention-days }}

- name: Upload results to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ inputs.codecov-token }}
52 changes: 52 additions & 0 deletions .github/scripts/download-codecov-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# This script downloads coverage artifacts from GitHub Actions runs.
#
# Required environment variables:
# GITHUB_TOKEN: Required for GitHub CLI authentication
# REPO: GitHub repository (e.g., owner/repo)
# ARTIFACTS_JSON: JSON array of artifacts to download (from find-codecov-artifact.sh output)
# COVERAGE_PATH: Directory where artifacts should be downloaded
#

set -e

GITHUB_TOKEN="${GITHUB_TOKEN:?GITHUB_TOKEN environment variable is required}"
REPO="${REPO:?REPO environment variable is required}"
ARTIFACTS_JSON="${ARTIFACTS_JSON:?ARTIFACTS_JSON environment variable is required}"
COVERAGE_PATH="${COVERAGE_PATH:?COVERAGE_PATH environment variable is required}"

echo "Downloading artifacts..."

# Validate JSON before processing
if ! echo "$ARTIFACTS_JSON" | jq empty 2>/dev/null; then
echo "ERROR: Invalid JSON received from artifact discovery step" >&2
echo "JSON content (truncated to 500 chars):" >&2
echo "$ARTIFACTS_JSON" | head -c 500 >&2
echo "" >&2
exit 1
fi

echo "$ARTIFACTS_JSON" | jq -c '.[]' | while read -r artifact; do
run_id=$(echo "$artifact" | jq -r '.run_id')
artifact_id=$(echo "$artifact" | jq -r '.artifact_id')
artifact_name=$(echo "$artifact" | jq -r '.artifact_name')

echo "Downloading artifact: $artifact_name (ID: $artifact_id) from run: $run_id"

# Download artifact using GitHub CLI
gh run download "$run_id" \
--repo "$REPO" \
--name "$artifact_name" \
--dir "$COVERAGE_PATH/$artifact_name"

if [ $? -eq 0 ]; then
echo "✓ Successfully downloaded $artifact_name"
else
echo "✗ Failed to download $artifact_name" >&2
exit 1
fi
done

echo "All artifacts downloaded successfully"

Loading
Loading