Skip to content

Commit b201ed5

Browse files
committed
Add github actions
1 parent 8a0b3ad commit b201ed5

9 files changed

Lines changed: 152 additions & 9 deletions

File tree

.github/build/action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: build
2+
inputs:
3+
package-version:
4+
required: true
5+
description: The python package version
6+
runs:
7+
using: "composite"
8+
steps:
9+
- uses: astral-sh/setup-uv@v5
10+
11+
- name: Build
12+
shell: bash
13+
run: |
14+
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version ${{ inputs.package-version }}
15+
uv build
16+
17+
- name: Upload package
18+
uses: actions/upload-artifact@v4
19+
with:
20+
path: ./dist

.github/publish/action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: publish
2+
inputs:
3+
repository-url:
4+
required: true
5+
description: The destination package repository URL
6+
runs:
7+
using: "composite"
8+
steps:
9+
- name: Publish package distributions to PyPI
10+
uses: pypa/gh-action-pypi-publish@release/v1
11+
with:
12+
repository-url: ${REPOSITORY_URL}

.github/workflows/CD.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CD Pipeline
2+
3+
on:
4+
create:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
10+
steps:
11+
- name: Load version into env
12+
shell: bash
13+
run: |
14+
[[ $GITHUB_REF =~ refs/tags/(.*) ]]
15+
version="${BASH_REMATCH[1]}"
16+
[ -z "${version}" ] && exit 1
17+
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
18+
19+
- uses: actions/checkout@v4
20+
21+
- uses: ./.github/build
22+
with:
23+
package-version: ${RELEASE_VERSION}
24+
25+
pypi-publish:
26+
needs: build
27+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
28+
runs-on: ubuntu-latest
29+
# Specifying a GitHub environment is optional, but strongly encouraged
30+
environment: pypi
31+
permissions:
32+
# IMPORTANT: this permission is mandatory for Trusted Publishing
33+
id-token: write
34+
steps:
35+
- uses: actions/download-artifact@v4
36+
- uses: actions/checkout@v4
37+
- uses: ./.github/publish
38+
with:
39+
repository-url: ${REPOSITORY_URL}

.github/workflows/CI.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- master
5+
6+
name: CI
7+
8+
jobs:
9+
test:
10+
strategy:
11+
matrix:
12+
python-version: ["3.13", "3.12", "3.11", "3.10", "3.9"]
13+
runs-on: ubuntu-latest
14+
environment: pypi-test
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: astral-sh/setup-uv@v5
18+
- uses: extractions/setup-just@v2
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: "Install python venv"
24+
run: "uv sync"
25+
26+
- name: "Lint and test"
27+
run: |
28+
source .venv/bin/activate
29+
just lint
30+
just test
31+
coverage xml
32+
33+
- uses: codecov/codecov-action@v5
34+
if: ${{ contains(matrix.python-version, '3.13') }}
35+
with:
36+
fail_ci_if_error: true
37+
token: ${{ secrets.CODECOV_TOKEN }}
38+
39+
build:
40+
needs: test
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Load version into env
44+
shell: bash
45+
run: |
46+
echo "RELEASE_VERSION=${{ github.sha }}" >> $GITHUB_ENV
47+
48+
- uses: actions/checkout@v4
49+
50+
- uses: ./.github/build
51+
with:
52+
package-version: ${RELEASE_VERSION}
53+
54+
pypi-publish:
55+
needs: [test, build]
56+
runs-on: ubuntu-latest
57+
# Specifying a GitHub environment is optional, but strongly encouraged
58+
environment: pypi-test
59+
permissions:
60+
# IMPORTANT: this permission is mandatory for Trusted Publishing
61+
id-token: write
62+
steps:
63+
- uses: actions/download-artifact@v4
64+
- uses: actions/checkout@v4
65+
- uses: ./.github/publish
66+
with:
67+
repository-url: ${REPOSITORY_URL}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ __pycache__/
33
.mypy_cache/
44
.ruff_cache/
55
*.py[oc]
6-
build/
7-
dist/
6+
./build/
7+
./dist/
88
wheels/
99
*.egg-info
1010
.coverage

enfig/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from enfig.base import BaseConfig
2-
from enfig.errors import ValidationError, ConfigAttributeError
2+
from enfig.errors import ConfigAttributeError, ValidationError
33

44
__all__ = [
55
BaseConfig.__name__,
66
ValidationError.__name__,
77
ConfigAttributeError.__name__,
88
]
9-

enfig/errors.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from enum import Enum, StrEnum
1+
from enum import Enum
22

33
from enfig.bool_type import _Bool
44

@@ -11,7 +11,7 @@ class InstantiationForbiddenError(EnfigError):
1111
pass
1212

1313

14-
class ConfigAttributeErrorType(StrEnum):
14+
class ConfigAttributeErrorType(str, Enum):
1515
NOT_SET = "Not set"
1616
INVALID_VALUE = "Invalid value"
1717

@@ -35,7 +35,8 @@ def __repr__(self):
3535
def __str__(self) -> str:
3636
required_type = bool if self.required_type is _Bool else self.required_type
3737
return (
38-
f"{self.attribute_name}: {self.error_type}, required type: `{required_type.__name__}`"
38+
f"{self.attribute_name}: {self.error_type}, "
39+
f"required type: `{required_type.__name__}`"
3940
)
4041

4142

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ name = "enfig"
33
version = "0.1.0"
44
description = "Add your description here"
55
readme = "README.md"
6-
requires-python = "^3.8"
6+
requires-python = ">=3.9"
7+
GitHub = "https://github.com/DAtek/enfig"
8+
license = "MIT"
9+
710
dependencies = []
811

912
[dependency-groups]

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from pytest import fixture
24

35
from enfig.base import BaseConfig
@@ -9,7 +11,7 @@ class VolumeConfig(BaseConfig):
911
VOLUME: int
1012
FIELD_WITH_DEFAULT_VALUE: str = "C"
1113
NON_MANDATORY_FIELD: str = None # type: ignore
12-
TYPED_NON_MANDATORY_FIELD: str | None = None
14+
TYPED_NON_MANDATORY_FIELD: Optional[str] = None
1315

1416
return VolumeConfig
1517

0 commit comments

Comments
 (0)