Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit 5336d93

Browse files
feat: update project CI/CD
1 parent b25814f commit 5336d93

19 files changed

+1724
-1106
lines changed

.github/workflows/bump_version.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Bump version
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
workflow_dispatch:
9+
inputs:
10+
increment:
11+
description: 'Version increment (major, minor, patch)'
12+
required: false
13+
type: choice
14+
options:
15+
- major
16+
- minor
17+
- patch
18+
default: patch
19+
20+
permissions:
21+
contents: write # 用于创建和推送标签
22+
pull-requests: write # 用于创建 PR
23+
24+
jobs:
25+
bump-version:
26+
if: "!startsWith(github.event.head_commit.message, 'bump:')"
27+
runs-on: ubuntu-latest
28+
name: "Bump version and create changelog with commitizen"
29+
steps:
30+
- name: Load secret
31+
uses: 1password/load-secrets-action@v2
32+
with:
33+
export-env: true
34+
env:
35+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
36+
PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential
37+
38+
- name: Check out
39+
uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 0
42+
token: '${{ env.PERSONAL_ACCESS_TOKEN }}'
43+
44+
- name: Create bump and changelog
45+
uses: commitizen-tools/commitizen-action@master
46+
with:
47+
github_token: ${{ env.PERSONAL_ACCESS_TOKEN }}
48+
branch: master

.github/workflows/deploy_docs.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Deploy Docs
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+' # 匹配类似 1.0.0, 2.1.3 等格式的标签
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write # 用于部署到 GitHub Pages
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: "3.12"
23+
24+
- name: Install uv
25+
uses: astral-sh/setup-uv@v5
26+
27+
- name: Install dependencies
28+
run: uv sync --extra=docs
29+
30+
- name: Build and deploy documentation
31+
run: uv run mkdocs gh-deploy --force
32+
env:
33+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/lint.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: lint_and_unittest
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
pull-requests: write # 用于在 PR 中添加评论
14+
15+
jobs:
16+
setup:
17+
uses: ./.github/workflows/setup.yaml
18+
with:
19+
install-deps: dev
20+
python-version: "3.12" # 使用最新版本
21+
secrets:
22+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
23+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
24+
25+
lint:
26+
needs: setup
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Setup Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.12"
36+
37+
- name: Install uv
38+
uses: astral-sh/setup-uv@v5
39+
40+
- name: Run lint checks
41+
id: lint
42+
run: uv tool run nox -s lint
43+
continue-on-error: true
44+
45+
- name: Comment on PR
46+
if: github.event_name == 'pull_request' && steps.lint.outcome == 'failure'
47+
uses: actions/github-script@v7
48+
with:
49+
script: |
50+
const output = `#### 🔍 Lint Check Failed
51+
Please fix the linting issues before merging.
52+
You can run \`nox -s lint\` locally to check and fix issues.`;
53+
54+
github.rest.issues.createComment({
55+
issue_number: context.issue.number,
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
body: output
59+
})
60+
61+
- name: Check lint result
62+
if: steps.lint.outcome == 'failure'
63+
run: exit 1
64+
65+
test-all:
66+
needs: setup
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v4
71+
72+
- name: Setup Python
73+
uses: actions/setup-python@v5
74+
with:
75+
python-version: "3.12"
76+
77+
- name: Install uv
78+
uses: astral-sh/setup-uv@v5
79+
80+
- name: Run tests on all Python versions
81+
id: test
82+
run: uv tool run nox -s test_all
83+
continue-on-error: true
84+
85+
- name: Comment on PR
86+
if: github.event_name == 'pull_request' && steps.test.outcome == 'failure'
87+
uses: actions/github-script@v7
88+
with:
89+
script: |
90+
const output = `#### ❌ Tests Failed
91+
Please fix the test failures before merging.
92+
You can run \`nox -s test_all\` locally to debug the failures.`;
93+
94+
github.rest.issues.createComment({
95+
issue_number: context.issue.number,
96+
owner: context.repo.owner,
97+
repo: context.repo.repo,
98+
body: output
99+
})
100+
101+
- name: Check test result
102+
if: steps.test.outcome == 'failure'
103+
run: exit 1

.github/workflows/release_build.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: release-build
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+' # 匹配类似 1.0.0, 2.1.3 等格式的标签
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Version to release (e.g. 1.0.0)'
11+
required: true
12+
type: string
13+
14+
15+
permissions:
16+
contents: write # 用于创建 release
17+
id-token: write # 用于发布到 PyPI
18+
19+
jobs:
20+
release-build:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write # 用于创建 GitHub Release
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Load secret
28+
uses: 1password/load-secrets-action@v2
29+
with:
30+
export-env: true
31+
env:
32+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
33+
PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential
34+
PYPI_TOKEN: op://shawndengdev/pypi_token/credential
35+
36+
- name: Setup Python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3"
40+
41+
- name: Install uv
42+
uses: astral-sh/setup-uv@v5
43+
with:
44+
version: ">=0.4.0"
45+
46+
- name: Install dependencies
47+
run: uv sync --extra dev
48+
49+
- name: Build and test
50+
run: |
51+
uvx nox -s lint
52+
uvx nox -s test
53+
uvx nox -s build
54+
55+
- name: Publish to PyPI
56+
env:
57+
UV_PUBLISH_TOKEN: ${{ env.PYPI_TOKEN }}
58+
run: uv publish
59+
60+
- name: Release
61+
uses: softprops/action-gh-release@v2
62+
with:
63+
files: |
64+
dist/*.tar.gz
65+
dist/*.whl
66+
generate_release_notes: true
67+
env:
68+
GITHUB_TOKEN: ${{ env.PERSONAL_ACCESS_TOKEN }}

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@
55
/build/
66
/coverage.xml
77
/.zip/
8-
/venv/
8+
/venv/
9+
/dist/
10+
**/__pycache__/
11+
*.pyc
12+
# MkDocs build output
13+
/site/

0 commit comments

Comments
 (0)