Skip to content

Commit e96adfe

Browse files
feat: update github action and project template
1 parent 4b21984 commit e96adfe

File tree

23 files changed

+1219
-322
lines changed

23 files changed

+1219
-322
lines changed

.github/workflows/bump_version.yaml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,47 @@ on:
44
push:
55
branches:
66
- master
7+
- main
78
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
823

924
jobs:
1025
bump-version:
1126
if: "!startsWith(github.event.head_commit.message, 'bump:')"
1227
runs-on: ubuntu-latest
1328
name: "Bump version and create changelog with commitizen"
1429
steps:
15-
- name: Load secret
16-
uses: 1password/load-secrets-action@v2
17-
with:
18-
export-env: true
19-
env:
20-
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
21-
PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential
22-
2330
- name: Check out
2431
uses: actions/checkout@v4
2532
with:
2633
fetch-depth: 0
27-
token: '${{ env.PERSONAL_ACCESS_TOKEN }}'
34+
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2835

29-
- name: Create bump and changelog
36+
- id: cz
37+
name: Create bump and changelog
3038
uses: commitizen-tools/commitizen-action@master
3139
with:
32-
github_token: ${{ env.PERSONAL_ACCESS_TOKEN }}
33-
branch: master
40+
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
41+
changelog_increment_filename: body.md
42+
increment: ${{ github.event.inputs.increment }}
43+
44+
- name: Release
45+
uses: softprops/action-gh-release@v1
46+
with:
47+
body_path: body.md
48+
tag_name: ${{ env.REVISION }}
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

.github/workflows/deploy_docs.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Deploy Docs
2+
3+
on:
4+
push:
5+
tags:
6+
- '*' # 匹配所有标签
7+
workflow_dispatch: # 保留手动触发选项
8+
9+
permissions:
10+
contents: write # 用于部署到 GitHub Pages
11+
12+
jobs:
13+
setup:
14+
uses: ./.github/workflows/setup.yaml
15+
with:
16+
install-deps: docs
17+
secrets:
18+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
19+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
20+
21+
deploy:
22+
needs: setup
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Build and deploy documentation
26+
run: uvx mkdocs gh-deploy --force
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

.github/workflows/lint.yaml

Lines changed: 79 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,92 @@
11
name: lint_and_unittest
22

3-
on: [ push, pull_request ]
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 中添加评论
414

515
jobs:
6-
lint_and_unittest:
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
727
runs-on: ubuntu-latest
828
steps:
9-
- name: Load secret
10-
uses: 1password/load-secrets-action@v2
11-
with:
12-
export-env: true
13-
env:
14-
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
15-
PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential
29+
- name: Check Python version
30+
run: python --version
1631

17-
- name: Check out
18-
uses: actions/checkout@v4
19-
with:
20-
fetch-depth: 0
21-
token: '${{ env.PERSONAL_ACCESS_TOKEN }}'
32+
- name: Run lint checks
33+
id: lint
34+
run: uvx nox -s lint
35+
continue-on-error: true
2236

23-
- uses: actions/setup-python@v5
37+
- name: Comment on PR
38+
if: github.event_name == 'pull_request' && steps.lint.outcome == 'failure'
39+
uses: actions/github-script@v7
2440
with:
25-
python-version: "3.12"
41+
script: |
42+
const output = `#### 🔍 Lint Check Failed
43+
Please fix the linting issues before merging.
44+
You can run \`nox -s lint\` locally to check and fix issues.`;
45+
46+
github.rest.issues.createComment({
47+
issue_number: context.issue.number,
48+
owner: context.repo.owner,
49+
repo: context.repo.repo,
50+
body: output
51+
})
2652
27-
- name: Install uv
28-
uses: astral-sh/setup-uv@v5
29-
with:
30-
version: ">=0.4.0"
53+
- name: Check lint result
54+
if: steps.lint.outcome == 'failure'
55+
run: exit 1
3156

32-
- name: Install dependencies
33-
run: uv sync --extra dev
57+
test-all:
58+
needs: setup
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Run tests on all Python versions
62+
id: test
63+
run: uvx nox -s test_all
64+
continue-on-error: true
3465

35-
- name: Run lint checks
36-
run: uvx nox -s lint
66+
- name: Upload coverage reports
67+
if: success()
68+
uses: codecov/codecov-action@v4
69+
with:
70+
token: ${{ secrets.CODECOV_TOKEN }}
71+
file: ./coverage.xml
72+
flags: unittests
73+
74+
- name: Comment on PR
75+
if: github.event_name == 'pull_request' && steps.test.outcome == 'failure'
76+
uses: actions/github-script@v7
77+
with:
78+
script: |
79+
const output = `#### ❌ Tests Failed
80+
Please fix the test failures before merging.
81+
You can run \`nox -s test_all\` locally to debug the failures.`;
82+
83+
github.rest.issues.createComment({
84+
issue_number: context.issue.number,
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
body: output
88+
})
3789
38-
- name: Run tests
39-
run: uvx nox -s test
90+
- name: Check test result
91+
if: steps.test.outcome == 'failure'
92+
run: exit 1

.github/workflows/release_build.yaml

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,52 @@
1-
name: release-build
1+
name: release_build
2+
23
on:
3-
workflow_dispatch:
44
push:
55
tags:
6-
- '*.*.*'
6+
- '*' # 匹配所有标签
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+
permissions:
15+
contents: write # 用于创建 release
16+
id-token: write # 用于发布到 PyPI
717

818
jobs:
9-
release-build:
19+
setup:
20+
uses: ./.github/workflows/setup.yaml
21+
with:
22+
install-deps: dev
23+
python-version: "3.12"
24+
secrets:
25+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
26+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
27+
28+
build:
29+
needs: setup
1030
runs-on: ubuntu-latest
11-
permissions:
12-
contents: write # 用于创建 GitHub Release
1331
steps:
14-
- uses: actions/checkout@v4
32+
- name: Run tests
33+
run: uvx nox -s test_all
1534

16-
- name: Load secret
17-
uses: 1password/load-secrets-action@v2
18-
with:
19-
export-env: true
20-
env:
21-
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
22-
PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential
23-
PYPI_TOKEN: op://shawndengdev/pypi_token/credential
24-
25-
- uses: actions/setup-python@v5
26-
with:
27-
python-version: "3.12"
35+
- name: Build package
36+
run: uvx nox -s build
2837

29-
- name: Install uv
30-
uses: astral-sh/setup-uv@v5
38+
- name: Create Release
39+
id: create_release
40+
uses: softprops/action-gh-release@v2
3141
with:
32-
version: ">=0.4.0"
33-
34-
- name: Install dependencies
35-
run: uv sync --extra dev
36-
37-
- name: Build and test
38-
run: |
39-
uvx nox -s lint
40-
uvx nox -s test
41-
uvx nox -s build
42+
tag_name: ${{ github.event.inputs.version || github.ref_name }}
43+
draft: false
44+
prerelease: false
45+
files: |
46+
dist/*
4247
4348
- name: Publish to PyPI
44-
env:
45-
UV_PUBLISH_TOKEN: ${{ env.PYPI_TOKEN }}
46-
run: uv publish
47-
48-
- name: Release
49-
uses: softprops/action-gh-release@v2
49+
uses: pypa/gh-action-pypi-publish@release/v1
5050
with:
51-
files: |
52-
dist/*.tar.gz
53-
dist/*.whl
54-
generate_release_notes: true
55-
env:
56-
GITHUB_TOKEN: ${{ env.PERSONAL_ACCESS_TOKEN }}
51+
packages-dir: dist/
52+
repository-url: https://upload.pypi.org/legacy/

.github/workflows/setup.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Reusable Setup
2+
on:
3+
workflow_call:
4+
inputs:
5+
python-version:
6+
required: false
7+
type: string
8+
default: "3.12"
9+
install-deps:
10+
required: false
11+
type: string
12+
default: "dev" # dev, docs, or none
13+
secrets:
14+
OP_SERVICE_ACCOUNT_TOKEN:
15+
required: false
16+
PERSONAL_ACCESS_TOKEN:
17+
required: false
18+
outputs:
19+
python-version:
20+
description: "The Python version that was set up"
21+
value: ${{ jobs.setup.outputs.python-version }}
22+
23+
jobs:
24+
setup:
25+
runs-on: ubuntu-latest
26+
outputs:
27+
python-version: ${{ steps.setup-python.outputs.python-version }}
28+
steps:
29+
- name: Load secret
30+
if: ${{ inputs.install-deps != 'none' }}
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 || github.token }}
43+
44+
- name: Setup Python
45+
id: setup-python
46+
uses: actions/setup-python@v5
47+
with:
48+
python-version: ${{ inputs.python-version }}
49+
cache: 'pip'
50+
cache-dependency-path: |
51+
**/requirements*.txt
52+
**/pyproject.toml
53+
**/poetry.lock
54+
**/Pipfile.lock
55+
56+
- name: Install uv
57+
uses: astral-sh/setup-uv@v5
58+
with:
59+
version: ">=0.4.0"
60+
61+
- name: Get uv cache dir
62+
id: get-uv-cache
63+
run: echo "UV_CACHE_DIR=$(uv cache dir)" >> $GITHUB_OUTPUT
64+
65+
- name: Cache uv packages
66+
uses: actions/cache@v4
67+
with:
68+
path: ${{ steps.get-uv-cache.outputs.UV_CACHE_DIR }}
69+
key: ${{ runner.os }}-uv-${{ hashFiles('**/pyproject.toml', '**/requirements*.txt') }}
70+
restore-keys: |
71+
${{ runner.os }}-uv-
72+
73+
- name: Install dependencies
74+
if: ${{ inputs.install-deps != 'none' }}
75+
run: uv sync --extra ${{ inputs.install-deps }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
/dist/
1010
**/__pycache__/
1111
*.pyc
12+
# MkDocs build output
13+
/site/

0 commit comments

Comments
 (0)