Skip to content

Commit 30d6fca

Browse files
committed
feat: add ci for template
1 parent ce3b055 commit 30d6fca

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed

cookiecutter.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"description": "What's the main goal of this package?",
66
"python_version": "3.13",
77
"year": "2025",
8-
"include_cli": "y"
8+
"include_cli": "y",
9+
"include_docs": "y",
10+
"include_pypi": "y"
911
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: 'Setup Python Environment'
2+
description: 'Setup Python and install project dependencies.'
3+
author: 'David Zhang'
4+
5+
inputs:
6+
python-version:
7+
description: 'Python version to use'
8+
required: true
9+
dependencies:
10+
description: 'Dependency group to install (e.g., "dev", "docs", "build")'
11+
required: true
12+
13+
runs:
14+
using: 'composite'
15+
steps:
16+
- name: Set up Python ${{ inputs.python-version }}
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ inputs.python-version }}
20+
21+
- name: Install dependencies
22+
shell: bash
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -e ".[${{ inputs.dependencies }}]"
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: test_deploy
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
tags: [ '*' ]
7+
pull_request:
8+
branches: [ main ]
9+
10+
env:
11+
PYTHON_VERSION: "{{cookiecutter.python_version}}"
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Python and install dependencies
22+
uses: ./.github/actions/setup
23+
with:
24+
python-version: ${{ env.PYTHON_VERSION }}
25+
dependencies: dev
26+
27+
- name: Run tests
28+
run: pytest
29+
30+
{% if cookiecutter.include_docs == 'y' %}
31+
deploy-docs:
32+
runs-on: ubuntu-latest
33+
34+
# Do not run on git tag (i.e. releases).
35+
# Only runs if tests pass.
36+
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
37+
needs: [test]
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
43+
- name: Setup Python and install dependencies
44+
uses: ./.github/actions/setup
45+
with:
46+
python-version: ${{ env.PYTHON_VERSION }}
47+
dependencies: docs
48+
49+
- name: Build documentation
50+
run: |
51+
cp README.md docs/index.md
52+
cp CHANGELOG.md docs/changelog.md
53+
# --strict errors on any warnings.
54+
# builds the site to ./site.
55+
mkdocs build --strict
56+
57+
- name: Deploy to GitHub Pages
58+
# Only trigger on push to main branch.
59+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
60+
uses: peaceiris/actions-gh-pages@v4
61+
with:
62+
github_token: ${{ secrets.GITHUB_TOKEN }}
63+
publish_dir: ./site
64+
{% endif %}
65+
66+
{% if cookiecutter.include_pypi == 'y' %}
67+
deploy-pypi:
68+
runs-on: ubuntu-latest
69+
70+
# Only runs on git tag and if tests pass.
71+
if: startsWith(github.ref, 'refs/tags/')
72+
needs: [test]
73+
74+
# Authenticate for PyPI publishing.
75+
permissions:
76+
id-token: write
77+
78+
steps:
79+
- name: Checkout repository
80+
uses: actions/checkout@v4
81+
82+
- name: Setup Python and install dependencies
83+
uses: ./.github/actions/setup
84+
with:
85+
python-version: ${{ env.PYTHON_VERSION }}
86+
dependencies: build
87+
88+
- name: Build package
89+
run: python -m build
90+
91+
- name: Publish to PyPI
92+
uses: pypa/gh-action-pypi-publish@release/v1
93+
{% endif %}

0 commit comments

Comments
 (0)