Skip to content

Commit 56fe2d0

Browse files
author
colyerdeng
committed
ci: optimize github actions workflows
- Use github.token instead of PAT - Remove debug steps and simplify configurations - Merge lint and test jobs - Standardize secrets inheritance - Fix uv command in deploy docs workflow
1 parent 661f8bb commit 56fe2d0

File tree

5 files changed

+15
-56
lines changed

5 files changed

+15
-56
lines changed

.github/workflows/bump_version.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ on:
1818
default: patch
1919

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

2423
jobs:
2524
setup:
@@ -36,13 +35,13 @@ jobs:
3635
uses: actions/checkout@v4
3736
with:
3837
fetch-depth: 0
39-
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
38+
token: ${{ github.token }}
4039

4140
- id: cz
4241
name: Create bump and changelog
4342
uses: commitizen-tools/commitizen-action@master
4443
with:
45-
github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
44+
github_token: ${{ github.token }}
4645
changelog_increment_filename: body.md
4746
increment: ${{ github.event.inputs.increment }}
4847

@@ -52,4 +51,4 @@ jobs:
5251
body_path: body.md
5352
tag_name: ${{ env.REVISION }}
5453
env:
55-
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
54+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/deploy_docs.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ jobs:
1414
uses: ./.github/workflows/setup.yaml
1515
with:
1616
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 }}
17+
secrets: inherit
2218

2319
deploy:
2420
needs: setup
@@ -27,4 +23,4 @@ jobs:
2723
- name: Build and deploy documentation
2824
run: uvx mkdocs gh-deploy --force
2925
env:
30-
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
26+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/lint.yaml

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,22 @@ jobs:
1717
uses: ./.github/workflows/setup.yaml
1818
with:
1919
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 }}
20+
python-version: "3.12"
21+
secrets: inherit
2422

25-
lint:
23+
check:
2624
needs: setup
2725
runs-on: ubuntu-latest
2826
steps:
2927
- name: Checkout code
3028
uses: actions/checkout@v4
3129

32-
- name: Set up 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-
4030
- name: Run lint checks
4131
id: lint
4232
run: uv tool run nox -s lint
4333
continue-on-error: true
4434

45-
- name: Comment on PR
35+
- name: Comment on PR (Lint)
4636
if: github.event_name == 'pull_request' && steps.lint.outcome == 'failure'
4737
uses: actions/github-script@v7
4838
with:
@@ -62,22 +52,7 @@ jobs:
6252
if: steps.lint.outcome == 'failure'
6353
run: exit 1
6454

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
55+
- name: Run tests
8156
id: test
8257
run: uv tool run nox -s test_all
8358
continue-on-error: true
@@ -90,7 +65,7 @@ jobs:
9065
file: ./coverage.xml
9166
flags: unittests
9267

93-
- name: Comment on PR
68+
- name: Comment on PR (Tests)
9469
if: github.event_name == 'pull_request' && steps.test.outcome == 'failure'
9570
uses: actions/github-script@v7
9671
with:

.github/workflows/release_build.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ jobs:
2121
with:
2222
install-deps: dev
2323
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 }}
24+
secrets: inherit
2925

3026
build:
3127
needs: setup
@@ -41,7 +37,7 @@ jobs:
4137
id: create_release
4238
uses: softprops/action-gh-release@v2
4339
with:
44-
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
40+
token: ${{ github.token }}
4541
tag_name: ${{ github.event.inputs.version || github.ref_name }}
4642
draft: false
4743
prerelease: false

.github/workflows/setup.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,18 @@ on:
1313
secrets:
1414
OP_SERVICE_ACCOUNT_TOKEN:
1515
required: false
16-
PERSONAL_ACCESS_TOKEN:
17-
required: false
1816
outputs:
1917
python-version:
2018
description: "The Python version that was set up"
2119
value: ${{ jobs.setup.outputs.python-version }}
22-
PERSONAL_ACCESS_TOKEN:
23-
description: "The personal access token"
24-
value: ${{ jobs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
2520

2621
jobs:
2722
setup:
2823
runs-on: ubuntu-latest
2924
outputs:
3025
python-version: ${{ steps.setup-python.outputs.python-version }}
31-
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
3226
steps:
3327
- name: Load secret
34-
if: ${{ inputs.install-deps != 'none' }}
3528
uses: 1password/load-secrets-action@v2
3629
with:
3730
export-env: true
@@ -43,7 +36,7 @@ jobs:
4336
uses: actions/checkout@v4
4437
with:
4538
fetch-depth: 0
46-
token: ${{ env.PERSONAL_ACCESS_TOKEN || github.token }}
39+
token: ${{ github.token }}
4740

4841
- name: Setup Python
4942
id: setup-python

0 commit comments

Comments
 (0)