Skip to content

Commit 03045e1

Browse files
author
colyerdeng
committed
feat: update
1 parent d809fac commit 03045e1

File tree

17 files changed

+642
-110
lines changed

17 files changed

+642
-110
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
# MkDocs build output
1313
/site/
1414
htmlcov/
15-
.env
15+
.env
16+
test-output/

pyproject.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ docs = [
3535
[project.scripts]
3636
repo-scaffold = "repo_scaffold.cli:cli"
3737

38-
[tool.setuptools.package-data]
39-
repo_scaffold = ["templates/**/*", "components/**/*"]
40-
4138
[build-system]
4239
requires = ["hatchling"]
4340
build-backend = "hatchling.build"
4441

42+
[tool.hatch.build.targets.wheel]
43+
packages = ["repo_scaffold"]
44+
include = [
45+
"repo_scaffold/templates/**/*",
46+
"repo_scaffold/components/**/*"
47+
]
48+
49+
50+
4551
[dependency-groups]
4652
dev = [
4753
"pytest-click>=1.1.0",

repo_scaffold/components/github_actions/component.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: github_actions
22
display_name: GitHub Actions
33
description: GitHub Actions CI/CD workflows for testing and deployment
44
category: ci_cd
5-
dependencies: []
5+
dependencies:
6+
- task_automation
67
conflicts: []
78
cookiecutter_vars:
89
use_github_actions: true
910
files:
1011
- src: .github/workflows/ci-tests.yaml.j2
1112
dest: .github/workflows/ci-tests.yaml
12-
- src: .github/workflows/package-release.yaml.j2
13-
dest: .github/workflows/package-release.yaml
13+
1414
- src: .github/workflows/version-bump.yaml.j2
1515
dest: .github/workflows/version-bump.yaml
1616
hooks: {}

repo_scaffold/components/github_actions/files/.github/workflows/ci-tests.yaml.j2

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ jobs:
4545
- name: Run tests
4646
run: uv run pytest --cov={{cookiecutter.package_name}} --cov-report=xml --cov-report=term-missing
4747
{% endif -%}
48-
{% if cookiecutter.use_airflow_docker == "true" -%}
49-
docker-build-test:
50-
name: 🐳 Multi-platform Docker Build Test
48+
{% if cookiecutter.use_podman == "true" -%}
49+
container-build-test:
50+
name: 🐳 Container Build Test
5151
runs-on: ubuntu-latest
5252
steps:
5353
- name: Check out the repo
5454
uses: actions/checkout@v4
5555
- name: Set up QEMU
5656
uses: docker/setup-qemu-action@v3
57-
- name: Test Build Image (no push)
58-
id: build-image
57+
- name: Test Build Container (no push)
58+
id: build-container
5959
uses: redhat-actions/buildah-build@v2
6060
with:
6161
image: ${{ github.repository }}-test
6262
tags: test-${{ github.sha }}
63-
containerfiles: ./docker/Dockerfile
63+
containerfiles: ./container/Containerfile
6464
platforms: linux/amd64,linux/arm64
6565
{% if cookiecutter.use_private_pypi == "true" -%}
6666
build-args: |-

repo_scaffold/components/github_actions/files/.github/workflows/package-release.yaml.j2

Lines changed: 0 additions & 66 deletions
This file was deleted.

repo_scaffold/components/podman/component.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ category: containerization
55
dependencies: []
66
conflicts:
77
- docker
8-
- airflow_docker
98
cookiecutter_vars:
109
use_podman: true
1110
use_containers: true

repo_scaffold/components/pre_commit/component.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ name: pre_commit
22
display_name: Pre-commit Hooks
33
description: Pre-commit hooks for code quality and validation
44
category: quality
5-
dependencies: []
5+
dependencies:
6+
- task_automation # for use_uv variable
7+
- github_actions # for use_github_actions variable
68
conflicts: []
79
cookiecutter_vars:
810
use_pre_commit: true

repo_scaffold/components/private_pypi/component.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: pypi
2+
display_name: PyPI Publishing
3+
description: PyPI publishing support for both public PyPI and private PyPI servers
4+
category: packaging
5+
dependencies:
6+
- github_actions
7+
- task_automation
8+
conflicts: []
9+
cookiecutter_vars:
10+
use_pypi: true
11+
pypi_type:
12+
- "public"
13+
- "private"
14+
# Public PyPI settings (default)
15+
use_public_pypi: true
16+
# Private PyPI settings
17+
use_private_pypi: false
18+
private_pypi_name: "homelab"
19+
private_pypi_url: "https://pypiserver.example.com/simple/"
20+
files:
21+
- src: pypi-release.yaml.j2
22+
dest: .github/workflows/pypi-release.yaml
23+
hooks: {}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: 📦 PyPI Release
2+
on:
3+
push:
4+
tags:
5+
- '[0-9]+.[0-9]+.[0-9]+' # 匹配类似 1.0.0, 2.1.3 等格式的标签
6+
workflow_dispatch:
7+
permissions:
8+
contents: write # 用于创建 release
9+
id-token: write # 用于发布到 PyPI
10+
jobs:
11+
build-and-test:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
should-publish-public: ${{ steps.determine-strategy.outputs.publish-public }}
15+
should-publish-private: ${{ steps.determine-strategy.outputs.publish-private }}
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Determine publishing strategy
21+
id: determine-strategy
22+
run: |
23+
# 根据配置决定发布策略
24+
{% if cookiecutter.use_public_pypi == "true" -%}
25+
# 公共 PyPI 模式:同时发布到公共和私有
26+
echo "publish-public=true" >> $GITHUB_OUTPUT
27+
{% if cookiecutter.use_private_pypi == "true" -%}
28+
echo "publish-private=true" >> $GITHUB_OUTPUT
29+
{% else -%}
30+
echo "publish-private=false" >> $GITHUB_OUTPUT
31+
{% endif -%}
32+
{% else -%}
33+
# 仅私有 PyPI 模式:只发布到私有
34+
echo "publish-public=false" >> $GITHUB_OUTPUT
35+
{% if cookiecutter.use_private_pypi == "true" -%}
36+
echo "publish-private=true" >> $GITHUB_OUTPUT
37+
{% else -%}
38+
echo "publish-private=false" >> $GITHUB_OUTPUT
39+
{% endif -%}
40+
{% endif -%}
41+
42+
{% if cookiecutter.use_task == "true" -%}
43+
- name: Install Task
44+
uses: arduino/setup-task@v2
45+
{% endif -%}
46+
- name: Install uv
47+
uses: astral-sh/setup-uv@v5
48+
49+
# Environment setup and testing
50+
- name: Initialize environment and test
51+
env:
52+
{% if cookiecutter.use_private_pypi == "true" -%}
53+
UV_INDEX_{{cookiecutter.private_pypi_name | upper}}_USERNAME: ${{ secrets.PYPI_SERVER_USERNAME }}
54+
UV_INDEX_{{cookiecutter.private_pypi_name | upper}}_PASSWORD: ${{ secrets.PYPI_SERVER_PASSWORD }}
55+
{% endif -%}
56+
{% if cookiecutter.use_task == "true" -%}
57+
run: |
58+
task init # 初始化项目环境
59+
task lint # 运行代码检查
60+
task test:all # 运行所有测试
61+
{% else -%}
62+
run: |
63+
uv sync --extra dev
64+
uv run ruff check .
65+
uv run ruff format --check .
66+
uv run pytest --cov={{cookiecutter.package_name}} tests/
67+
{% endif -%}
68+
69+
# Build package
70+
- name: Build package
71+
{% if cookiecutter.use_task == "true" -%}
72+
run: task build
73+
{% else -%}
74+
run: uv build
75+
{% endif -%}
76+
77+
# Upload build artifacts
78+
- name: Upload build artifacts
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: python-package-distributions
82+
path: dist/
83+
retention-days: 1
84+
85+
publish-to-public-pypi:
86+
name: Publish to Public PyPI
87+
needs: build-and-test
88+
if: needs.build-and-test.outputs.should-publish-public == 'true'
89+
runs-on: ubuntu-latest
90+
permissions:
91+
id-token: write # 用于 PyPI trusted publishing
92+
steps:
93+
- name: Download build artifacts
94+
uses: actions/download-artifact@v4
95+
with:
96+
name: python-package-distributions
97+
path: dist/
98+
99+
- name: Publish to PyPI
100+
uses: pypa/gh-action-pypi-publish@release/v1
101+
with:
102+
# Use trusted publishing (no token needed)
103+
# Configure at: https://pypi.org/manage/account/publishing/
104+
print-hash: true
105+
106+
publish-to-private-pypi:
107+
name: Publish to Private PyPI
108+
needs: build-and-test
109+
if: needs.build-and-test.outputs.should-publish-private == 'true'
110+
runs-on: ubuntu-latest
111+
steps:
112+
- name: Download build artifacts
113+
uses: actions/download-artifact@v4
114+
with:
115+
name: python-package-distributions
116+
path: dist/
117+
118+
- name: Install uv
119+
uses: astral-sh/setup-uv@v5
120+
121+
- name: Publish to Private PyPI
122+
env:
123+
UV_PUBLISH_USERNAME: ${{ secrets.PYPI_SERVER_USERNAME }}
124+
UV_PUBLISH_PASSWORD: ${{ secrets.PYPI_SERVER_PASSWORD }}
125+
run: |
126+
uv publish \
127+
--publish-url {{cookiecutter.private_pypi_url | replace('/simple/', '/') }} \
128+
--username $UV_PUBLISH_USERNAME \
129+
--password $UV_PUBLISH_PASSWORD
130+
131+
create-github-release:
132+
name: Create GitHub Release
133+
needs: [build-and-test, publish-to-public-pypi, publish-to-private-pypi]
134+
if: always() && needs.build-and-test.result == 'success'
135+
runs-on: ubuntu-latest
136+
permissions:
137+
contents: write # 用于创建 GitHub Release
138+
steps:
139+
- name: Download build artifacts
140+
uses: actions/download-artifact@v4
141+
with:
142+
name: python-package-distributions
143+
path: dist/
144+
145+
- name: Create GitHub Release
146+
uses: softprops/action-gh-release@v2
147+
with:
148+
files: |
149+
dist/*.tar.gz
150+
dist/*.whl
151+
generate_release_notes: true
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)