Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions {{cookiecutter.project_name}}/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vars:
VERSION:
sh: "{{ '{{.RUN_SCRIPT}}' }} python -c \"import sys; sys.path.insert(0, 'src'); from {{ '{{.PROJECT_SLUG}}' }} import __version__; print(__version__)\""
LOCAL_PLATFORM:
sh: "bash {{ '{{.SCRIPTS_DIR}}' }}/get_platform.sh"
sh: "{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_platform.py"
# Use PLATFORM if specified, otherwise use LOCAL_PLATFORM
PLATFORM: '{{ '{{if .PLATFORM}}' }}{{ '{{.PLATFORM}}' }}{{ '{{else}}' }}{{ '{{.LOCAL_PLATFORM}}' }}{{ '{{end}}' }}'
# Output redirect based on CI environment
Expand Down Expand Up @@ -88,7 +88,7 @@ tasks:
TIMESTAMP:
sh: '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_rfc3339_timestamp.py'
EPOCH:
sh: 'bash {{ '{{.SCRIPTS_DIR}}' }}/get_epoch.sh'
sh: '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_epoch.py'
COMMIT_HASH:
sh: git rev-parse HEAD
BUILD_PLATFORM: '{{ '{{if eq .PLATFORM "all"}}' }}{{ '{{.SUPPORTED_PLATFORMS}}' }}{{ '{{else if .PLATFORM}}' }}{{ '{{.PLATFORM}}' }}{{ '{{else}}' }}{{ '{{.LOCAL_PLATFORM}}' }}{{ '{{end}}' }}'
Expand Down Expand Up @@ -187,18 +187,7 @@ tasks:
clean:
desc: Clean up build artifacts, cache files/directories, temp files, etc.
cmds:
- rm -rf .pytest_cache
- rm -rf htmlcov
- rm -rf .coverage
- rm -rf dist
- rm -rf build
- rm -rf *.egg-info
- rm -f sbom.*.json
- rm -f vulns.*.json
- rm -f license-check.*.json
- rm -f {{ cookiecutter.github_org }}_{{ cookiecutter.project_slug }}_*_*.tar
- find . -type d -name __pycache__ -exec rm -rf {} + || true
- find . -type f -name '*.pyc' -delete || true
- '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/clean.py'

release:
desc: Cut a project release
Expand Down
49 changes: 49 additions & 0 deletions {{cookiecutter.project_name}}/scripts/clean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
"""Cross-platform cleanup of build artifacts, cache files, and temp files."""

import glob
import shutil
import sys
from pathlib import Path


def main() -> int:
"""Remove build artifacts, cache directories, and temporary files."""
root = Path(".")

# Paths to remove (may be files or directories)
for name in [".pytest_cache", "htmlcov", ".coverage", "dist", "build"]:
path = root / name
if path.is_dir():
shutil.rmtree(path)
elif path.is_file():
path.unlink()

# Glob patterns for directories
for path in glob.glob("*.egg-info"):
shutil.rmtree(path)

# Glob patterns for files
for pattern in [
"sbom.*.json",
"vulns.*.json",
"license-check.*.json",
"{{ cookiecutter.github_org }}_{{ cookiecutter.project_slug }}_*_*.tar",
]:
for path in glob.glob(pattern):
Path(path).unlink()

# Recursively remove __pycache__ directories
for path in root.rglob("__pycache__"):
if path.is_dir():
shutil.rmtree(path)

# Recursively remove .pyc files
for path in root.rglob("*.pyc"):
path.unlink()

return 0


if __name__ == "__main__":
sys.exit(main())
6 changes: 6 additions & 0 deletions {{cookiecutter.project_name}}/scripts/get_epoch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python3
"""Get the current Unix epoch timestamp."""

import time

print(int(time.time()))
4 changes: 0 additions & 4 deletions {{cookiecutter.project_name}}/scripts/get_epoch.sh

This file was deleted.

28 changes: 28 additions & 0 deletions {{cookiecutter.project_name}}/scripts/get_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""Get the Docker platform string for the current machine.

Always uses 'linux' as the OS since container builds target Linux.
"""

import platform
import sys

# Always use linux for container builds
os_name = "linux"
machine = platform.machine().lower()

# Inspired by https://github.com/containerd/containerd/blob/e0912c068b131b33798ae45fd447a1624a6faf0a/platforms/database.go#L76
arch_map = {
# AMD64
"x86_64": "amd64",
"amd64": "amd64",
# ARM64
"aarch64": "arm64",
"arm64": "arm64",
}

if machine not in arch_map:
print(f"Unsupported architecture: {machine}", file=sys.stderr)
sys.exit(1)

print(f"{os_name}/{arch_map[machine]}")
19 changes: 0 additions & 19 deletions {{cookiecutter.project_name}}/scripts/get_platform.sh

This file was deleted.

Loading