Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .github/set-version
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ import os
GIT_REF_PREFIX = "refs/tags/"


def github_ref_type(value: str) -> str:
def github_ref_type(value: str | None) -> str:
if value is None:
raise ValueError("No GITHUB_REF environment variable")

if not value.startswith(GIT_REF_PREFIX):
raise ValueError("Invalid GITHUB_REF format, expects `refs/tags/<tag name>`")

return value


def write_about_file(file: io.TextIOWrapper, git_ref: str) -> None:
def write_about_file(filename: str, git_ref: str) -> str:
tag = git_ref[len(GIT_REF_PREFIX) :]
value = f'__version__ = "{tag}"'
print(value, file=file)

print(f"Writing version {tag} to {filename}")
with open(filename, "w") as fp:
print(value, file=fp)

return tag


Expand All @@ -28,7 +35,6 @@ def main() -> None:
"-g",
"--github-ref",
default=os.environ.get("GITHUB_REF"),
type=github_ref_type,
help=(
'The Git reference, like "refs/tags/<tag name>". '
"Read automatically the GITHUB_REF environment variable, if possible."
Expand All @@ -38,12 +44,16 @@ def main() -> None:
"-f",
"--filename",
default="structlog_gcp/__about__.py",
type=argparse.FileType("w"),
help="The file to write the version into.",
)
args = parser.parse_args()

write_about_file(args.filename, args.github_ref)
try:
github_ref = github_ref_type(args.github_ref)
except Exception as exc:
parser.error(str(exc))

write_about_file(args.filename, github_ref)


if __name__ == "__main__":
Expand Down
20 changes: 9 additions & 11 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,32 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.11"

- name: Setup Hatch
run: pipx install hatch
enable-cache: true

- name: Configure version
if: github.event.action == 'published'
run: ./.github/set-version

- name: Test
run: hatch run pytest --color=yes
run: make test

- name: mypy
run: hatch run mypy
run: make mypy

- name: lint
run: hatch run ruff check
run: uv run ruff check

- name: format
run: hatch run ruff format --diff
run: uv run ruff format --diff

- name: Build
run: hatch build --clean
run: make build

- name: Upload package
if: github.event.action == 'published'
uses: actions/upload-artifact@v4
with:
name: Packages
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ all: fmt mypy test

.PHONY: mypy
mypy:
hatch run mypy
uv run mypy

.PHONY: fmt
fmt:
hatch run ruff format
hatch run ruff check --fix
uv run ruff format
uv run ruff check --fix

.PHONY: test
test:
hatch run test
uv run pytest

.PHONY: build
build:
uv run python -m build --installer=uv
26 changes: 12 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "structlog-gcp"
description = "A structlog set of processors to output as Google Cloud Logging format"
readme = "README.md"
requires-python = ">=3.10"
license = "MIT"
license = { file = "LICENSE" }
keywords = []
authors = [
{ name = "Jonathan Ballet", email = "[email protected]" },
Expand All @@ -31,20 +27,22 @@ Documentation = "https://github.com/multani/structlog-gcp#readme"
Issues = "https://github.com/multani/structlog-gcp/issues"
Source = "https://github.com/multani/structlog-gcp"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "structlog_gcp/__about__.py"

[tool.hatch.envs.default]
dependencies = [
"ruff",
"mypy",
"pytest",
"pytest-cov",
[tool.uv]
dev-dependencies = [
"build[uv]>=1.2.2",
"mypy>=1.11.2",
"pytest>=8.3.3",
"pytest-cov>=5.0.0",
"ruff>=0.6.6",
]

[tool.hatch.envs.default.scripts]
test = "pytest"

[tool.pytest.ini_options]
addopts = [
"--doctest-modules",
Expand Down
Loading