Skip to content

Commit 003092e

Browse files
colyerdengShawnDen-coder
authored andcommitted
refactor: optimize GitHub Actions workflows
1. Remove setup.yaml dependency 2. Add Python and uv setup steps to each workflow 3. Use github.token consistently 4. Update template workflows to match
1 parent cdab063 commit 003092e

File tree

5 files changed

+92
-92
lines changed

5 files changed

+92
-92
lines changed

.github/workflows/bump_version.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,28 @@ permissions:
2222
pull-requests: write # 用于创建 PR
2323

2424
jobs:
25-
setup:
26-
uses: ./.github/workflows/setup.yaml
27-
secrets: inherit
28-
2925
bump-version:
3026
if: "!startsWith(github.event.head_commit.message, 'bump:')"
31-
needs: setup
3227
runs-on: ubuntu-latest
3328
name: "Bump version and create changelog with commitizen"
3429
steps:
35-
- name: Debug token (bump-version job)
36-
run: |
37-
echo "Token from setup job is set: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN != '' }}"
38-
3930
- name: Check out
4031
uses: actions/checkout@v4
4132
with:
4233
fetch-depth: 0
4334
token: ${{ github.token }}
4435

36+
- name: Setup Python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3.12"
40+
41+
- name: Install uv
42+
uses: astral-sh/setup-uv@v5
43+
44+
- name: Install dependencies
45+
run: uv sync --extra=dev
46+
4547
- id: cz
4648
name: Create bump and changelog
4749
uses: commitizen-tools/commitizen-action@master

.github/workflows/deploy_docs.yaml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ 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:
18-
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
19-
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
20-
outputs:
21-
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
22-
2313
deploy:
24-
needs: setup
2514
runs-on: ubuntu-latest
2615
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+
2730
- name: Build and deploy documentation
28-
run: uvx mkdocs gh-deploy --force
31+
run: uv run mkdocs gh-deploy --force
2932
env:
30-
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
33+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/lint.yaml

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,29 @@ 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:
22-
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
23-
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
24-
25-
lint:
26-
needs: setup
16+
check:
2717
runs-on: ubuntu-latest
2818
steps:
2919
- name: Checkout code
3020
uses: actions/checkout@v4
3121

32-
- name: Set up Python
22+
- name: Setup Python
3323
uses: actions/setup-python@v5
3424
with:
3525
python-version: "3.12"
3626

3727
- name: Install uv
3828
uses: astral-sh/setup-uv@v5
3929

30+
- name: Install dependencies
31+
run: uv sync --extra=dev
32+
4033
- name: Run lint checks
4134
id: lint
42-
run: uv tool run nox -s lint
35+
run: uvx nox -s lint
4336
continue-on-error: true
4437

45-
- name: Comment on PR
38+
- name: Comment on PR (Lint)
4639
if: github.event_name == 'pull_request' && steps.lint.outcome == 'failure'
4740
uses: actions/github-script@v7
4841
with:
@@ -62,24 +55,9 @@ jobs:
6255
if: steps.lint.outcome == 'failure'
6356
run: exit 1
6457

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: Set up 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
58+
- name: Run tests
8159
id: test
82-
run: uv tool run nox -s test_all
60+
run: uvx nox -s test_all
8361
continue-on-error: true
8462

8563
- name: Upload coverage reports
@@ -90,7 +68,7 @@ jobs:
9068
file: ./coverage.xml
9169
flags: unittests
9270

93-
- name: Comment on PR
71+
- name: Comment on PR (Tests)
9472
if: github.event_name == 'pull_request' && steps.test.outcome == 'failure'
9573
uses: actions/github-script@v7
9674
with:

.github/workflows/release_build.yaml

Lines changed: 41 additions & 30 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,40 +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:
25-
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
26-
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
27-
outputs:
28-
personal-access-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
29-
30-
build:
31-
needs: setup
19+
release-build:
3220
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write # 用于创建 GitHub Release
3323
steps:
34-
- name: Run tests
35-
run: uvx nox -s test_all
24+
- uses: actions/checkout@v4
3625

37-
- name: Build package
38-
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
3934

40-
- name: Create Release
41-
id: create_release
42-
uses: softprops/action-gh-release@v2
35+
- uses: actions/setup-python@v5
4336
with:
44-
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
45-
tag_name: ${{ github.event.inputs.version || github.ref_name }}
46-
draft: false
47-
prerelease: false
48-
files: |
49-
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
5052
5153
- name: Publish to PyPI
52-
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
5360
with:
54-
packages-dir: dist/
55-
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 }}

repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/bump_version.yaml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,33 @@ permissions:
2222
pull-requests: write # 用于创建 PR
2323

2424
jobs:
25-
setup:
26-
uses: ./.github/workflows/setup.yaml
27-
secrets: inherit
28-
2925
bump-version:
3026
if: "!startsWith(github.event.head_commit.message, 'bump:')"
31-
needs: setup
3227
runs-on: ubuntu-latest
3328
name: "Bump version and create changelog with commitizen"
3429
steps:
3530
- name: Check out
3631
uses: actions/checkout@v4
3732
with:
3833
fetch-depth: 0
39-
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
34+
token: ${{ github.token }}
35+
36+
- name: Setup Python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3.12"
40+
41+
- name: Install uv
42+
uses: astral-sh/setup-uv@v5
43+
44+
- name: Install dependencies
45+
run: uv sync --extra=dev
4046

4147
- id: cz
4248
name: Create bump and changelog
4349
uses: commitizen-tools/commitizen-action@master
4450
with:
45-
github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
51+
github_token: ${{ github.token }}
4652
changelog_increment_filename: body.md
4753
increment: ${{ github.event.inputs.increment }}
4854

@@ -52,4 +58,4 @@ jobs:
5258
body_path: body.md
5359
tag_name: ${{ env.REVISION }}
5460
env:
55-
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
61+
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)