diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index de2b7c8..e973ba0 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -22,8 +22,13 @@ 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: @@ -31,20 +36,20 @@ jobs: 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 }} diff --git a/.github/workflows/deploy_docs.yaml b/.github/workflows/deploy_docs.yaml index d8a36ec..f475e3a 100644 --- a/.github/workflows/deploy_docs.yaml +++ b/.github/workflows/deploy_docs.yaml @@ -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 @@ -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 }} diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index bf72057..c5eba6d 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -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 @@ -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 diff --git a/.github/workflows/release_build.yaml b/.github/workflows/release_build.yaml index 312df96..51fa442 100644 --- a/.github/workflows/release_build.yaml +++ b/.github/workflows/release_build.yaml @@ -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 @@ -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 diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 7f0c905..05836dd 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -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' }} diff --git a/noxfile.py b/noxfile.py index 95700f5..5612001 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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: @@ -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) @@ -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" ) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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") diff --git a/pyproject.toml b/pyproject.toml index 619e83e..255efd9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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] @@ -76,6 +78,7 @@ lines-after-imports = 2 [tool.ruff.lint.pydocstyle] convention = "google" + [tool.commitizen] name = "cz_conventional_commits" tag_format = "$version" diff --git a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/bump_version.yaml b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/bump_version.yaml index de2b7c8..e973ba0 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/bump_version.yaml +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/bump_version.yaml @@ -22,8 +22,13 @@ 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: @@ -31,20 +36,20 @@ jobs: 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 }} diff --git a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/deploy_docs.yaml b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/deploy_docs.yaml index 41e76eb..fe44119 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/deploy_docs.yaml +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/deploy_docs.yaml @@ -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 @@ -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 %} diff --git a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/lint.yaml b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/lint.yaml index ae142da..c54d5e0 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/lint.yaml +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/lint.yaml @@ -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 @@ -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 diff --git a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/release_build.yaml b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/release_build.yaml index 4a5d1f0..ba25f58 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/release_build.yaml +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/release_build.yaml @@ -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 @@ -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 diff --git a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/setup.yaml b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/setup.yaml index 2757f03..26cf8d1 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/setup.yaml +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/setup.yaml @@ -6,7 +6,7 @@ on: python-version: required: false type: string - default: "{{cookiecutter.max_python_version}}" + default: "{{cookiecutter.max_python_version}}" # 使用用户选择的最高 Python 版本 install-deps: required: false type: string @@ -20,12 +20,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' }} diff --git a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py index 9aebebf..9c62e40 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py @@ -61,8 +61,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) @@ -80,6 +80,8 @@ def test(session: nox.Session) -> None: # Run pytest with coverage session.run( + "uv", + "run", "pytest", "--cov={{cookiecutter.project_slug}}", "--cov-report=term-missing", @@ -116,7 +118,7 @@ def test_all(session: nox.Session) -> None: ] + test_args # 运行测试 - session.run("pytest", *test_args) + session.run("uv", "run", "pytest", *test_args) @nox.session(reuse_venv=True) @@ -129,7 +131,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) @@ -197,8 +199,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", ".") {% if cookiecutter.use_mkdocs == "yes" %} @@ -212,7 +214,7 @@ def docs(session: nox.Session) -> None: session: Nox session object for running commands """ install_with_uv(session, extras=["docs"]) - session.run("mkdocs", "build") + session.run("uv", "run", "mkdocs", "build") @nox.session(reuse_venv=True) @@ -225,5 +227,5 @@ def docs_serve(session: nox.Session) -> None: session: Nox session object for running commands """ install_with_uv(session, extras=["docs"]) - session.run("mkdocs", "serve") + session.run("uv", "run", "mkdocs", "serve") {% endif %} diff --git a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/pyproject.toml b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/pyproject.toml index 7659321..9141580 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/pyproject.toml +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ [project.optional-dependencies] dev = [ - "ruff>=0.9.6", + "ruff>=0.9.7", # Update ruff version "nox>=2024.10.9", "pytest>=8.3.4", "pytest-mock>=3.14.0", diff --git a/uv.lock b/uv.lock index afefbf1..0ef16a2 100644 --- a/uv.lock +++ b/uv.lock @@ -802,6 +802,7 @@ docs = [ { name = "mkdocs-material" }, { name = "mkdocstrings" }, { name = "mkdocstrings-python" }, + { name = "pymdown-extensions" }, ] [package.metadata] @@ -816,11 +817,12 @@ requires-dist = [ { name = "mkdocstrings", marker = "extra == 'docs'", specifier = ">=0.24.0" }, { name = "mkdocstrings-python", marker = "extra == 'docs'", specifier = ">=1.7.5" }, { name = "nox", marker = "extra == 'dev'", specifier = ">=2024.10.9" }, + { name = "pymdown-extensions", marker = "extra == 'docs'", specifier = ">=10.7" }, { name = "pytest", marker = "extra == 'dev'", specifier = ">=8.3.4" }, { name = "pytest-cov", marker = "extra == 'dev'", specifier = ">=6.0.0" }, { name = "pytest-mock", marker = "extra == 'dev'", specifier = ">=3.14.0" }, { name = "ruff", specifier = ">=0.9.6" }, - { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.8.4" }, + { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.9.6" }, ] provides-extras = ["dev", "docs"]