Skip to content

Commit 6ae8f7b

Browse files
fix: standardize token usage in GitHub Actions workflows
1 parent d88a7d4 commit 6ae8f7b

File tree

8 files changed

+34
-16
lines changed

8 files changed

+34
-16
lines changed

.github/workflows/bump_version.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,34 @@ permissions:
2222
pull-requests: write # 用于创建 PR
2323

2424
jobs:
25+
setup:
26+
uses: ./.github/workflows/setup.yaml
27+
secrets: inherit
28+
2529
bump-version:
2630
if: "!startsWith(github.event.head_commit.message, 'bump:')"
31+
needs: setup
2732
runs-on: ubuntu-latest
2833
name: "Bump version and create changelog with commitizen"
2934
steps:
3035
- name: Check out
3136
uses: actions/checkout@v4
3237
with:
3338
fetch-depth: 0
34-
token: ${{ needs.setup.outputs.personal-access-token || github.token }}
39+
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
3540

3641
- id: cz
3742
name: Create bump and changelog
3843
uses: commitizen-tools/commitizen-action@master
3944
with:
40-
github_token: ${{ needs.setup.outputs.personal-access-token || github.token }}
45+
github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
4146
changelog_increment_filename: body.md
4247
increment: ${{ github.event.inputs.increment }}
4348

44-
- name: Release
45-
uses: softprops/action-gh-release@v1
49+
- name: Create Release
50+
uses: softprops/action-gh-release@v2
4651
with:
4752
body_path: body.md
4853
tag_name: ${{ env.REVISION }}
4954
env:
50-
GITHUB_TOKEN: ${{ needs.setup.outputs.personal-access-token || github.token }}
55+
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}

.github/workflows/deploy_docs.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
secrets:
1818
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
1919
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
20+
outputs:
21+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2022

2123
deploy:
2224
needs: setup
@@ -25,4 +27,4 @@ jobs:
2527
- name: Build and deploy documentation
2628
run: uvx mkdocs gh-deploy --force
2729
env:
28-
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
30+
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}

.github/workflows/release_build.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
secrets:
2525
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
2626
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
27+
outputs:
28+
personal-access-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2729

2830
build:
2931
needs: setup
@@ -39,6 +41,7 @@ jobs:
3941
id: create_release
4042
uses: softprops/action-gh-release@v2
4143
with:
44+
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
4245
tag_name: ${{ github.event.inputs.version || github.ref_name }}
4346
draft: false
4447
prerelease: false

.github/workflows/setup.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ on:
1919
python-version:
2020
description: "The Python version that was set up"
2121
value: ${{ jobs.setup.outputs.python-version }}
22+
PERSONAL_ACCESS_TOKEN:
23+
description: "The personal access token"
24+
value: ${{ jobs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
2225

2326
jobs:
2427
setup:
2528
runs-on: ubuntu-latest
2629
outputs:
2730
python-version: ${{ steps.setup-python.outputs.python-version }}
31+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2832
steps:
2933
- name: Load secret
3034
if: ${{ inputs.install-deps != 'none' }}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ jobs:
3636
uses: actions/checkout@v4
3737
with:
3838
fetch-depth: 0
39-
token: ${{ needs.setup.outputs.personal-access-token || github.token }}
39+
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
4040

4141
- id: cz
4242
name: Create bump and changelog
4343
uses: commitizen-tools/commitizen-action@master
4444
with:
45-
github_token: ${{ needs.setup.outputs.personal-access-token || github.token }}
45+
github_token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
4646
changelog_increment_filename: body.md
4747
increment: ${{ github.event.inputs.increment }}
4848

49-
- name: Release
50-
uses: softprops/action-gh-release@v1
49+
- name: Create Release
50+
uses: softprops/action-gh-release@v2
5151
with:
5252
body_path: body.md
5353
tag_name: ${{ env.REVISION }}
5454
env:
55-
GITHUB_TOKEN: ${{ needs.setup.outputs.personal-access-token || github.token }}
55+
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN }}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ jobs:
1515
uses: ./.github/workflows/setup.yaml
1616
with:
1717
install-deps: docs
18-
python-version: "{{ cookiecutter.max_python_version }}"
19-
secrets:
20-
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
21-
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
18+
secrets: inherit
2219

2320
deploy:
2421
needs: setup
@@ -27,5 +24,5 @@ jobs:
2724
- name: Build and deploy documentation
2825
run: uvx mkdocs gh-deploy --force
2926
env:
30-
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
27+
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
3128
{% endif %}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
secrets:
2525
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
2626
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
27+
outputs:
28+
personal-access-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2729

2830
build:
2931
needs: setup
@@ -39,6 +41,7 @@ jobs:
3941
id: create_release
4042
uses: softprops/action-gh-release@v2
4143
with:
44+
token: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
4245
tag_name: ${{ github.event.inputs.version || github.ref_name }}
4346
draft: false
4447
prerelease: false

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ on:
2020
python-version:
2121
description: "The Python version that was set up"
2222
value: ${{ jobs.setup.outputs.python-version }}
23+
PERSONAL_ACCESS_TOKEN:
24+
description: "The personal access token"
25+
value: ${{ jobs.setup.outputs.PERSONAL_ACCESS_TOKEN }}
2326

2427
jobs:
2528
setup:
2629
runs-on: ubuntu-latest
2730
outputs:
2831
python-version: ${{ steps.setup-python.outputs.python-version }}
32+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
2933
steps:
3034
- name: Load secret
3135
if: ${{ inputs.install-deps != 'none' }}

0 commit comments

Comments
 (0)