Skip to content

Commit 35f1ce3

Browse files
committed
add copier template
1 parent e294324 commit 35f1ce3

30 files changed

Lines changed: 733 additions & 484 deletions

.github/workflows/deploy.yaml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Build and Deploy Template
2+
3+
on:
4+
push:
5+
branches:
6+
- template
7+
8+
jobs:
9+
test-and-deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
steps:
16+
- name: Checkout template branch
17+
uses: actions/checkout@v4
18+
with:
19+
ref: template
20+
fetch-depth: 0
21+
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v5
24+
25+
- name: Run template tests
26+
run: make test
27+
28+
- name: Build template output
29+
run: make build
30+
31+
- name: Get template commit SHA
32+
id: template_sha
33+
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
34+
35+
- name: Clone repository for main branch
36+
run: |
37+
cd ..
38+
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git main-repo
39+
cd main-repo
40+
# Try to checkout main, or create orphan if it doesn't exist
41+
git checkout main 2>/dev/null || git checkout --orphan main
42+
43+
- name: Apply build output to main branch
44+
run: |
45+
cd ../main-repo
46+
# Remove all files except .git
47+
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
48+
# Copy build output
49+
cp -r ../python_template/build_output/. .
50+
# Remove copier answers file (shouldn't be in generated project)
51+
rm -f .copier-answers.yml
52+
53+
- name: Commit and create PR
54+
run: |
55+
cd ../main-repo
56+
git config user.name "github-actions[bot]"
57+
git config user.email "github-actions[bot]@users.noreply.github.com"
58+
git add -A
59+
60+
# Check if there are changes
61+
if git diff --staged --quiet; then
62+
echo "No changes to commit"
63+
echo "has_changes=false" >> $GITHUB_ENV
64+
else
65+
# If main doesn't exist on remote, push it first
66+
if ! git ls-remote --heads origin main | grep -q main; then
67+
echo "Creating main branch"
68+
git commit -m "Initial commit from template@${{ steps.template_sha.outputs.sha }}"
69+
git push origin main
70+
fi
71+
72+
# Create and push PR branch
73+
git checkout -b template-build
74+
git commit -m "Build from template@${{ steps.template_sha.outputs.sha }}" --allow-empty
75+
git push -f origin template-build
76+
echo "has_changes=true" >> $GITHUB_ENV
77+
fi
78+
79+
- name: Create Pull Request
80+
if: env.has_changes == 'true'
81+
env:
82+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
run: |
84+
# Try to create PR, if it fails because PR exists, update it
85+
if ! gh pr create \
86+
--base main \
87+
--head template-build \
88+
--title "Build from template@${{ steps.template_sha.outputs.sha }}" \
89+
--body "## 🤖 Automated Template Build
90+
91+
This PR contains the rendered template from the latest changes on the \`template\` branch.
92+
93+
**Source commit:** \`${{ steps.template_sha.outputs.sha }}\`
94+
**Build timestamp:** ${{ github.event.head_commit.timestamp }}
95+
96+
### ✅ Validation
97+
- Template tests passed
98+
- Pre-commit hooks validated" 2>&1 | tee /tmp/pr-output.txt; then
99+
# Check if error is because PR already exists
100+
if grep -q "already exists" /tmp/pr-output.txt; then
101+
echo "PR already exists, updating it"
102+
gh pr edit template-build \
103+
--title "Build from template@${{ steps.template_sha.outputs.sha }}" \
104+
--body "## 🤖 Automated Template Build
105+
106+
This PR contains the rendered template from the latest changes on the \`template\` branch.
107+
108+
**Source commit:** \`${{ steps.template_sha.outputs.sha }}\`
109+
**Build timestamp:** ${{ github.event.head_commit.timestamp }}
110+
111+
### ✅ Validation
112+
- Template tests passed
113+
- Pre-commit hooks validated"
114+
else
115+
echo "Failed to create PR"
116+
cat /tmp/pr-output.txt
117+
exit 1
118+
fi
119+
else
120+
echo "PR created successfully"
121+
fi

.gitignore

Lines changed: 18 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,22 @@
1-
# Byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
5-
6-
# C extensions
7-
*.so
8-
9-
# Distribution / packaging
10-
.Python
11-
build/
12-
develop-eggs/
13-
dist/
14-
downloads/
15-
eggs/
16-
.eggs/
17-
lib/
18-
lib64/
19-
parts/
20-
sdist/
21-
var/
22-
wheels/
23-
share/python-wheels/
24-
*.egg-info/
25-
.installed.cfg
26-
*.egg
27-
MANIFEST
28-
29-
# PyInstaller
30-
# Usually these files are written by a python script from a template
31-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32-
*.manifest
33-
*.spec
34-
35-
# Installer logs
36-
pip-log.txt
37-
pip-delete-this-directory.txt
38-
39-
# Unit test / coverage reports
40-
htmlcov/
41-
.tox/
42-
.nox/
43-
.coverage
44-
.coverage.*
45-
.cache
46-
nosetests.xml
47-
coverage.xml
48-
*.cover
49-
*.py,cover
50-
.hypothesis/
51-
.pytest_cache/
52-
cover/
53-
54-
# Translations
55-
*.mo
56-
*.pot
57-
58-
# Django stuff:
59-
*.log
60-
local_settings.py
61-
db.sqlite3
62-
db.sqlite3-journal
63-
64-
# Flask stuff:
65-
instance/
66-
.webassets-cache
67-
68-
# Scrapy stuff:
69-
.scrapy
70-
71-
# Sphinx documentation
72-
docs/_build/
73-
74-
# PyBuilder
75-
.pybuilder/
76-
target/
77-
78-
# Jupyter Notebook
79-
.ipynb_checkpoints
80-
81-
# IPython
82-
profile_default/
83-
ipython_config.py
1+
# Copier template testing outputs
2+
temp_out/
3+
test_output/
4+
build_output/
845

85-
# pyenv
86-
# For a library or package, you might want to ignore these files since the code is
87-
# intended to run in multiple environments; otherwise, check them in:
88-
# .python-version
89-
90-
# pipenv
91-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94-
# install all needed dependencies.
95-
#Pipfile.lock
96-
97-
# poetry
98-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99-
# This is especially recommended for binary packages to ensure reproducibility, and is more
100-
# commonly ignored for libraries.
101-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
103-
104-
# pdm
105-
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106-
#pdm.lock
107-
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108-
# in version control.
109-
# https://pdm.fming.dev/#use-with-ide
110-
.pdm.toml
111-
112-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113-
__pypackages__/
114-
115-
# Celery stuff
116-
celerybeat-schedule
117-
celerybeat.pid
118-
119-
# SageMath parsed files
120-
*.sage.py
121-
122-
# Environments
123-
.env
124-
.venv
125-
env/
126-
venv/
127-
ENV/
128-
env.bak/
129-
venv.bak/
130-
131-
# Spyder project settings
132-
.spyderproject
133-
.spyproject
134-
135-
# Rope project settings
136-
.ropeproject
137-
138-
# mkdocs documentation
139-
/site
140-
141-
# mypy
142-
.mypy_cache/
143-
.dmypy.json
144-
dmypy.json
145-
146-
# Pyre type checker
147-
.pyre/
6+
# Python cache from test runs
7+
__pycache__/
8+
*.pyc
1489

149-
# pytype static type analyzer
150-
.pytype/
10+
# OS files
11+
.DS_Store
12+
Thumbs.db
15113

152-
# Cython debug symbols
153-
cython_debug/
14+
# Editor files
15+
.vscode/
16+
.idea/
17+
*.swp
18+
*.swo
19+
*~
15420

155-
# PyCharm
156-
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157-
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158-
# and can be added to the global gitignore or merged into this file. For a more nuclear
159-
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
21+
# Template environment
22+
.venv

.pre-commit-config.yaml

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -48,50 +48,6 @@ repos:
4848
- id: check-added-large-files
4949
args: ["--maxkb=500"] # Policy: reject very large blobs
5050

51-
- repo: https://github.com/astral-sh/ruff-pre-commit
52-
rev: v0.13.2
53-
hooks:
54-
- id: ruff
55-
name: Ruff Linter (autofix)
56-
args: [--fix, "--config=pyproject.toml"]
57-
- id: ruff-format
58-
name: Ruff Formatter
59-
args: ["--config=pyproject.toml"]
60-
61-
############################################################
62-
# PUSH-TIME (SLOWER / ANALYSIS) HOOKS
63-
# These run less frequently to keep commit loop fast.
64-
############################################################
65-
- repo: local
66-
hooks:
67-
- id: pytest-check
68-
name: Run Test Suite
69-
entry: uv run pytest
70-
language: system
71-
pass_filenames: false
72-
always_run: true
73-
stages: [pre-push]
74-
# Optional faster feedback: args: ["-q", "--maxfail=1"]
75-
- id: pylint
76-
name: Pylint (design checks)
77-
entry: uv run pylint
78-
language: system
79-
types: [python]
80-
args: ["--rcfile=pyproject.toml"]
81-
stages: [pre-push]
82-
- id: deptry
83-
name: Deptry (dependency hygiene)
84-
entry: uv run deptry python_package
85-
language: system
86-
pass_filenames: false
87-
stages: [pre-push]
88-
- id: vulture
89-
name: Vulture (dead code)
90-
entry: uv run vulture python_package
91-
language: system
92-
pass_filenames: false
93-
stages: [pre-push]
94-
9551
- repo: https://github.com/Yelp/detect-secrets
9652
rev: v1.5.0
9753
hooks:
@@ -100,11 +56,3 @@ repos:
10056
args: ["--baseline", ".secrets.baseline"]
10157
exclude: uv.lock
10258
stages: [pre-push]
103-
104-
- repo: https://github.com/astral-sh/uv-pre-commit
105-
rev: 0.8.22
106-
hooks:
107-
- id: uv-lock
108-
name: Validate pyproject / lock
109-
stages: [pre-push]
110-
pass_filenames: false

0 commit comments

Comments
 (0)