Skip to content

Commit e5123e9

Browse files
authored
feat(windows): move from sh to py for better windows support (#84)
1 parent 6d18f1b commit e5123e9

8 files changed

Lines changed: 99 additions & 44 deletions

File tree

.github/etc/dictionary.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
An
2-
burndown
3-
Labworks
4-
labworksacr
5-
TODOs
6-
tfvars
71
allstar
2+
An
83
app
94
application
5+
burndown
6+
citus
107
conftest
8+
containerapp
119
dependabot
1210
docstrings
11+
fetchall
1312
for
1413
jonzeolla
1514
labworks.dev
15+
labworksacr
1616
labworksdev
17+
Labworks
1718
managing
19+
muuda
20+
psea
1821
refurb
1922
renovatebot
2023
skopeo
24+
sslmode
2125
syft
2226
taskfile
27+
tfvars
2328
todo
2429
todo-app
30+
TODOs
2531
zenable

Taskfile.yml

Lines changed: 3 additions & 14 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
@@ -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}}'
@@ -234,18 +234,7 @@ tasks:
234234
clean:
235235
desc: Clean up build artifacts, cache files/directories, temp files, etc.
236236
cmds:
237-
- rm -rf .pytest_cache
238-
- rm -rf htmlcov
239-
- rm -rf .coverage
240-
- rm -rf dist
241-
- rm -rf build
242-
- rm -rf *.egg-info
243-
- rm -f sbom.*.json
244-
- rm -f vulns.*.json
245-
- rm -f license-check.*.json
246-
- rm -f labworksdev_todo?app_*_*.tar
247-
- find . -type d -name __pycache__ -exec rm -rf {} + || true
248-
- find . -type f -name '*.pyc' -delete || true
237+
- '{{.RUN_SCRIPT}} {{.SCRIPTS_DIR}}/clean.py'
249238

250239
release:
251240
desc: Cut a project release

docs/DATABASE-MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,4 @@ az cosmosdb postgres cluster delete \
193193
--resource-group rg-todo-app \
194194
--cluster-name todo-app-db \
195195
--yes
196-
```
196+
```

scripts/clean.py

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+
"labworksdev_todo?app_*_*.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())

scripts/get_epoch.py

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()))

scripts/get_epoch.sh

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

scripts/get_platform.py

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]}")

scripts/get_platform.sh

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

0 commit comments

Comments
 (0)