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
15 changes: 10 additions & 5 deletions .github/workflows/bump_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,34 @@ permissions:
pull-requests: write # 用于创建 PR

jobs:
setup:
uses: ./.github/workflows/setup.yaml
secrets: inherit

bump-version:
if: "!startsWith(github.event.head_commit.message, 'bump:')"
needs: setup
runs-on: ubuntu-latest
name: "Bump version and create changelog with commitizen"
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}

- id: cz
name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
changelog_increment_filename: body.md
increment: ${{ github.event.inputs.increment }}

- name: Release
uses: softprops/action-gh-release@v1
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body_path: body.md
tag_name: ${{ env.REVISION }}
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
4 changes: 3 additions & 1 deletion .github/workflows/deploy_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
secrets:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
outputs:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

deploy:
needs: setup
Expand All @@ -25,4 +27,4 @@ jobs:
- name: Build and deploy documentation
run: uvx mkdocs gh-deploy --force
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
27 changes: 23 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ jobs:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Check Python version
run: python --version
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run lint checks
id: lint
run: uvx nox -s lint
run: uv tool run nox -s lint
continue-on-error: true

- name: Comment on PR
Expand All @@ -58,9 +66,20 @@ jobs:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run tests on all Python versions
id: test
run: uvx nox -s test_all
run: uv tool run nox -s test_all
continue-on-error: true

- name: Upload coverage reports
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
secrets:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
outputs:
personal-access-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

build:
needs: setup
Expand All @@ -39,6 +41,7 @@ jobs:
id: create_release
uses: softprops/action-gh-release@v2
with:
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
tag_name: ${{ github.event.inputs.version || github.ref_name }}
draft: false
prerelease: false
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ on:
python-version:
description: "The Python version that was set up"
value: ${{ jobs.setup.outputs.python-version }}
PERSONAL_ACCESS_TOKEN:
description: "The personal access token"
value: ${{ jobs.setup.outputs.PERSONAL_ACCESS_TOKEN }}

jobs:
setup:
runs-on: ubuntu-latest
outputs:
python-version: ${{ steps.setup-python.outputs.python-version }}
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
steps:
- name: Load secret
if: ${{ inputs.install-deps != 'none' }}
Expand Down
51 changes: 25 additions & 26 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
from pathlib import Path

# 支持的 Python 版本范围
MIN_PYTHON = "3.10"
MIN_PYTHON = "3.12"
MAX_PYTHON = "3.12"

# 生成版本列表
PYTHON_VERSIONS = [
f"3.{minor}"
for minor in range(int(MIN_PYTHON.split(".")[-1]), int(MAX_PYTHON.split(".")[-1]) + 1)
]
PYTHON_VERSIONS = [MIN_PYTHON]


def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> None:
Expand Down Expand Up @@ -61,8 +58,8 @@ def lint(session: nox.Session) -> None:
install_with_uv(session, extras=["dev"])

# Run ruff checks
session.run("ruff", "check", ".")
session.run("ruff", "format", "--check", ".")
session.run("uv", "run", "ruff", "check", ".")
session.run("uv", "run", "ruff", "format", "--check", ".")


@nox.session(python=PYTHON_VERSIONS[-1], reuse_venv=True)
Expand All @@ -80,12 +77,14 @@ def test(session: nox.Session) -> None:

# Run pytest with coverage
session.run(
"uv",
"run",
"pytest",
"--cov=repo_scaffold",
"--cov-report=term-missing",
"--cov-report=xml",
"-v",
"tests",
"tests"
)


Expand All @@ -101,22 +100,20 @@ def test_all(session: nox.Session) -> None:
session: Nox session object for running commands
"""
# Install dependencies
session.install("uv")
install_with_uv(session, extras=["dev"])

# 确定是否是最新的 Python 版本
is_latest_python = session.python == PYTHON_VERSIONS[-1]

# 构建测试命令
test_args = ["-v", "tests"]
if is_latest_python:
test_args = [
"--cov=repo_scaffold",
"--cov-report=term-missing",
"--cov-report=xml",
] + test_args

# 运行测试
session.run("pytest", *test_args)
session.run(
"uv",
"run",
"pytest",
"--cov=repo_scaffold",
"--cov-report=term-missing",
"--cov-report=xml",
"-v",
"tests"
)


@nox.session(reuse_venv=True)
Expand All @@ -129,7 +126,7 @@ def build(session: nox.Session) -> None:
session: Nox session object for running commands
"""
install_with_uv(session, extras=["dev"])
session.run("python", "-m", "build")
session.run("uv","build")


@nox.session(reuse_venv=True)
Expand Down Expand Up @@ -197,8 +194,8 @@ def baseline(session: nox.Session) -> None:
install_with_uv(session, extras=["dev"])

# 运行 ruff 并自动修复所有问题
session.run("ruff", "check", ".", "--add-noqa")
session.run("ruff", "format", ".")
session.run("uv", "run", "ruff", "check", ".", "--add-noqa")
session.run("uv", "run", "ruff", "format", ".")


@nox.session(reuse_venv=True)
Expand All @@ -210,8 +207,9 @@ def docs(session: nox.Session) -> None:
Args:
session: Nox session object for running commands
"""
session.install("uv")
install_with_uv(session, extras=["docs"])
session.run("mkdocs", "build")
session.run("uv", "run", "mkdocs", "build")


@nox.session(reuse_venv=True)
Expand All @@ -223,5 +221,6 @@ def docs_serve(session: nox.Session) -> None:
Args:
session: Nox session object for running commands
"""
session.install("uv")
install_with_uv(session, extras=["docs"])
session.run("mkdocs", "serve")
session.run("uv", "run", "mkdocs", "serve")
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies = [

[project.optional-dependencies]
dev = [
"ruff>=0.8.4",
"ruff>=0.9.6",
"nox>=2024.10.9",
"pytest>=8.3.4",
"pytest-mock>=3.14.0",
Expand All @@ -31,6 +31,8 @@ docs = [
"mkdocstrings-python>=1.7.5",
"mkdocs-gen-files>=0.5.0",
"mkdocs-literate-nav>=0.6.1",
"pymdown-extensions>=10.7",
"pymdown-extensions>=10.7",
]

[project.scripts]
Expand Down Expand Up @@ -76,6 +78,7 @@ lines-after-imports = 2
[tool.ruff.lint.pydocstyle]
convention = "google"


[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,34 @@ permissions:
pull-requests: write # 用于创建 PR

jobs:
setup:
uses: ./.github/workflows/setup.yaml
secrets: inherit

bump-version:
if: "!startsWith(github.event.head_commit.message, 'bump:')"
needs: setup
runs-on: ubuntu-latest
name: "Bump version and create changelog with commitizen"
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}

- id: cz
name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
changelog_increment_filename: body.md
increment: ${{ github.event.inputs.increment }}

- name: Release
uses: softprops/action-gh-release@v1
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body_path: body.md
tag_name: ${{ env.REVISION }}
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ jobs:
uses: ./.github/workflows/setup.yaml
with:
install-deps: docs
python-version: "{{ cookiecutter.max_python_version }}"
secrets:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
secrets: inherit

deploy:
needs: setup
Expand All @@ -27,5 +24,5 @@ jobs:
- name: Build and deploy documentation
run: uvx mkdocs gh-deploy --force
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ jobs:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Check Python version
run: python --version
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "{{cookiecutter.max_python_version}}"

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run lint checks
id: lint
run: uvx nox -s lint
run: uv tool run nox -s lint
continue-on-error: true

- name: Comment on PR
Expand All @@ -58,9 +66,20 @@ jobs:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "{{cookiecutter.max_python_version}}"

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run tests on all Python versions
id: test
run: uvx nox -s test_all
run: uv tool run nox -s test_all
continue-on-error: true

- name: Upload coverage reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
secrets:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
outputs:
personal-access-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

build:
needs: setup
Expand All @@ -39,6 +41,7 @@ jobs:
id: create_release
uses: softprops/action-gh-release@v2
with:
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
tag_name: ${{ github.event.inputs.version || github.ref_name }}
draft: false
prerelease: false
Expand Down
Loading