Skip to content

Commit 50a4e65

Browse files
authored
Merge branch 'main' into feat/zenable-noninteractive
2 parents a29c52c + b6e94e4 commit 50a4e65

7 files changed

Lines changed: 97 additions & 48 deletions

File tree

Taskfile.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tasks:
3636
status:
3737
# Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag
3838
# https://yaml.org/spec/1.2.2/#691-node-tags
39-
- '! test -d .git'
39+
- '! git rev-parse --git-dir'
4040
cmds:
4141
- uv tool install pre-commit
4242
# Don't run this in pipelines
@@ -93,8 +93,8 @@ tasks:
9393
update:
9494
desc: Update the project dev and runtime dependencies
9595
cmds:
96-
# Upgrade uv via brew on macOS/Linux when running locally (not CI)
97-
- '{{if and (ne .GITHUB_ACTIONS "true") (ne OS "windows")}}brew upgrade uv{{end}}'
96+
# Upgrade uv when running locally (not CI); use brew on macOS/Linux, uv self update on Windows
97+
- '{{if ne .GITHUB_ACTIONS "true"}}{{if ne OS "windows"}}brew upgrade uv{{else}}uv self update{{end}}{{end}}'
9898
- uv tool upgrade --all
9999
- pre-commit autoupdate --freeze --jobs 4
100100
# Copy the newly updated config into the project template, excluding the exclude line
@@ -128,9 +128,9 @@ tasks:
128128
env:
129129
GH_TOKEN:
130130
sh: |
131-
if [[ -n "${GH_TOKEN:-}" ]]; then
131+
if [ -n "${GH_TOKEN:-}" ]; then
132132
echo "${GH_TOKEN}"
133-
elif command -v gh &> /dev/null && gh auth token &> /dev/null; then
133+
elif gh auth token > /dev/null 2>&1; then
134134
gh auth token
135135
fi
136136
cmds:

{{cookiecutter.project_name}}/Taskfile.yml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vars:
1818
VERSION:
1919
sh: "{{ '{{.RUN_SCRIPT}}' }} python -c \"import sys; sys.path.insert(0, 'src'); from {{ '{{.PROJECT_SLUG}}' }} import __version__; print(__version__)\""
2020
LOCAL_PLATFORM:
21-
sh: "bash {{ '{{.SCRIPTS_DIR}}' }}/get_platform.sh"
21+
sh: "{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_platform.py"
2222
# Use PLATFORM if specified, otherwise use LOCAL_PLATFORM
2323
PLATFORM: '{{ '{{if .PLATFORM}}' }}{{ '{{.PLATFORM}}' }}{{ '{{else}}' }}{{ '{{.LOCAL_PLATFORM}}' }}{{ '{{end}}' }}'
2424
# Output redirect based on CI environment
@@ -34,7 +34,7 @@ tasks:
3434
- pyproject.toml
3535
- uv.lock
3636
preconditions:
37-
- which uv
37+
- uv --version
3838
cmds:
3939
# Sync dependencies with uv
4040
- uv sync --frozen --all-extras
@@ -47,7 +47,7 @@ tasks:
4747
status:
4848
# Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag
4949
# https://yaml.org/spec/1.2.2/#691-node-tags
50-
- '! test -d .git'
50+
- '! git rev-parse --git-dir'
5151
cmds:
5252
- uv tool install pre-commit
5353
# Don't run this in pipelines
@@ -88,7 +88,7 @@ tasks:
8888
TIMESTAMP:
8989
sh: '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_rfc3339_timestamp.py'
9090
EPOCH:
91-
sh: 'bash {{ '{{.SCRIPTS_DIR}}' }}/get_epoch.sh'
91+
sh: '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_epoch.py'
9292
COMMIT_HASH:
9393
sh: git rev-parse HEAD
9494
BUILD_PLATFORM: '{{ '{{if eq .PLATFORM "all"}}' }}{{ '{{.SUPPORTED_PLATFORMS}}' }}{{ '{{else if .PLATFORM}}' }}{{ '{{.PLATFORM}}' }}{{ '{{else}}' }}{{ '{{.LOCAL_PLATFORM}}' }}{{ '{{end}}' }}'
@@ -173,8 +173,8 @@ tasks:
173173
update:
174174
desc: Update the project dev and runtime dependencies
175175
cmds:
176-
# Upgrade uv via brew on macOS/Linux when running locally (not CI)
177-
- '{{ '{{if and (ne .GITHUB_ACTIONS "true") (ne OS "windows")}}' }}brew upgrade uv{{ '{{end}}' }}'
176+
# Upgrade uv when running locally (not CI); use brew on macOS/Linux, uv self update on Windows
177+
- '{{ '{{if ne .GITHUB_ACTIONS "true"}}{{if ne OS "windows"}}' }}brew upgrade uv{{ '{{else}}' }}uv self update{{ '{{end}}{{end}}' }}'
178178
- uv tool upgrade --all
179179
- pre-commit autoupdate --freeze --jobs 4
180180
- uv lock --upgrade
@@ -187,27 +187,16 @@ tasks:
187187
clean:
188188
desc: Clean up build artifacts, cache files/directories, temp files, etc.
189189
cmds:
190-
- rm -rf .pytest_cache
191-
- rm -rf htmlcov
192-
- rm -rf .coverage
193-
- rm -rf dist
194-
- rm -rf build
195-
- rm -rf *.egg-info
196-
- rm -f sbom.*.json
197-
- rm -f vulns.*.json
198-
- rm -f license-check.*.json
199-
- rm -f {{ cookiecutter.github_org }}_{{ cookiecutter.project_slug }}_*_*.tar
200-
- find . -type d -name __pycache__ -exec rm -rf {} + || true
201-
- find . -type f -name '*.pyc' -delete || true
190+
- '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/clean.py'
202191

203192
release:
204193
desc: Cut a project release
205194
env:
206195
GH_TOKEN:
207196
sh: |
208-
if [[ -n "${GH_TOKEN:-}" ]]; then
197+
if [ -n "${GH_TOKEN:-}" ]; then
209198
echo "${GH_TOKEN}"
210-
elif command -v gh &> /dev/null && gh auth token &> /dev/null; then
199+
elif gh auth token > /dev/null 2>&1; then
211200
gh auth token
212201
fi
213202
cmds:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
"""Cross-platform cleanup of build artifacts, cache files, and temp files."""
3+
4+
import glob
5+
import shutil
6+
import sys
7+
from pathlib import Path
8+
9+
10+
def main() -> int:
11+
"""Remove build artifacts, cache directories, and temporary files."""
12+
root = Path(".")
13+
14+
# Paths to remove (may be files or directories)
15+
for name in [".pytest_cache", "htmlcov", ".coverage", "dist", "build"]:
16+
path = root / name
17+
if path.is_dir():
18+
shutil.rmtree(path)
19+
elif path.is_file():
20+
path.unlink()
21+
22+
# Glob patterns for directories
23+
for path in glob.glob("*.egg-info"):
24+
shutil.rmtree(path)
25+
26+
# Glob patterns for files
27+
for pattern in [
28+
"sbom.*.json",
29+
"vulns.*.json",
30+
"license-check.*.json",
31+
"{{ cookiecutter.github_org }}_{{ cookiecutter.project_slug }}_*_*.tar",
32+
]:
33+
for path in glob.glob(pattern):
34+
Path(path).unlink()
35+
36+
# Recursively remove __pycache__ directories
37+
for path in root.rglob("__pycache__"):
38+
if path.is_dir():
39+
shutil.rmtree(path)
40+
41+
# Recursively remove .pyc files
42+
for path in root.rglob("*.pyc"):
43+
path.unlink()
44+
45+
return 0
46+
47+
48+
if __name__ == "__main__":
49+
sys.exit(main())
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python3
2+
"""Get the current Unix epoch timestamp."""
3+
4+
import time
5+
6+
print(int(time.time()))

{{cookiecutter.project_name}}/scripts/get_epoch.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
"""Get the Docker platform string for the current machine.
3+
4+
Always uses 'linux' as the OS since container builds target Linux.
5+
"""
6+
7+
import platform
8+
import sys
9+
10+
# Always use linux for container builds
11+
os_name = "linux"
12+
machine = platform.machine().lower()
13+
14+
# Inspired by https://github.com/containerd/containerd/blob/e0912c068b131b33798ae45fd447a1624a6faf0a/platforms/database.go#L76
15+
arch_map = {
16+
# AMD64
17+
"x86_64": "amd64",
18+
"amd64": "amd64",
19+
# ARM64
20+
"aarch64": "arm64",
21+
"arm64": "arm64",
22+
}
23+
24+
if machine not in arch_map:
25+
print(f"Unsupported architecture: {machine}", file=sys.stderr)
26+
sys.exit(1)
27+
28+
print(f"{os_name}/{arch_map[machine]}")

{{cookiecutter.project_name}}/scripts/get_platform.sh

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

0 commit comments

Comments
 (0)