Skip to content

Commit a31ccce

Browse files
vinaysettyNoB0
andauthored
Feature/11 update pre commit and ci in template (#12)
* Updates pre-commit and CI. * Uloads coverage results. * Updates pre-commit config and CI yaml files. * Removing Spacy * Adds a dummy test. * Adds README for setting up CI. * Adds README for setting up CI. * Removes spacy. * Updates README. * Adds coverage badge to README.md * Update README.md * Update README.md * Update README.md Co-authored-by: Nolwenn Bernard <28621493+NoB0@users.noreply.github.com> * Update README.md Co-authored-by: Nolwenn Bernard <28621493+NoB0@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Nolwenn Bernard <28621493+NoB0@users.noreply.github.com> * Removing duplicate comment in PR * Cleaning up CI setup and removing harcoded username and gist id * Renames build-and-test to pre-commit-and-test * Updating README.md comments * Updating README.md comments * Moved CI setup guide to docs. * Updates README with CI_setup.md * Fix nit comments. * Update README for GIST_OWNER. --------- Co-authored-by: Nolwenn Bernard <28621493+NoB0@users.noreply.github.com>
1 parent d327f42 commit a31ccce

File tree

10 files changed

+407
-73
lines changed

10 files changed

+407
-73
lines changed

.github/workflows/ci.yaml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
on:
2+
pull_request:
3+
types:
4+
- opened
5+
- reopened
6+
- synchronize
7+
paths-ignore:
8+
- "**.md"
9+
10+
env:
11+
REPO_NAME: ${{ github.event.repository.name }}
12+
13+
name: CI
14+
15+
jobs:
16+
pre-commit-and-test:
17+
if: always()
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 60
20+
steps:
21+
- name: Get branch name
22+
id: branch-name
23+
uses: tj-actions/branch-names@v7.0.7
24+
25+
- uses: actions/checkout@v3
26+
with:
27+
fetch-depth: 0
28+
ref: ${{ github.event.pull_request.head.sha }}
29+
30+
- name: Setup python
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: 3.9
34+
cache: "pip"
35+
cache-dependency-path: requirements.txt
36+
37+
- name: Install Dependencies
38+
run: |
39+
pip install --upgrade pip
40+
pip install -r requirements.txt
41+
42+
- name: Run black
43+
shell: bash
44+
run: pre-commit run black --all-files
45+
46+
- name: Run flake8
47+
shell: bash
48+
run: pre-commit run flake8 --all-files
49+
50+
- name: Run docformatter
51+
shell: bash
52+
run: pre-commit run docformatter --all-files
53+
54+
- name: Run pydocstyle
55+
shell: bash
56+
run: pre-commit run pydocstyle --all-files
57+
58+
- name: Run mypy
59+
shell: bash
60+
run: pre-commit run mypy --all-files
61+
62+
- name: Run pytest with code coverage
63+
run: |
64+
pytest --junitxml pytest.xml --cov=. --cov-report=term-missing --cov-report=xml:coverage.xml --cov-branch | tee pytest-coverage.txt
65+
66+
- name: Upload Coverage Results
67+
uses: actions/upload-artifact@v3
68+
with:
69+
name: coverage-results
70+
path: coverage.xml
71+
if: ${{ always() }}
72+
73+
- name: Upload Unit Test Results
74+
if: always()
75+
uses: actions/upload-artifact@v3
76+
with:
77+
name: unit-test-py39
78+
path: pytest.xml
79+
80+
- name: Upload Unit Test Results
81+
if: always()
82+
uses: actions/upload-artifact@v3
83+
with:
84+
name: unit-test-py39
85+
path: pytest-coverage.txt
86+
87+
publish-test-results:
88+
name: "Publish Unit Tests Results"
89+
needs: pre-commit-and-test
90+
runs-on: ubuntu-latest
91+
if: always()
92+
timeout-minutes: 20
93+
94+
steps:
95+
- name: Download Artifacts
96+
uses: actions/download-artifact@v3
97+
with:
98+
name: unit-test-py39
99+
path: unit-test-py39
100+
101+
- name: Download coverage report
102+
uses: actions/download-artifact@v3
103+
with:
104+
name: coverage-results
105+
106+
- name: Pytest coverage comment in pull-request
107+
uses: MishaKav/pytest-coverage-comment@main
108+
with:
109+
default-branch: main
110+
pytest-coverage-path: unit-test-py39/pytest-coverage.txt
111+
junitxml-path: unit-test-py39/pytest.xml
112+
hide-badge: true
113+
hide-report: false
114+
create-new-comment: false
115+
hide-comment: false
116+
report-only-changed-files: true
117+
118+
- name: Get the Coverage
119+
shell: bash
120+
run: |
121+
regex='<coverage.+line-rate="([0-9).[0-9]+)".+>'
122+
line=$(grep -oP $regex coverage.xml)
123+
[[ $line =~ $regex ]]
124+
coverage=$( bc <<< ${BASH_REMATCH[1]}*100 )
125+
if (( $(echo "$coverage > 90" |bc -l) )); then
126+
COLOR=green
127+
else
128+
COLOR=red
129+
fi
130+
echo "COVERAGE=${coverage%.*}%" >> $GITHUB_ENV
131+
echo "COLOR=$COLOR" >> $GITHUB_ENV
132+
133+
- name: Create Coverage Badge
134+
uses: schneegans/dynamic-badges-action@v1.7.0
135+
with:
136+
auth: ${{ secrets.GIST_SECRET }}
137+
gistID: ${{ secrets.GIST_ID }}
138+
filename: coverage.${{ env.REPO_NAME }}.${{ github.event.number }}.json
139+
label: coverage
140+
message: ${{ env.COVERAGE }}
141+
color: ${{ env.COLOR }}
142+
143+
- name: Find Comment
144+
uses: peter-evans/find-comment@v2
145+
id: fc
146+
with:
147+
issue-number: ${{ github.event.pull_request.number }}
148+
comment-author: "github-actions[bot]"
149+
body-includes: Current Branch | Main Branch
150+
151+
- name: Create coverage comment
152+
uses: peter-evans/create-or-update-comment@v2
153+
with:
154+
comment-id: ${{ steps.fc.outputs.comment-id }}
155+
issue-number: ${{ github.event.pull_request.number }}
156+
reactions: eyes
157+
body: |
158+
Current Branch | Main Branch |
159+
| ------ | ------ |
160+
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/${{ env.GIST_OWNER }}/${{ secrets.GIST_ID }}/raw/coverage.${{ env.REPO_NAME }}.${{ github.event.number }}.json) | ![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/${{ github.repository_owner }}/${{ secrets.GIST_ID }}/raw/coverage.${{ env.REPO_NAME }}.main.json) |
161+
edit-mode: replace
162+

.github/workflows/merge.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Deploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
pre-commit-and-test:
9+
name: "Pre-commit and Test Python 3.9"
10+
runs-on: ubuntu-latest
11+
if: always()
12+
timeout-minutes: 20
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Setup python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.9"
20+
cache: "pip"
21+
22+
- name: Install Dependencies
23+
run: |
24+
pip install --upgrade pip
25+
pip install -r requirements.txt
26+
pip install pytest-github-actions-annotate-failures
27+
28+
- name: Install Graphviz
29+
uses: tlylt/install-graphviz@v1
30+
31+
- name: PyTest with code coverage
32+
continue-on-error: true
33+
run: |
34+
pytest --cov=. --cov-report=term-missing --cov-report=xml --cov-branch
35+
36+
- name: Get the Coverage
37+
shell: bash
38+
run: |
39+
regex='<coverage.+line-rate="([0-9]+\.[0-9]+)".+>'
40+
line=$(grep -oP "$regex" coverage.xml)
41+
[[ $line =~ $regex ]]
42+
coverage=$( bc <<< "${BASH_REMATCH[1]}*100" )
43+
if (( $(echo "$coverage > 90" | bc -l) )); then
44+
COLOR=green
45+
else
46+
COLOR=red
47+
fi
48+
echo "COVERAGE=${coverage%.*}%" >> $GITHUB_ENV
49+
echo "COLOR=$COLOR" >> $GITHUB_ENV
50+
51+
- name: Create Coverage Badge
52+
uses: schneegans/dynamic-badges-action@v1.7.0
53+
with:
54+
auth: ${{ secrets.GIST_SECRET }}
55+
gistID: ${{ secrets.GIST_ID }}
56+
filename: badge.json
57+
label: coverage
58+
message: ${{ env.COVERAGE }}
59+
color: ${{ env.COLOR }}
60+
61+
- name: Create or Update Coverage Comment
62+
uses: peter-evans/create-or-update-comment@v2
63+
with:
64+
token: ${{ secrets.GITHUB_TOKEN }}
65+
issue-number: ${{ github.event.pull_request.number }}
66+
body: |
67+
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/${{ env.GIST_OWNER }}/${{ secrets.GIST_ID }}/raw/coverage.${{ env.REPO_NAME }}.main.json)
68+
edit-mode: replace
69+
reactions: eyes

.github/workflows/python-package-conda.yaml

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@ name: build
22

33
on: [push]
44

5+
env:
6+
REPO_NAME: ${{ github.event.repository.name }}
7+
58
jobs:
6-
pre-commit:
9+
pre-commit-and-test:
710
if: always()
811
runs-on: ubuntu-latest
9-
timeout-minutes: 2
12+
timeout-minutes: 60
1013
steps:
14+
- name: Get branch name
15+
id: branch-name
16+
uses: tj-actions/branch-names@v7.0.7
17+
1118
- uses: actions/checkout@v3
1219
with:
1320
fetch-depth: 0
21+
ref: ${{ github.event.pull_request.head.sha }}
1422

15-
- uses: actions/setup-python@v4
23+
- name: Setup python
24+
uses: actions/setup-python@v4
1625
with:
17-
python-version: "3.9"
26+
architecture: x64
27+
python-version: 3.9
1828
cache: "pip"
29+
cache-dependency-path: requirements.txt
1930

2031
- name: Install Dependencies
2132
run: |
@@ -32,58 +43,16 @@ jobs:
3243

3344
- name: Run docformatter
3445
shell: bash
35-
run: pre-commit run docformatter --all-file
46+
run: pre-commit run docformatter --all-files
3647

3748
- name: Run pydocstyle
3849
shell: bash
39-
run: pre-commit run pydocstyle --all-file
40-
41-
mypy:
42-
if: always()
43-
runs-on: ubuntu-latest
44-
timeout-minutes: 2
45-
steps:
46-
- uses: actions/checkout@v3
47-
with:
48-
fetch-depth: 0
49-
50-
- uses: actions/setup-python@v4
51-
with:
52-
python-version: "3.9"
53-
cache: "pip"
54-
55-
- name: Install Dependencies
56-
run: |
57-
pip install --upgrade pip
58-
pip install -r requirements.txt
50+
run: pre-commit run pydocstyle --all-files
5951

6052
- name: Run mypy
6153
shell: bash
62-
run: pre-commit run mypy --all-file
63-
64-
build-linux:
65-
runs-on: ubuntu-latest
66-
strategy:
67-
max-parallel: 5
68-
69-
steps:
70-
- uses: actions/checkout@v3
71-
- name: Set up Python 3.9
72-
uses: actions/setup-python@v4
73-
with:
74-
python-version: 3.9
75-
cache: "pip"
76-
77-
- name: Install Dependencies
78-
run: |
79-
pip install --upgrade pip
80-
pip install -r requirements.txt
54+
run: pre-commit run mypy --all-files
8155

82-
- name: Run tests
83-
run: |
84-
pytest tests --cov=./ --cov-report=xml
85-
86-
- name: "Upload coverage to Codecov"
87-
uses: codecov/codecov-action@v2
88-
with:
89-
token: ${{ secrets.CODECOV_TOKEN }}
56+
- name: Run pytest with code coverage
57+
run: |
58+
pytest --junitxml pytest.xml --cov=. --cov-report=term-missing --cov-report=xml:coverage.xml --cov-branch | tee pytest-coverage.txt

0 commit comments

Comments
 (0)