-
Notifications
You must be signed in to change notification settings - Fork 240
feat: codecov override with merge squash hash #2371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
35857cf
feat: ci codecov
SkArchon 9fa697a
fix: updates
SkArchon 951a031
fix: updates
SkArchon e25578b
fix: flag update
SkArchon 2b0a1fa
fix: updates
SkArchon d78a79b
fix: add router
SkArchon 7a4f4ab
fix: add router
SkArchon 2d97285
fix: test merge hash
SkArchon df1b4cf
fix: testing
SkArchon bffcc81
fix: router tests
SkArchon 17b63d3
fix: router updates
SkArchon 3396b25
fix: revert
SkArchon a74f748
fix: updates
SkArchon 472ca22
fix: specify branch
SkArchon 01c9157
fix: changes to ci
SkArchon b0e90a1
fix: update status
SkArchon 7e81751
fix: upload
SkArchon d7e9ee4
fix: proper upload
SkArchon 9e63709
fix: update workflow
SkArchon be4fbad
fix: sanitized
SkArchon 34639a3
updates
SkArchon b762eb1
fix: refactoring
SkArchon 1ef9acd
fix: refactoring
SkArchon ae33c06
fix: rabbit review
SkArchon 156b3e2
fix: comments
SkArchon 7ce3c62
fix: cli workflow
SkArchon aa75820
Merge branch 'main' into milinda/merge-codecov
SkArchon 266ceac
Merge branch 'main' into milinda/merge-codecov
SkArchon 1f0ce6f
fix: when there are no artifacts
SkArchon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: 'Codecov Download and Upload' | ||
| description: 'Download coverage artifact from previous PR run and upload 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 | ||
| workflow-path: | ||
| description: 'Path to workflow file for artifact lookup' | ||
| required: true | ||
| override-commit: | ||
| description: 'Commit SHA to override in Codecov' | ||
| required: true | ||
| 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 run for this commit | ||
| id: find-run | ||
| shell: bash | ||
| env: | ||
| GITHUB_TOKEN: ${{ inputs.github-token }} | ||
| REPO: ${{ github.repository }} | ||
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
| CURRENT_RUN_ID: ${{ github.run_id }} | ||
| ARTIFACT_NAME: ${{ inputs.artifact-name }} | ||
| WORKFLOW_PATH: ${{ inputs.workflow-path }} | ||
| run: ./.github/scripts/find-codecov-artifact.sh | ||
|
|
||
| - name: Download coverage artifact from previous run | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: ${{ inputs.artifact-name }} | ||
| run-id: ${{ steps.find-run.outputs.run_id }} | ||
| github-token: ${{ inputs.github-token }} | ||
| path: ${{ inputs.coverage-path }} | ||
|
|
||
| - name: Upload results to Codecov | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| token: ${{ inputs.codecov-token }} | ||
| override_commit: ${{ inputs.override-commit }} | ||
| override_branch: main | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| 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 }} | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This script finds the latest successful workflow run artifact for a PR commit. | ||
| # | ||
| # Required environment variables: | ||
| # REPO: GitHub repository (e.g., owner/repo) | ||
| # HEAD_SHA: The PR head commit SHA | ||
| # CURRENT_RUN_ID: The current workflow run ID | ||
| # ARTIFACT_NAME: Name of the artifact to find | ||
| # WORKFLOW_PATH: Path to the workflow file to filter by | ||
| # GITHUB_TOKEN: Required for API authentication | ||
| # | ||
| # Outputs (to $GITHUB_OUTPUT): | ||
| # run_id: The workflow run ID containing the artifact | ||
| # artifact_id: The artifact ID | ||
|
|
||
| REPO="${REPO:?REPO environment variable is required}" | ||
| HEAD_SHA="${HEAD_SHA:?HEAD_SHA environment variable is required}" | ||
| CURRENT_RUN_ID="${CURRENT_RUN_ID:?CURRENT_RUN_ID environment variable is required}" | ||
| ARTIFACT_NAME="${ARTIFACT_NAME:?ARTIFACT_NAME environment variable is required}" | ||
| WORKFLOW_PATH="${WORKFLOW_PATH:?WORKFLOW_PATH environment variable is required}" | ||
|
|
||
| echo "Head SHA: $HEAD_SHA" | ||
| echo "Current run id: $CURRENT_RUN_ID" | ||
|
|
||
| # Get all PR runs for this commit (since its runs per Sha 500 should be enough for now) | ||
| json=$(curl -sf \ | ||
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "https://api.github.com/repos/$REPO/actions/runs?head_sha=$HEAD_SHA&event=pull_request&per_page=500") | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "Failed to fetch workflow runs" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Pick the latest *completed & successful* run that is NOT this run | ||
| run_id=$(echo "$json" | jq -r --arg cur "$CURRENT_RUN_ID" --arg workflow "$WORKFLOW_PATH" ' | ||
| .workflow_runs | ||
| | map(select( | ||
| .id != ($cur|tonumber) | ||
| and .status == "completed" | ||
| and .conclusion == "success" | ||
| and .path == $workflow | ||
| )) | ||
| | sort_by(.created_at) | ||
| | last | ||
| | .id | ||
| ') | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "Failed to parse workflow runs JSON" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "$run_id" ] || [ "$run_id" = "null" ]; then | ||
| echo "No previous successful PR run found for $HEAD_SHA" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Using run id: $run_id" | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # Get artifacts for that run | ||
| artifacts_json=$(curl -s \ | ||
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| "https://api.github.com/repos/$REPO/actions/runs/$run_id/artifacts") | ||
|
|
||
| # Find the artifact ID for the desired artifact name | ||
| artifact_id=$(echo "$artifacts_json" | jq -r --arg name "$ARTIFACT_NAME" ' | ||
| .artifacts | ||
| | map(select(.name == $name and .expired == false)) | ||
| | sort_by(.created_at) | ||
| | last | ||
| | .id | ||
| ') | ||
|
|
||
| if [ -z "$artifact_id" ] || [ "$artifact_id" = "null" ]; then | ||
| echo "No non-expired artifact named '$ARTIFACT_NAME' found for run $run_id" >&2 | ||
| echo "Artifacts JSON for debugging:" >&2 | ||
| echo "$artifacts_json" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Using artifact id: $artifact_id" | ||
|
|
||
| echo "run_id=$run_id" >> "$GITHUB_OUTPUT" | ||
| echo "artifact_id=$artifact_id" >> "$GITHUB_OUTPUT" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.