You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 85ee719
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+20-8Lines changed: 20 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Upload a Cobertura XML coverage report to GitHub's code coverage API.
12
12
label: code-coverage/jacoco
13
13
```
14
14
15
-
The action handles everything else automatically: gzip/base64 encoding, resolving the correct commit SHA and ref, detecting PR number (from both `pull_request` and `push` events), and calling the upload API.
15
+
The action handles everything else automatically: event routing, gzip/base64 encoding, resolving the correct commit SHA and ref, detecting PR numbers from both `pull_request` and `push` events, and calling the upload API.
16
16
17
17
## Inputs
18
18
@@ -35,7 +35,7 @@ permissions:
35
35
code-quality: write
36
36
```
37
37
38
-
For push-only workflows where the action looks up PR numbers via `gh pr list`, also add `pull-requests: read`.
38
+
For push-only workflows where the action looks up PR numbers, also add `pull-requests: read`.
39
39
The runner must have the GitHub CLI installed. GitHub-hosted runners include it by default.
40
40
41
41
## Error handling
@@ -72,12 +72,26 @@ If you want the action to return immediately after the upload request instead of
72
72
73
73
## Event handling
74
74
75
-
The action auto-detects the event type and resolves the correct values:
75
+
The action auto-detects the event type and resolves the correct behavior:
76
76
77
-
- **`pull_request` / `pull_request_target`**: Uses the PR head SHA and ref (not the merge commit), and includes the PR number.
78
-
- **`push`**: Uses `github.sha` and `github.ref`, and looks up whether the branch has an open PR via `gh pr list`.
77
+
- **`pull_request` / `pull_request_target`**: Uses the PR head SHA (not the merge commit) and includes the PR number.
78
+
- **Default-branch `push`**: Uses `github.sha` and `github.ref`.
79
+
- **Non-default branch `push` with an open PR**: Looks up the PR number and uploads coverage for the pushed commit.
80
+
- **Non-default branch `push` without an open PR**: Skips successfully instead of sending an upload request the API cannot associate with a PR.
79
81
80
-
This means it works with both patterns — workflows triggered by `pull_request` and push-only workflows that serve PRs via branch pushes.
82
+
Configure workflows to run for pull requests and pushes to the default branch:
83
+
84
+
```yaml
85
+
on:
86
+
push:
87
+
branches: [main]
88
+
pull_request:
89
+
branches: [main]
90
+
```
91
+
92
+
Push-only workflows can upload PR coverage by granting `pull-requests: read`. Repositories may also use broader `push` triggers for other CI requirements; pushes without an open PR are skipped safely.
93
+
94
+
See [Choosing a workflow strategy](docs/workflow-strategies.md) for trigger and job layouts, or [Upgrading](docs/upgrading.md) for version and compatibility guidance.
echo "::warning::Skipping coverage upload for merge queue. Configure your workflow to upload coverage for PRs and the default branch instead. To avoid spinning up a runner, add \"if: github.event_name != 'merge_group'\" to the upload job."
49
-
exit 0
50
-
fi
51
-
52
-
if [ "${{ github.event.pull_request.head.repo.full_name }}" != "" ] && \
53
-
[ "${{ github.event.pull_request.head.repo.full_name }}" != "$GITHUB_REPOSITORY" ]; then
Review the [changelog](../CHANGELOG.md) before upgrading.
4
+
5
+
## Version references
6
+
7
+
Each release uses a complete semantic version tag such as `v1.4.3`. The corresponding major tag remains a supported movable alias:
8
+
9
+
```yaml
10
+
- uses: actions/upload-code-coverage@v1
11
+
```
12
+
13
+
Workflows using `v1` receive new `v1.x.x` releases when the major tag advances. Workflows pinned to a complete version or commit SHA must update that reference explicitly.
14
+
15
+
## Compatibility
16
+
17
+
Existing workflows can upgrade without changing their triggers, job layout, action inputs, or permissions.
18
+
19
+
Push-only workflows should keep `pull-requests: read` so the action can discover an open pull request for a pushed branch. For a non-default branch push without an open pull request, the action now skips successfully instead of attempting an upload that the API rejects.
The action supports different trigger and job layouts. Choose the one that best fits your CI workflow.
4
+
5
+
## Pull requests and default-branch pushes
6
+
7
+
For most repositories, run coverage for pull requests and pushes to the default branch:
8
+
9
+
```yaml
10
+
on:
11
+
pull_request:
12
+
push:
13
+
branches: [main]
14
+
```
15
+
16
+
This avoids running coverage for branches that do not have a pull request. Pull request events also provide the PR number directly, so the upload job does not need `pull-requests: read`.
17
+
18
+
## Push-only workflows
19
+
20
+
Some workflows use `push` events to run tests on every branch, without a `pull_request` trigger. This trigger strategy works with either the separate-job or same-job layout described below.
21
+
22
+
In a separate-job layout, the test job generates the report and the upload job receives it through an artifact on every push. The action then determines whether the report can be uploaded:
23
+
24
+
- Default-branch pushes upload normally.
25
+
- Pushes with an open pull request upload using the discovered PR number.
26
+
- Pushes without an open pull request skip successfully.
27
+
28
+
If a branch is pushed before its pull request is opened, coverage is not uploaded until the next push. To upload coverage when a pull request is opened without requiring another push, use a `pull_request` trigger.
29
+
30
+
Push-only workflows have an existing requirement to grant the upload job `pull-requests: read`:
31
+
32
+
```yaml
33
+
permissions:
34
+
contents: read
35
+
code-quality: write
36
+
pull-requests: read
37
+
```
38
+
39
+
See the [README permissions section](../README.md#permissions) for the complete requirements, including GitHub CLI availability.
40
+
41
+
## Separate upload job
42
+
43
+
A separate upload job keeps `code-quality: write` away from the job that runs repository code and third-party dependencies. Because jobs have isolated filesystems, pass the coverage report between them with `actions/upload-artifact` and `actions/download-artifact`.
44
+
45
+
It also allows the test job to run independently when the upload job is skipped. This is the recommended layout.
46
+
47
+
## Same-job upload
48
+
49
+
For a simpler workflow, generate and upload the report in the same job:
50
+
51
+
```yaml
52
+
permissions:
53
+
contents: read
54
+
code-quality: write
55
+
56
+
steps:
57
+
# ... generate cobertura.xml ...
58
+
59
+
- uses: actions/upload-code-coverage@v1
60
+
with:
61
+
file: cobertura.xml
62
+
language: Java
63
+
label: code-coverage/jacoco
64
+
```
65
+
66
+
No artifact transfer is needed, but the job that runs tests also receives `code-quality: write`. If the job runs on every push, tests still run before the action decides whether to upload or skip. Applying an event condition to the entire job instead would skip both testing and uploading.
67
+
68
+
## Avoiding duplicate runs
69
+
70
+
A workflow with broad `push` and `pull_request` triggers may run twice for the same pull request commit. To avoid that, either:
71
+
72
+
- Use `pull_request` plus default-branch `push`; or
73
+
- Use a push-only workflow with `pull-requests: read`.
74
+
75
+
## Multiple reports
76
+
77
+
Call the action once for each report and use a distinct `label`:
0 commit comments