Skip to content

Commit 2d2bcc3

Browse files
committed
ci: Refactor tests, add version tagging
1 parent 4e8da20 commit 2d2bcc3

File tree

2 files changed

+111
-35
lines changed

2 files changed

+111
-35
lines changed

.github/workflows/build-publish.yml

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1-
name: Test/Build/Publish
1+
name: Build and publish
22
on:
33
push:
44
branches:
5-
- dev
65
- main
6+
paths:
7+
- http_csp/**
8+
- pyproject.toml
9+
- poetry.lock
710
pull_request:
811
branches:
9-
- dev
1012
- main
13+
paths:
14+
- http_csp/**
15+
- pyproject.toml
16+
- poetry.lock
1117

1218
jobs:
13-
test:
14-
name: Run tests
19+
version-tag:
20+
name: Version tagging
1521
runs-on: ubuntu-latest
22+
outputs:
23+
new_tag: ${{ steps.tag-version.outputs.new_tag }}
1624
steps:
1725
- name: Checkout code
1826
uses: actions/checkout@v3
19-
27+
28+
- name: Determine new version number
29+
id: tag-version
30+
uses: mathieudutour/[email protected]
31+
with:
32+
github_token: ${{ secrets.GITHUB_TOKEN }}
33+
dry_run: true
34+
2035
- name: Set up Poetry
2136
uses: snok/install-poetry@v1
2237
with:
@@ -25,46 +40,37 @@ jobs:
2540
virtualenvs-in-project: false
2641
installer-parallel: true
2742

28-
- name: Set up Python
29-
uses: actions/setup-python@v4
30-
with:
31-
python-version: 3.11
32-
cache: poetry
33-
34-
- name: Install dependencies
35-
run: poetry install --with dev
36-
37-
- name: Lint with flake8
43+
- name: Set up Git
3844
run: |
39-
# stop the build if there are Python syntax errors or undefined names
40-
poetry run flake8 . --count --select=E9,F63,F7,F82 \
41-
--show-source --statistics
42-
43-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
44-
poetry run flake8 . --count --exit-zero --max-complexity=10 \
45-
--max-line-length=127 --statistics
45+
git config user.name "github-actions[bot]"
46+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
4647
47-
- name: Run tests
48-
run: poetry run pytest
48+
- name: Bump Poetry version
49+
run: |
50+
poetry version ${{ steps.tag-version.outputs.new_version }}
51+
git add pyproject.toml
52+
git commit -m "chore: Bump poetry version [skip ci]"
53+
git push
4954
50-
- name: Dependencies safety check
55+
- name: Create Git tag
5156
run: |
52-
poetry export --without-hashes -f requirements.txt | \
53-
poetry run safety check --full-report --stdin
57+
git tag ${{ steps.tag-version.outputs.new_tag }}
58+
git push origin --tags
5459
55-
- name: Create code coverage report
56-
uses: MishaKav/pytest-coverage-comment@main
60+
- name: Create Git release if pushed to main
61+
if: github.ref_name == 'main'
62+
uses: ncipollo/release-action@v1
63+
with:
64+
tag: ${{ steps.tag-version.outputs.new_tag }}
65+
name: Release ${{ steps.tag-version.outputs.new_tag }}
66+
body: ${{ steps.tag-version.outputs.changelog }}
5767

5868
build-publish:
5969
name: Build and publish
6070
runs-on: ubuntu-latest
6171
permissions:
6272
id-token: write
63-
needs: test
64-
if: |
65-
needs.test.result == 'success' &&
66-
github.ref_name == 'main' &&
67-
github.event_name == 'push'
73+
needs: version-tag
6874
steps:
6975
- name: Checkout code
7076
uses: actions/checkout@v3
@@ -85,3 +91,9 @@ jobs:
8591
with:
8692
verbose: true
8793
print-hash: true
94+
95+
- name: Upload build artifacts
96+
uses: actions/upload-artifact@v3
97+
with:
98+
path: dist
99+
name: python-package-build

.github/workflows/quality.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Code quality
2+
on:
3+
push:
4+
branches:
5+
- dev
6+
- main
7+
paths:
8+
- http_csp/**
9+
- pyproject.toml
10+
- poetry.lock
11+
pull_request:
12+
branches:
13+
- dev
14+
- main
15+
paths:
16+
- http_csp/**
17+
- pyproject.toml
18+
- poetry.lock
19+
20+
jobs:
21+
test:
22+
name: Run tests
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v3
27+
28+
- name: Set up Poetry
29+
uses: snok/install-poetry@v1
30+
with:
31+
version: latest
32+
virtualenvs-create: true
33+
virtualenvs-in-project: false
34+
installer-parallel: true
35+
36+
- name: Set up Python
37+
uses: actions/setup-python@v4
38+
with:
39+
python-version: 3.11
40+
cache: poetry
41+
42+
- name: Install dependencies
43+
run: poetry install --with dev
44+
45+
- name: Lint with flake8
46+
run: |
47+
# stop the build if there are Python syntax errors or undefined names
48+
poetry run flake8 . --count --select=E9,F63,F7,F82 \
49+
--show-source --statistics
50+
51+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
52+
poetry run flake8 . --count --exit-zero --max-complexity=10 \
53+
--max-line-length=127 --statistics
54+
55+
- name: Run tests
56+
run: poetry run pytest
57+
58+
- name: Dependencies safety check
59+
run: |
60+
poetry export --without-hashes -f requirements.txt | \
61+
poetry run safety check --full-report --stdin
62+
63+
- name: Create code coverage report
64+
uses: MishaKav/pytest-coverage-comment@main

0 commit comments

Comments
 (0)