Skip to content

Commit

Permalink
Unrelated doc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Jul 23, 2023
1 parent 9835b20 commit d349c12
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ badge to your Readme will be displayed in:
- The text output of the workflow run

### Basic usage

```yaml
# .github/workflows/ci.yml
name: CI
Expand All @@ -78,7 +79,7 @@ on:
pull_request:
push:
branches:
- 'main'
- "main"

jobs:
test:
Expand All @@ -96,7 +97,7 @@ jobs:
- uses: actions/checkout@v3

- name: Install everything, run the tests, produce the .coverage file
run: make test # This is the part where you put your own test command
run: make test # This is the part where you put your own test command

- name: Coverage comment
id: coverage_comment
Expand All @@ -114,6 +115,11 @@ jobs:
path: python-coverage-comment-action.txt
```
The "Store Pull Request comment to be posted" step as well as the file below
are only needed in contexts where some contributors don't have write access to
the repository. In closed-source context, it's likely that all contributors
have write-access (i.e. nobody uses forks), you can remove both.
```yaml
# .github/workflows/coverage.yml
name: Post coverage comment
Expand Down Expand Up @@ -166,9 +172,9 @@ on:
pull_request:
push:
branches:
- 'master'
- "master"
tags:
- '*'
- "*"

jobs:
build:
Expand All @@ -193,7 +199,7 @@ jobs:
python-version: ${{ matrix.python_version }}

- name: Install everything, run the tests, produce a .coverage.xxx file
run: make test # This is the part where you put your own test command
run: make test # This is the part where you put your own test command
env:
COVERAGE_FILE: ".coverage.${{ matrix.python_version }}"
# Alternatively you can run coverage with the --parallel flag or add
Expand All @@ -220,7 +226,7 @@ jobs:
- uses: actions/download-artifact@v3
id: download
with:
name: 'coverage'
name: "coverage"

- name: Coverage comment
id: coverage_comment
Expand All @@ -235,10 +241,10 @@ jobs:
with:
name: python-coverage-comment-action
path: python-coverage-comment-action.txt

```
### All options
```yaml
- name: Display coverage
id: coverage_comment
Expand Down Expand Up @@ -302,18 +308,18 @@ By default, comments are generated from a
[Jinja](https://jinja.palletsprojects.com) template that you can read
[here](https://github.com/py-cov-action/python-coverage-comment-action/blob/v3/coverage_comment/template_files/comment.md.j2).
If you want to change this template, you can set ``COMMENT_TEMPLATE``. This is
If you want to change this template, you can set `COMMENT_TEMPLATE`. This is
an advanced usage, so you're likely to run into more road bumps.

You will need to follow some rules for your template to be valid:

- Your template needs to be syntactically correct with Jinja2 rules
- You may define a new template from scratch, but in this case you are required
to include ``{{ marker }}``, which includes an HTML comment (invisible on
to include `{{ marker }}`, which includes an HTML comment (invisible on
GitHub) that the action uses to identify its own comments.
- If you'd rather want to change parts of the default template, you can do so
by starting your comment with ``{% extends "base" %}``, and then override the
blocks (``{% block foo %}``) that you wish to change. If you're unsure how it
by starting your comment with `{% extends "base" %}`, and then override the
blocks (`{% block foo %}`) that you wish to change. If you're unsure how it
works, see [the Jinja
documentation](https://jinja.palletsprojects.com/en/3.0.x/templates/#template-inheritance)
- In either case, you will most likely want to get yourself familiar with the
Expand All @@ -322,6 +328,7 @@ You will need to follow some rules for your template to be valid:
Should those variables change, we'll do our best to bump the action's major version.

### Examples

In the first example, we change the emoji that illustrates coverage going down from
`:down_arrow:` to `:sob:`:

Expand Down Expand Up @@ -435,7 +442,9 @@ jobs:
```

# Other topics

## Pinning

On the examples above, the version was set to `v3` (a branch). You can also pin
a specific version such as `v3.0.0` (a tag). There are still things left to
figure out in how to manage releases and version. If you're interested, please
Expand Down Expand Up @@ -466,7 +475,6 @@ a brand new action (this action) was created.
You can find the (unmaintained) language-generic version
[here](https://github.com/marketplace/actions/coverage-comment).


## Why do we need `relative_files = true` ?

Yes, I agree, this is annoying! The reason is that by default, coverage writes
Expand All @@ -483,9 +491,11 @@ anymore.
## .coverage file generated on a Windows file system

If your project's coverage was built on Windows, you may get an error like:

```
CoverageWarning: Couldn't parse 'yourproject\__init__.py': No source for code: 'yourproject\__init__.py'. (couldnt-parse)
```

This is likely due to coverage being confused with the coverage being computed with `\` but read with `/`. You can most probably fix it with the following in your [coverage configuration](https://coverage.readthedocs.io/en/latest/config.html):

```
Expand Down
13 changes: 8 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Python Coverage Comment
branding:
icon: 'umbrella'
color: 'purple'
icon: "umbrella"
color: "purple"
description: >
Publish diff coverage report as PR comment, and create a coverage badge
to display on the readme.
Expand Down Expand Up @@ -74,7 +74,7 @@ inputs:
default: false
ANNOTATION_TYPE:
description: >
Only needed if ANNOTATE_MISSING_LINES is set to true. This parameter allows you to choose between
Only relevant if ANNOTATE_MISSING_LINES is set to true. This parameter allows you to choose between
notice, warning and error as annotation type. For more information look here:
https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-notice-message
default: warning
Expand All @@ -85,8 +85,10 @@ inputs:
outputs:
COMMENT_FILE_WRITTEN:
description: >
If "true", a comment file was written to COMMENT_FILENAME. If "false",
no comment file was written (because the comment was already posted).
Only set when running in PR mode. If "true", a comment file was written
to COMMENT_FILENAME and you'll need to run the action in workflow_run
mode to post it. If "false", no comment file was written (because the
comment was already posted to the PR).
runs:
using: docker
image: Dockerfile
Expand All @@ -97,6 +99,7 @@ runs:
COVERAGE_DATA_BRANCH: ${{ inputs.COVERAGE_DATA_BRANCH }}
COMMENT_ARTIFACT_NAME: ${{ inputs.COMMENT_ARTIFACT_NAME }}
COMMENT_FILENAME: ${{ inputs.COMMENT_FILENAME }}
SUBPROJECT_ID: ${{ inputs.SUBPROJECT_ID }}
MINIMUM_GREEN: ${{ inputs.MINIMUM_GREEN }}
MINIMUM_ORANGE: ${{ inputs.MINIMUM_ORANGE }}
MERGE_COVERAGE_FILES: ${{ inputs.MERGE_COVERAGE_FILES }}
Expand Down

0 comments on commit d349c12

Please sign in to comment.