Skip to content

Commit 5c645df

Browse files
author
colyerdeng
committed
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
1 parent 5a82c29 commit 5c645df

File tree

5 files changed

+70
-128
lines changed

5 files changed

+70
-128
lines changed

.github/workflows/bump_version.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ on:
1818
default: patch
1919

2020
permissions:
21-
contents: write
21+
contents: write # 用于创建和推送标签
22+
pull-requests: write # 用于创建 PR
2223

2324
jobs:
2425
setup:

.github/workflows/deploy_docs.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@ permissions:
1010
contents: write # 用于部署到 GitHub Pages
1111

1212
jobs:
13-
setup:
14-
uses: ./.github/workflows/setup.yaml
15-
with:
16-
install-deps: docs
17-
secrets: inherit
18-
1913
deploy:
20-
needs: setup
2114
runs-on: ubuntu-latest
2215
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+
2330
- name: Build and deploy documentation
2431
run: uv run mkdocs gh-deploy --force
2532
env:

.github/workflows/lint.yaml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,26 @@ permissions:
1313
pull-requests: write # 用于在 PR 中添加评论
1414

1515
jobs:
16-
setup:
17-
uses: ./.github/workflows/setup.yaml
18-
with:
19-
install-deps: dev
20-
python-version: "3.12"
21-
secrets: inherit
22-
2316
check:
24-
needs: setup
2517
runs-on: ubuntu-latest
2618
steps:
2719
- name: Checkout code
2820
uses: actions/checkout@v4
2921

22+
- name: Setup Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.12"
26+
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v5
29+
30+
- name: Install dependencies
31+
run: uv sync --extra=dev
32+
3033
- name: Run lint checks
3134
id: lint
32-
run: uv tool run nox -s lint
35+
run: uvx nox -s lint
3336
continue-on-error: true
3437

3538
- name: Comment on PR (Lint)
@@ -54,7 +57,7 @@ jobs:
5457

5558
- name: Run tests
5659
id: test
57-
run: uv tool run nox -s test_all
60+
run: uvx nox -s test_all
5861
continue-on-error: true
5962

6063
- name: Upload coverage reports

.github/workflows/release_build.yaml

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: release_build
1+
name: release-build
22

33
on:
44
push:
@@ -16,36 +16,51 @@ permissions:
1616
id-token: write # 用于发布到 PyPI
1717

1818
jobs:
19-
setup:
20-
uses: ./.github/workflows/setup.yaml
21-
with:
22-
install-deps: dev
23-
python-version: "3.12"
24-
secrets: inherit
25-
26-
build:
27-
needs: setup
19+
release-build:
2820
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write # 用于创建 GitHub Release
2923
steps:
30-
- name: Run tests
31-
run: uvx nox -s test_all
24+
- uses: actions/checkout@v4
3225

33-
- name: Build package
34-
run: uvx nox -s build
26+
- name: Load secret
27+
uses: 1password/load-secrets-action@v2
28+
with:
29+
export-env: true
30+
env:
31+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
32+
PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential
33+
PYPI_TOKEN: op://shawndengdev/pypi_token/credential
3534

36-
- name: Create Release
37-
id: create_release
38-
uses: softprops/action-gh-release@v2
35+
- uses: actions/setup-python@v5
3936
with:
40-
token: ${{ github.token }}
41-
tag_name: ${{ github.event.inputs.version || github.ref_name }}
42-
draft: false
43-
prerelease: false
44-
files: |
45-
dist/*
37+
python-version: "3.12"
38+
39+
- name: Install uv
40+
uses: astral-sh/setup-uv@v5
41+
with:
42+
version: ">=0.4.0"
43+
44+
- name: Install dependencies
45+
run: uv sync --extra dev
46+
47+
- name: Build and test
48+
run: |
49+
uvx nox -s lint
50+
uvx nox -s test
51+
uvx nox -s build
4652
4753
- name: Publish to PyPI
48-
uses: pypa/gh-action-pypi-publish@release/v1
54+
env:
55+
UV_PUBLISH_TOKEN: ${{ env.PYPI_TOKEN }}
56+
run: uv publish
57+
58+
- name: Release
59+
uses: softprops/action-gh-release@v2
4960
with:
50-
packages-dir: dist/
51-
repository-url: https://upload.pypi.org/legacy/
61+
files: |
62+
dist/*.tar.gz
63+
dist/*.whl
64+
generate_release_notes: true
65+
env:
66+
GITHUB_TOKEN: ${{ env.PERSONAL_ACCESS_TOKEN }}

.github/workflows/setup.yaml

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

0 commit comments

Comments
 (0)