Skip to content

Commit 5a48086

Browse files
colyerdengShawnDen-coder
authored andcommitted
fix(template): improve GitHub Actions workflow templates
- fix: use {% raw %} to protect GitHub Actions expressions - fix: remove redundant setup.yaml workflow - fix: update version tag pattern to match semantic versioning - fix: use cookiecutter variables for Python version
1 parent d7a8f45 commit 5a48086

File tree

7 files changed

+50
-114
lines changed

7 files changed

+50
-114
lines changed

.github/workflows/deploy_docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Deploy Docs
33
on:
44
push:
55
tags:
6-
- '*' # 匹配所有标签
6+
- '[0-9]*.[0-9]*.[0-9]*' # 匹配语义化版本号标签 (e.g., 1.0.0, 1.0.0-beta)
77
workflow_dispatch: # 保留手动触发选项
88

99
permissions:

.github/workflows/release_build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: release-build
33
on:
44
push:
55
tags:
6-
- '*' # 匹配所有标签
6+
- '[0-9]*.[0-9]*.[0-9]*' # 匹配语义化版本号标签 (e.g., 1.0.0, 1.0.0-beta)
77
workflow_dispatch:
88
inputs:
99
version:

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ jobs:
3131
uses: actions/checkout@v4
3232
with:
3333
fetch-depth: 0
34-
token: ${{ github.token }}
34+
{% raw %}token: ${{ github.token }}{% endraw %}
3535

3636
- name: Setup Python
3737
uses: actions/setup-python@v5
3838
with:
39-
python-version: "3.12"
39+
python-version: "{{ cookiecutter.max_python_version[0] }}"
4040

4141
- name: Install uv
4242
uses: astral-sh/setup-uv@v5
@@ -48,14 +48,14 @@ jobs:
4848
name: Create bump and changelog
4949
uses: commitizen-tools/commitizen-action@master
5050
with:
51-
github_token: ${{ github.token }}
51+
{% raw %}github_token: ${{ github.token }}{% endraw %}
5252
changelog_increment_filename: body.md
53-
increment: ${{ github.event.inputs.increment }}
53+
{% raw %}increment: ${{ github.event.inputs.increment }}{% endraw %}
5454

5555
- name: Create Release
5656
uses: softprops/action-gh-release@v2
5757
with:
5858
body_path: body.md
59-
tag_name: ${{ env.REVISION }}
59+
{% raw %}tag_name: ${{ env.REVISION }}{% endraw %}
6060
env:
61-
GITHUB_TOKEN: ${{ github.token }}
61+
{% raw %}GITHUB_TOKEN: ${{ github.token }}{% endraw %}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Deploy Docs
44
on:
55
push:
66
tags:
7-
- '*' # 匹配所有标签
7+
- '[0-9]*.[0-9]*.[0-9]*' # 匹配语义化版本号标签 (e.g., 1.0.0, 1.0.0-beta)
88
workflow_dispatch: # 保留手动触发选项
99

1010
permissions:
@@ -24,5 +24,5 @@ jobs:
2424
- name: Build and deploy documentation
2525
run: uvx mkdocs gh-deploy --force
2626
env:
27-
GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}
27+
{% raw %}GITHUB_TOKEN: ${{ needs.setup.outputs.PERSONAL_ACCESS_TOKEN || github.token }}{% endraw %}
2828
{% endif %}

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

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: release_build
33
on:
44
push:
55
tags:
6-
- '*' # 匹配所有标签
6+
- '[0-9]*.[0-9]*.[0-9]*' # 匹配语义化版本号标签 (e.g., 1.0.0, 1.0.0-beta)
77
workflow_dispatch:
88
inputs:
99
version:
@@ -16,40 +16,50 @@ 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: "{{ cookiecutter.max_python_version }}"
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-
3019
build:
31-
needs: setup
3220
runs-on: ubuntu-latest
3321
steps:
34-
- name: Run tests
35-
run: uvx nox -s test_all
22+
- uses: actions/checkout@v4
23+
24+
- name: Load secret
25+
uses: 1password/load-secrets-action@v2
26+
with:
27+
export-env: true
28+
env:
29+
{% raw %}OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}{% endraw %}
30+
PERSONAL_ACCESS_TOKEN: op://shawndengdev/github_access_token/credential
31+
PYPI_TOKEN: op://shawndengdev/pypi_token/credential
3632

37-
- name: Build package
38-
run: uvx nox -s build
33+
- name: Setup Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: "{{ cookiecutter.max_python_version[0] }}"
3937

40-
- name: Create Release
41-
id: create_release
42-
uses: softprops/action-gh-release@v2
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v5
4340
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/*
41+
version: ">=0.4.0"
42+
43+
- name: Install dependencies
44+
run: uv sync --extra dev
45+
46+
- name: Build and test
47+
run: |
48+
uvx nox -s lint
49+
uvx nox -s test
50+
uvx nox -s build
5051
5152
- name: Publish to PyPI
52-
uses: pypa/gh-action-pypi-publish@release/v1
53+
env:
54+
{% raw %}UV_PUBLISH_TOKEN: ${{ env.PYPI_TOKEN }}{% endraw %}
55+
run: uv publish
56+
57+
- name: Release
58+
uses: softprops/action-gh-release@v2
5359
with:
54-
packages-dir: dist/
55-
repository-url: https://upload.pypi.org/legacy/
60+
files: |
61+
dist/*.tar.gz
62+
dist/*.whl
63+
generate_release_notes: true
64+
env:
65+
{% raw %}GITHUB_TOKEN: ${{ env.PERSONAL_ACCESS_TOKEN }}{% endraw %}

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

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

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)