Skip to content

Commit 8688be1

Browse files
committed
Try different approach.
1 parent 0b69386 commit 8688be1

File tree

2 files changed

+69
-45
lines changed

2 files changed

+69
-45
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
ame: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "main"
8+
9+
jobs:
10+
test:
11+
name: Run tests & display coverage
12+
runs-on: ubuntu-latest
13+
permissions:
14+
# Gives the action the necessary permissions for publishing new
15+
# comments in pull requests.
16+
pull-requests: write
17+
# Gives the action the necessary permissions for pushing data to the
18+
# python-coverage-comment-action branch, and for editing existing
19+
# comments (to avoid publishing multiple comments in the same PR)
20+
contents: write
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Install everything, run the tests, produce the .coverage file
25+
run: |
26+
run coverage run -m pytest
27+
run coverage xml
28+
29+
- name: Coverage comment
30+
id: coverage_comment
31+
uses: py-cov-action/python-coverage-comment-action@v3
32+
with:
33+
GITHUB_TOKEN: ${{ github.token }}
34+
35+
- name: Store Pull Request comment to be posted
36+
uses: actions/upload-artifact@v4
37+
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
38+
with:
39+
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly
40+
name: python-coverage-comment-action
41+
# If you use a different name, update COMMENT_FILENAME accordingly
42+
path: python-coverage-comment-action.txt

.github/workflows/coverage.yml

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,35 @@
1-
name: Coverage
1+
name: Post coverage comment
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
workflow_dispatch:
8-
9-
env:
10-
PYTHON_VERSION: 3.11
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
118

129
jobs:
13-
generate-coverage:
10+
test:
11+
name: Run tests & display coverage
1412
runs-on: ubuntu-latest
15-
13+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
14+
permissions:
15+
# Gives the action the necessary permissions for publishing new
16+
# comments in pull requests.
17+
pull-requests: write
18+
# Gives the action the necessary permissions for editing existing
19+
# comments (to avoid publishing multiple comments in the same PR)
20+
contents: write
21+
# Gives the action the necessary permissions for looking up the
22+
# workflow that launched this workflow, and download the related
23+
# artifact that contains the comment to be published
24+
actions: read
1625
steps:
17-
- uses: actions/checkout@v3
18-
with:
19-
fetch-depth: 1
20-
21-
- name: Install Poetry
22-
run: |
23-
pipx install poetry
24-
poetry config virtualenvs.path ~/.virtualenvs${{ env.PYTHON_VERSION }}
25-
26-
- name: Set up Python ${{ env.PYTHON_VERSION }}
27-
uses: actions/setup-python@v3
26+
# DO NOT run actions/checkout here, for security reasons
27+
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
28+
- name: Post comment
29+
uses: py-cov-action/python-coverage-comment-action@v3
2830
with:
29-
python-version: ${{ env.PYTHON_VERSION }}
30-
cache: "poetry"
31-
32-
- name: Install dependencies
33-
run: poetry install -E minify
34-
35-
- name: Generate coverage badge
36-
run: |
37-
chmod +x generate_badge.sh
38-
./generate_badge.sh
39-
40-
- name: Commit and push coverage badge
41-
continue-on-error: true
42-
env:
4331
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
run: |
45-
git config --global user.name "github-actions[bot]"
46-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
47-
git config pull.rebase true
48-
git checkout -b py-code-coverage || git checkout py-code-coverage
49-
git pull origin py-code-coverage
50-
git add .
51-
git commit --verbose -m "Update coverage badge"
52-
git rebase --strategy-option=ours py-code-coverage --verbose
53-
git push --verbose origin py-code-coverage
32+
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
33+
# Update those if you changed the default values:
34+
# COMMENT_ARTIFACT_NAME: python-coverage-comment-action
35+
# COMMENT_FILENAME: python-coverage-comment-action.txt

0 commit comments

Comments
 (0)