From d88a7d4788e60f398d01a6903c58b45e27e8bd52 Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 22:46:10 +0800 Subject: [PATCH 01/15] fix: use token from setup workflow in bump_version workflow --- .github/workflows/bump_version.yaml | 6 +++--- .../.github/workflows/bump_version.yaml | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index de2b7c8..5593e20 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -31,13 +31,13 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + token: ${{ needs.setup.outputs.personal-access-token || github.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 || github.token }} changelog_increment_filename: body.md increment: ${{ github.event.inputs.increment }} @@ -47,4 +47,4 @@ jobs: body_path: body.md tag_name: ${{ env.REVISION }} env: - GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ needs.setup.outputs.personal-access-token || github.token }} 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..e8e05b5 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,13 +36,13 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + token: ${{ needs.setup.outputs.personal-access-token || github.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 || github.token }} changelog_increment_filename: body.md increment: ${{ github.event.inputs.increment }} @@ -47,4 +52,4 @@ jobs: body_path: body.md tag_name: ${{ env.REVISION }} env: - GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ needs.setup.outputs.personal-access-token || github.token }} From 6ae8f7b00a0216a20ab3ab5196cfa4ffe70ebff7 Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 22:55:49 +0800 Subject: [PATCH 02/15] fix: standardize token usage in GitHub Actions workflows --- .github/workflows/bump_version.yaml | 15 ++++++++++----- .github/workflows/deploy_docs.yaml | 4 +++- .github/workflows/release_build.yaml | 3 +++ .github/workflows/setup.yaml | 4 ++++ .../.github/workflows/bump_version.yaml | 10 +++++----- .../.github/workflows/deploy_docs.yaml | 7 ++----- .../.github/workflows/release_build.yaml | 3 +++ .../.github/workflows/setup.yaml | 4 ++++ 8 files changed, 34 insertions(+), 16 deletions(-) diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index 5593e20..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: ${{ needs.setup.outputs.personal-access-token || github.token }} + token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} - id: cz name: Create bump and changelog uses: commitizen-tools/commitizen-action@master with: - github_token: ${{ needs.setup.outputs.personal-access-token || github.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: ${{ needs.setup.outputs.personal-access-token || github.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/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/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 e8e05b5..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 @@ -36,20 +36,20 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ needs.setup.outputs.personal-access-token || github.token }} + token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} - id: cz name: Create bump and changelog uses: commitizen-tools/commitizen-action@master with: - github_token: ${{ needs.setup.outputs.personal-access-token || github.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: ${{ needs.setup.outputs.personal-access-token || github.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/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..80a9dd6 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 @@ -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' }} From 3542ea8ddf5b9c98bf1344372c21b0d881a2c3c1 Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 23:04:30 +0800 Subject: [PATCH 03/15] fix: explicitly install ruff in nox sessions and update dev dependencies --- noxfile.py | 1 + pyproject.toml | 7 ++++++- uv.lock | 12 +++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 95700f5..6c03875 100644 --- a/noxfile.py +++ b/noxfile.py @@ -41,6 +41,7 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No extras: Optional list of extra dependency groups to install (e.g. ["dev", "docs"]) """ session.install("uv") + session.install("ruff") # Explicitly install ruff if extras: session.run("uv", "sync", *(f"--extra={extra}" for extra in extras)) else: diff --git a/pyproject.toml b/pyproject.toml index 619e83e..b2cd994 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", @@ -43,6 +43,11 @@ repo_scaffold = ["templates/**/*", "cookiecutter.json"] requires = ["hatchling"] build-backend = "hatchling.build" +[dependency-groups] +dev = [ + "ruff>=0.9.6", +] + [tool.ruff] line-length = 120 include = ["pyproject.toml", "repo_scaffold/*.py"] diff --git a/uv.lock b/uv.lock index afefbf1..4112203 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,4 @@ version = 1 -revision = 1 requires-python = ">=3.12" [[package]] @@ -804,6 +803,11 @@ docs = [ { name = "mkdocstrings-python" }, ] +[package.dev-dependencies] +dev = [ + { name = "ruff" }, +] + [package.metadata] requires-dist = [ { name = "click", specifier = ">=8.1.8" }, @@ -820,9 +824,11 @@ requires-dist = [ { 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"] + +[package.metadata.requires-dev] +dev = [{ name = "ruff", specifier = ">=0.9.6" }] [[package]] name = "requests" From 462eb3ed2f03cca3330ff4b13b4bd72484dfbf37 Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 23:05:43 +0800 Subject: [PATCH 04/15] fix: update template files to explicitly install ruff and update dev dependencies --- .../template-python/{{cookiecutter.project_slug}}/noxfile.py | 1 + .../{{cookiecutter.project_slug}}/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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..de75450 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py @@ -41,6 +41,7 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No extras: Optional list of extra dependency groups to install (e.g. ["dev", "docs"]) """ session.install("uv") + session.install("ruff") # Explicitly install ruff if extras: session.run("uv", "sync", *(f"--extra={extra}" for extra in extras)) else: 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", From ad16934b442eec9150cde552713e778cfa7e692c Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 23:09:39 +0800 Subject: [PATCH 05/15] fix: add code checkout and Python setup steps to lint workflow --- .github/workflows/lint.yaml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index bf72057..f0b5fcc 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -26,8 +26,13 @@ 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: Run lint checks id: lint @@ -58,6 +63,14 @@ 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: Run tests on all Python versions id: test run: uvx nox -s test_all From 71e0d5d0eef81dd0e1145b84503367e0deec14e6 Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 23:21:19 +0800 Subject: [PATCH 06/15] fix: use cookiecutter max_python_version in GitHub Actions workflows --- .github/workflows/lint.yaml | 10 +++++-- noxfile.py | 7 ++--- .../.github/workflows/lint.yaml | 27 ++++++++++++++++--- .../.github/workflows/setup.yaml | 2 +- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index f0b5fcc..c5eba6d 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -34,9 +34,12 @@ jobs: 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 @@ -71,9 +74,12 @@ jobs: 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/noxfile.py b/noxfile.py index 6c03875..a392ca7 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: 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/setup.yaml b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/setup.yaml index 80a9dd6..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 From ea5f9573956d273ef162ccdf1caa663a56a152f9 Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 23:24:47 +0800 Subject: [PATCH 07/15] fix: explicitly install pytest packages in nox sessions --- noxfile.py | 3 +++ .../template-python/{{cookiecutter.project_slug}}/noxfile.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/noxfile.py b/noxfile.py index a392ca7..a294135 100644 --- a/noxfile.py +++ b/noxfile.py @@ -41,6 +41,9 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No session.install("ruff") # Explicitly install ruff if extras: session.run("uv", "sync", *(f"--extra={extra}" for extra in extras)) + # Install pytest and related packages for test sessions + if any(extra == "dev" for extra in extras): + session.install("pytest", "pytest-cov", "pytest-mock") else: session.run("uv", "sync") 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 de75450..765afeb 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py @@ -44,6 +44,9 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No session.install("ruff") # Explicitly install ruff if extras: session.run("uv", "sync", *(f"--extra={extra}" for extra in extras)) + # Install pytest and related packages for test sessions + if any(extra == "dev" for extra in extras): + session.install("pytest", "pytest-cov", "pytest-mock") else: session.run("uv", "sync") From 5a96451e8f9b4155f73f964d1081e2c90ba75750 Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 23:41:27 +0800 Subject: [PATCH 08/15] fix: use uvx prefix for all third-party commands in nox sessions --- noxfile.py | 20 +++++++++---------- .../{{cookiecutter.project_slug}}/noxfile.py | 17 ++++++++-------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/noxfile.py b/noxfile.py index a294135..8406bef 100644 --- a/noxfile.py +++ b/noxfile.py @@ -41,9 +41,6 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No session.install("ruff") # Explicitly install ruff if extras: session.run("uv", "sync", *(f"--extra={extra}" for extra in extras)) - # Install pytest and related packages for test sessions - if any(extra == "dev" for extra in extras): - session.install("pytest", "pytest-cov", "pytest-mock") else: session.run("uv", "sync") @@ -62,8 +59,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("uvx", "ruff", "check", ".") + session.run("uvx", "ruff", "format", "--check", ".") @nox.session(python=PYTHON_VERSIONS[-1], reuse_venv=True) @@ -81,6 +78,7 @@ def test(session: nox.Session) -> None: # Run pytest with coverage session.run( + "uvx", "pytest", "--cov=repo_scaffold", "--cov-report=term-missing", @@ -117,7 +115,7 @@ def test_all(session: nox.Session) -> None: ] + test_args # 运行测试 - session.run("pytest", *test_args) + session.run("uvx","pytest", *test_args) @nox.session(reuse_venv=True) @@ -130,7 +128,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) @@ -198,8 +196,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("uvx","ruff", "check", ".", "--add-noqa") + session.run("uvx","ruff", "format", ".") @nox.session(reuse_venv=True) @@ -212,7 +210,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("uvx","mkdocs", "build") @nox.session(reuse_venv=True) @@ -225,4 +223,4 @@ 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("uvx","mkdocs", "serve") 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 765afeb..df2b88f 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py @@ -65,8 +65,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("uvx", "ruff", "check", ".") + session.run("uvx", "ruff", "format", "--check", ".") @nox.session(python=PYTHON_VERSIONS[-1], reuse_venv=True) @@ -84,6 +84,7 @@ def test(session: nox.Session) -> None: # Run pytest with coverage session.run( + "uvx", "pytest", "--cov={{cookiecutter.project_slug}}", "--cov-report=term-missing", @@ -120,7 +121,7 @@ def test_all(session: nox.Session) -> None: ] + test_args # 运行测试 - session.run("pytest", *test_args) + session.run("uvx", "pytest", *test_args) @nox.session(reuse_venv=True) @@ -133,7 +134,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) @@ -201,8 +202,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("uvx", "ruff", "check", ".", "--add-noqa") + session.run("uvx", "ruff", "format", ".") {% if cookiecutter.use_mkdocs == "yes" %} @@ -216,7 +217,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("uvx", "mkdocs", "build") @nox.session(reuse_venv=True) @@ -229,5 +230,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("uvx", "mkdocs", "serve") {% endif %} From beaf30fdb5ce489bdc70cf8ed827de10a91343bb Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 23:43:30 +0800 Subject: [PATCH 09/15] refactor: remove explicit pytest package installation as uvx handles it --- .../template-python/{{cookiecutter.project_slug}}/noxfile.py | 3 --- 1 file changed, 3 deletions(-) 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 df2b88f..047303b 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py @@ -44,9 +44,6 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No session.install("ruff") # Explicitly install ruff if extras: session.run("uv", "sync", *(f"--extra={extra}" for extra in extras)) - # Install pytest and related packages for test sessions - if any(extra == "dev" for extra in extras): - session.install("pytest", "pytest-cov", "pytest-mock") else: session.run("uv", "sync") From 0a5d8907706033c6454f1368edbfaff6da2a8e2e Mon Sep 17 00:00:00 2001 From: ShawnDeng-code Date: Mon, 17 Feb 2025 23:53:43 +0800 Subject: [PATCH 10/15] fix: fix github action --- noxfile.py | 6 +----- pyproject.toml | 10 +++++----- .../{{cookiecutter.project_slug}}/noxfile.py | 1 - uv.lock | 12 ++++-------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/noxfile.py b/noxfile.py index 8406bef..eb08177 100644 --- a/noxfile.py +++ b/noxfile.py @@ -38,7 +38,6 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No extras: Optional list of extra dependency groups to install (e.g. ["dev", "docs"]) """ session.install("uv") - session.install("ruff") # Explicitly install ruff if extras: session.run("uv", "sync", *(f"--extra={extra}" for extra in extras)) else: @@ -80,9 +79,6 @@ def test(session: nox.Session) -> None: session.run( "uvx", "pytest", - "--cov=repo_scaffold", - "--cov-report=term-missing", - "--cov-report=xml", "-v", "tests", ) @@ -115,7 +111,7 @@ def test_all(session: nox.Session) -> None: ] + test_args # 运行测试 - session.run("uvx","pytest", *test_args) + session.run("uvx", "pytest", "-v", *test_args) @nox.session(reuse_venv=True) diff --git a/pyproject.toml b/pyproject.toml index b2cd994..76f0dc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ docs = [ "mkdocstrings-python>=1.7.5", "mkdocs-gen-files>=0.5.0", "mkdocs-literate-nav>=0.6.1", + "pymdown-extensions>=10.7", ] [project.scripts] @@ -43,11 +44,6 @@ repo_scaffold = ["templates/**/*", "cookiecutter.json"] requires = ["hatchling"] build-backend = "hatchling.build" -[dependency-groups] -dev = [ - "ruff>=0.9.6", -] - [tool.ruff] line-length = 120 include = ["pyproject.toml", "repo_scaffold/*.py"] @@ -81,6 +77,10 @@ lines-after-imports = 2 [tool.ruff.lint.pydocstyle] convention = "google" +[tool.pytest.ini_options] +addopts = "--cov=repo_scaffold --cov-report=term-missing --cov-report=xml" +testpaths = ["tests"] + [tool.commitizen] name = "cz_conventional_commits" tag_format = "$version" 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 047303b..38d221e 100644 --- a/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py +++ b/repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/noxfile.py @@ -41,7 +41,6 @@ def install_with_uv(session: nox.Session, extras: list[str] | None = None) -> No extras: Optional list of extra dependency groups to install (e.g. ["dev", "docs"]) """ session.install("uv") - session.install("ruff") # Explicitly install ruff if extras: session.run("uv", "sync", *(f"--extra={extra}" for extra in extras)) else: diff --git a/uv.lock b/uv.lock index 4112203..0ef16a2 100644 --- a/uv.lock +++ b/uv.lock @@ -1,4 +1,5 @@ version = 1 +revision = 1 requires-python = ">=3.12" [[package]] @@ -801,11 +802,7 @@ docs = [ { name = "mkdocs-material" }, { name = "mkdocstrings" }, { name = "mkdocstrings-python" }, -] - -[package.dev-dependencies] -dev = [ - { name = "ruff" }, + { name = "pymdown-extensions" }, ] [package.metadata] @@ -820,15 +817,14 @@ 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.9.6" }, ] - -[package.metadata.requires-dev] -dev = [{ name = "ruff", specifier = ">=0.9.6" }] +provides-extras = ["dev", "docs"] [[package]] name = "requests" From 661f8bb6df3c04c8c10bbc9b313910094887e6a6 Mon Sep 17 00:00:00 2001 From: colyerdeng Date: Tue, 18 Feb 2025 11:34:25 +0800 Subject: [PATCH 11/15] refactor: replace uvx with uv run in noxfile.py --- noxfile.py | 46 ++++++++++--------- pyproject.toml | 4 +- .../{{cookiecutter.project_slug}}/noxfile.py | 17 +++---- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/noxfile.py b/noxfile.py index eb08177..5612001 100644 --- a/noxfile.py +++ b/noxfile.py @@ -58,8 +58,8 @@ def lint(session: nox.Session) -> None: install_with_uv(session, extras=["dev"]) # Run ruff checks - session.run("uvx", "ruff", "check", ".") - session.run("uvx", "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) @@ -77,10 +77,14 @@ def test(session: nox.Session) -> None: # Run pytest with coverage session.run( - "uvx", + "uv", + "run", "pytest", + "--cov=repo_scaffold", + "--cov-report=term-missing", + "--cov-report=xml", "-v", - "tests", + "tests" ) @@ -96,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("uvx", "pytest", "-v", *test_args) + session.run( + "uv", + "run", + "pytest", + "--cov=repo_scaffold", + "--cov-report=term-missing", + "--cov-report=xml", + "-v", + "tests" + ) @nox.session(reuse_venv=True) @@ -192,8 +194,8 @@ def baseline(session: nox.Session) -> None: install_with_uv(session, extras=["dev"]) # 运行 ruff 并自动修复所有问题 - session.run("uvx","ruff", "check", ".", "--add-noqa") - session.run("uvx","ruff", "format", ".") + session.run("uv", "run", "ruff", "check", ".", "--add-noqa") + session.run("uv", "run", "ruff", "format", ".") @nox.session(reuse_venv=True) @@ -205,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("uvx","mkdocs", "build") + session.run("uv", "run", "mkdocs", "build") @nox.session(reuse_venv=True) @@ -218,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("uvx","mkdocs", "serve") + session.run("uv", "run", "mkdocs", "serve") diff --git a/pyproject.toml b/pyproject.toml index 76f0dc2..255efd9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ docs = [ "mkdocs-gen-files>=0.5.0", "mkdocs-literate-nav>=0.6.1", "pymdown-extensions>=10.7", + "pymdown-extensions>=10.7", ] [project.scripts] @@ -77,9 +78,6 @@ lines-after-imports = 2 [tool.ruff.lint.pydocstyle] convention = "google" -[tool.pytest.ini_options] -addopts = "--cov=repo_scaffold --cov-report=term-missing --cov-report=xml" -testpaths = ["tests"] [tool.commitizen] name = "cz_conventional_commits" 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 38d221e..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("uvx", "ruff", "check", ".") - session.run("uvx", "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,7 +80,8 @@ def test(session: nox.Session) -> None: # Run pytest with coverage session.run( - "uvx", + "uv", + "run", "pytest", "--cov={{cookiecutter.project_slug}}", "--cov-report=term-missing", @@ -117,7 +118,7 @@ def test_all(session: nox.Session) -> None: ] + test_args # 运行测试 - session.run("uvx", "pytest", *test_args) + session.run("uv", "run", "pytest", *test_args) @nox.session(reuse_venv=True) @@ -198,8 +199,8 @@ def baseline(session: nox.Session) -> None: install_with_uv(session, extras=["dev"]) # 运行 ruff 并自动修复所有问题 - session.run("uvx", "ruff", "check", ".", "--add-noqa") - session.run("uvx", "ruff", "format", ".") + session.run("uv", "run", "ruff", "check", ".", "--add-noqa") + session.run("uv", "run", "ruff", "format", ".") {% if cookiecutter.use_mkdocs == "yes" %} @@ -213,7 +214,7 @@ def docs(session: nox.Session) -> None: session: Nox session object for running commands """ install_with_uv(session, extras=["docs"]) - session.run("uvx", "mkdocs", "build") + session.run("uv", "run", "mkdocs", "build") @nox.session(reuse_venv=True) @@ -226,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("uvx", "mkdocs", "serve") + session.run("uv", "run", "mkdocs", "serve") {% endif %} From 56fe2d08633dbb55b523a2763dbab059d428d9c6 Mon Sep 17 00:00:00 2001 From: colyerdeng Date: Tue, 18 Feb 2025 12:23:32 +0800 Subject: [PATCH 12/15] ci: optimize github actions workflows - Use github.token instead of PAT - Remove debug steps and simplify configurations - Merge lint and test jobs - Standardize secrets inheritance - Fix uv command in deploy docs workflow --- .github/workflows/bump_version.yaml | 9 +++---- .github/workflows/deploy_docs.yaml | 8 ++---- .github/workflows/lint.yaml | 37 +++++----------------------- .github/workflows/release_build.yaml | 8 ++---- .github/workflows/setup.yaml | 9 +------ 5 files changed, 15 insertions(+), 56 deletions(-) diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index e973ba0..04cee3c 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -18,8 +18,7 @@ on: default: patch permissions: - contents: write # 用于创建和推送标签 - pull-requests: write # 用于创建 PR + contents: write jobs: setup: @@ -36,13 +35,13 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} + token: ${{ github.token }} - id: cz name: Create bump and changelog uses: commitizen-tools/commitizen-action@master with: - github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} + github_token: ${{ github.token }} changelog_increment_filename: body.md increment: ${{ github.event.inputs.increment }} @@ -52,4 +51,4 @@ jobs: body_path: body.md tag_name: ${{ env.REVISION }} env: - GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/deploy_docs.yaml b/.github/workflows/deploy_docs.yaml index f475e3a..5ef875e 100644 --- a/.github/workflows/deploy_docs.yaml +++ b/.github/workflows/deploy_docs.yaml @@ -14,11 +14,7 @@ jobs: uses: ./.github/workflows/setup.yaml with: install-deps: docs - 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 }} + secrets: inherit deploy: needs: setup @@ -27,4 +23,4 @@ jobs: - name: Build and deploy documentation run: uvx mkdocs gh-deploy --force env: - GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }} + GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index c5eba6d..86d9913 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -17,32 +17,22 @@ jobs: uses: ./.github/workflows/setup.yaml with: install-deps: dev - python-version: "3.12" # 使用最新版本 - secrets: - OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} - PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + python-version: "3.12" + secrets: inherit - lint: + check: 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 lint checks id: lint run: uv tool run nox -s lint continue-on-error: true - - name: Comment on PR + - name: Comment on PR (Lint) if: github.event_name == 'pull_request' && steps.lint.outcome == 'failure' uses: actions/github-script@v7 with: @@ -62,22 +52,7 @@ jobs: if: steps.lint.outcome == 'failure' run: exit 1 - test-all: - 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 + - name: Run tests id: test run: uv tool run nox -s test_all continue-on-error: true @@ -90,7 +65,7 @@ jobs: file: ./coverage.xml flags: unittests - - name: Comment on PR + - name: Comment on PR (Tests) if: github.event_name == 'pull_request' && steps.test.outcome == 'failure' uses: actions/github-script@v7 with: diff --git a/.github/workflows/release_build.yaml b/.github/workflows/release_build.yaml index 51fa442..1b2037d 100644 --- a/.github/workflows/release_build.yaml +++ b/.github/workflows/release_build.yaml @@ -21,11 +21,7 @@ jobs: with: install-deps: dev python-version: "3.12" - 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 }} + secrets: inherit build: needs: setup @@ -41,7 +37,7 @@ jobs: id: create_release uses: softprops/action-gh-release@v2 with: - token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }} + 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 05836dd..def7823 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -13,25 +13,18 @@ on: secrets: OP_SERVICE_ACCOUNT_TOKEN: required: false - PERSONAL_ACCESS_TOKEN: - required: false outputs: 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' }} uses: 1password/load-secrets-action@v2 with: export-env: true @@ -43,7 +36,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ env.PERSONAL_ACCESS_TOKEN || github.token }} + token: ${{ github.token }} - name: Setup Python id: setup-python From 52d6dff284b7a864e28315030ad69985f89e044f Mon Sep 17 00:00:00 2001 From: colyerdeng Date: Tue, 18 Feb 2025 12:24:01 +0800 Subject: [PATCH 13/15] ci: fix uv command in deploy docs workflow --- .github/workflows/deploy_docs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_docs.yaml b/.github/workflows/deploy_docs.yaml index 5ef875e..b2f010e 100644 --- a/.github/workflows/deploy_docs.yaml +++ b/.github/workflows/deploy_docs.yaml @@ -21,6 +21,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Build and deploy documentation - run: uvx mkdocs gh-deploy --force + run: uv run mkdocs gh-deploy --force env: GITHUB_TOKEN: ${{ github.token }} From 5c645df291a0d7ed5ffee9a2e0a5ecdf3c4fc968 Mon Sep 17 00:00:00 2001 From: colyerdeng Date: Tue, 18 Feb 2025 12:52:50 +0800 Subject: [PATCH 14/15] refactor: optimize github actions workflows 1. Remove setup.yaml and make each workflow independent 2. Update uv commands to use sync and uvx 3. Update PyPI publish configuration 4. Fix line endings --- .github/workflows/bump_version.yaml | 3 +- .github/workflows/deploy_docs.yaml | 21 ++++--- .github/workflows/lint.yaml | 23 ++++---- .github/workflows/release_build.yaml | 67 +++++++++++++--------- .github/workflows/setup.yaml | 84 ---------------------------- 5 files changed, 70 insertions(+), 128 deletions(-) delete mode 100644 .github/workflows/setup.yaml diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index fc6dbe1..9642665 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -18,7 +18,8 @@ on: default: patch permissions: - contents: write + contents: write # 用于创建和推送标签 + pull-requests: write # 用于创建 PR jobs: setup: diff --git a/.github/workflows/deploy_docs.yaml b/.github/workflows/deploy_docs.yaml index b2f010e..81b4e13 100644 --- a/.github/workflows/deploy_docs.yaml +++ b/.github/workflows/deploy_docs.yaml @@ -10,16 +10,23 @@ permissions: contents: write # 用于部署到 GitHub Pages jobs: - setup: - uses: ./.github/workflows/setup.yaml - with: - install-deps: docs - secrets: inherit - deploy: - 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: "3.12" + + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Install dependencies + run: uv sync --extra=docs + - name: Build and deploy documentation run: uv run mkdocs gh-deploy --force env: diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 86d9913..95227fb 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -13,23 +13,26 @@ permissions: pull-requests: write # 用于在 PR 中添加评论 jobs: - setup: - uses: ./.github/workflows/setup.yaml - with: - install-deps: dev - python-version: "3.12" - secrets: inherit - check: - 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: "3.12" + + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Install dependencies + run: uv sync --extra=dev + - name: Run lint checks id: lint - run: uv tool run nox -s lint + run: uvx nox -s lint continue-on-error: true - name: Comment on PR (Lint) @@ -54,7 +57,7 @@ jobs: - name: Run tests id: test - run: uv tool run nox -s test_all + run: uvx 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 1b2037d..faca019 100644 --- a/.github/workflows/release_build.yaml +++ b/.github/workflows/release_build.yaml @@ -1,4 +1,4 @@ -name: release_build +name: release-build on: push: @@ -16,36 +16,51 @@ permissions: id-token: write # 用于发布到 PyPI jobs: - setup: - uses: ./.github/workflows/setup.yaml - with: - install-deps: dev - python-version: "3.12" - secrets: inherit - - build: - needs: setup + release-build: runs-on: ubuntu-latest + permissions: + contents: write # 用于创建 GitHub Release steps: - - name: Run tests - run: uvx nox -s test_all + - uses: actions/checkout@v4 - - name: Build package - run: uvx nox -s build + - name: Load secret + uses: 1password/load-secrets-action@v2 + with: + export-env: true + env: + OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} + PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential + PYPI_TOKEN: op://shawndengdev/pypi_token/credential - - name: Create Release - id: create_release - uses: softprops/action-gh-release@v2 + - uses: actions/setup-python@v5 with: - token: ${{ github.token }} - tag_name: ${{ github.event.inputs.version || github.ref_name }} - draft: false - prerelease: false - files: | - dist/* + python-version: "3.12" + + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + version: ">=0.4.0" + + - name: Install dependencies + run: uv sync --extra dev + + - name: Build and test + run: | + uvx nox -s lint + uvx nox -s test + uvx nox -s build - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + env: + UV_PUBLISH_TOKEN: ${{ env.PYPI_TOKEN }} + run: uv publish + + - name: Release + uses: softprops/action-gh-release@v2 with: - packages-dir: dist/ - repository-url: https://upload.pypi.org/legacy/ + files: | + dist/*.tar.gz + dist/*.whl + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ env.PERSONAL_ACCESS_TOKEN }} diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml deleted file mode 100644 index d567114..0000000 --- a/.github/workflows/setup.yaml +++ /dev/null @@ -1,84 +0,0 @@ -name: Reusable Setup -on: - workflow_call: - inputs: - python-version: - required: false - type: string - default: "3.12" - install-deps: - required: false - type: string - default: "dev" # dev, docs, or none - secrets: - OP_SERVICE_ACCOUNT_TOKEN: - required: false - outputs: - 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: ${{ steps.set-token.outputs.PERSONAL_ACCESS_TOKEN }} - steps: - - name: Load secret - uses: 1password/load-secrets-action@v2 - with: - export-env: true - env: - OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} - PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential - - - name: Set token output - id: set-token - run: | - if [ -z "${PERSONAL_ACCESS_TOKEN}" ]; then - echo "Error: PERSONAL_ACCESS_TOKEN is not set" - exit 1 - fi - echo "PERSONAL_ACCESS_TOKEN=${PERSONAL_ACCESS_TOKEN}" >> $GITHUB_OUTPUT - - - name: Debug token (setup job) - run: | - echo "Token is set: ${{ steps.set-token.outputs.PERSONAL_ACCESS_TOKEN != '' }}" - echo "Token first char: ${PERSONAL_ACCESS_TOKEN:0:1}" - - - name: Check out - uses: actions/checkout@v4 - with: - fetch-depth: 0 - token: ${{ github.token }} - - - name: Setup Python - id: setup-python - uses: actions/setup-python@v5 - with: - python-version: ${{ inputs.python-version }} - - - name: Install uv - uses: astral-sh/setup-uv@v5 - with: - version: ">=0.4.0" - - - name: Get uv cache dir - id: get-uv-cache - run: echo "UV_CACHE_DIR=$(uv cache dir)" >> $GITHUB_OUTPUT - - - name: Install dependencies - if: ${{ inputs.install-deps != 'none' }} - run: uv sync --extra ${{ inputs.install-deps }} - - - name: Cache uv packages - uses: actions/cache@v4 - with: - path: ${{ steps.get-uv-cache.outputs.UV_CACHE_DIR }} - key: ${{ runner.os }}-uv-${{ hashFiles('**/pyproject.toml', '**/requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-uv- From 2ff64103849f481c3eeeb350f082b683b076d638 Mon Sep 17 00:00:00 2001 From: colyerdeng Date: Tue, 18 Feb 2025 12:59:14 +0800 Subject: [PATCH 15/15] refactor: update bump_version workflow 1. Remove setup.yaml dependency 2. Add Python and uv setup steps 3. Use github.token consistently --- .github/workflows/bump_version.yaml | 20 +++++++++-------- .../.github/workflows/bump_version.yaml | 22 ++++++++++++------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index 9642665..f241915 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -22,26 +22,28 @@ 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: Debug token (bump-version job) - run: | - echo "Token from setup job is set: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN != '' }}" - - name: Check out uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ github.token }} + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Install dependencies + run: uv sync --extra=dev + - id: cz name: Create bump and changelog uses: commitizen-tools/commitizen-action@master 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 e973ba0..f241915 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,13 +22,8 @@ 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: @@ -36,13 +31,24 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} + token: ${{ github.token }} + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Install dependencies + run: uv sync --extra=dev - id: cz name: Create bump and changelog uses: commitizen-tools/commitizen-action@master with: - github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} + github_token: ${{ github.token }} changelog_increment_filename: body.md increment: ${{ github.event.inputs.increment }} @@ -52,4 +58,4 @@ jobs: body_path: body.md tag_name: ${{ env.REVISION }} env: - GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ github.token }}