-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTaskfile.yaml
198 lines (167 loc) Β· 7.01 KB
/
Taskfile.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
## ==================================================
## π§ Taskfile: Workflow Automation for CloudOps
## ==================================================
version: '3'
# silent: true
# output: prefixed
#################################################################################
## π GLOBAL VARIABLES #
#################################################################################
vars:
TODAY: '{{ now | date "2006-01-02T15:04:05-07:00" }}'
PROJECT_NAME: "runbooks"
PYTHON_VERSION: "3.12"
PYTHON_INTERPRETER: "python3"
CHECK_DIRS: "src/runbooks"
DATA_BUCKET: "s3://runbooks/data"
DATA_LOCAL_DIR: "data"
PUBLISH_TOKEN: "{{.UV_PUBLISH_TOKEN}}"
#################################################################################
# TASKS #
#################################################################################
tasks:
## Default Task: Help Menu
default:
desc: "Display available tasks and their descriptions"
cmds:
- task: help
#################################################################################
# ENVIRONMENT SETUP #
#################################################################################
# - echo "Installing build tool..."
# - "{{.PYTHON_INTERPRETER}} -m pip install build --upgrade"
## ==========================
## INSTALL DEPENDENCIES
## ==========================
install:
desc: "Install Python dependencies using UV with copy mode"
cmds:
- echo "π Setting UV link mode for compatibility..."
# - export UV_LINK_MODE={{.UV_LINK_MODE}}
- export UV_LINK_MODE=copy
# - uv self update ## Optional: Update UV tool if required
- echo "π¦ Syncing dependencies with UV..."
- uv sync --all-extras --dev
- uv pip list
- echo "β
Dependencies installed successfully."
## PIP
# - echo "Installing dependencies with PIP..."
# - "{{.PYTHON_INTERPRETER}} -m pip install build --upgrade"
## Clean Build Artifacts and Cache
clean:
desc: "Clean Python cache files and build artifacts"
cmds:
- echo "Cleaning Python cache files..."
- find . -type f -name "*.py[co]" -delete
- find . -type d -name "__pycache__" -delete
- echo "Removing temporary directories..."
- rm -rf .pytest_cache .mypy_cache dist build *.egg-info
## Deep Clean (including dependencies)
real-clean:
desc: "Perform deep clean of all build artifacts and dependencies"
cmds:
- task: clean
- echo "Removing virtual environment..."
- rm -rf .venv
#################################################################################
# CODE QUALITY CHECKS #
#################################################################################
## Format Code with Ruff
format:
desc: "Auto-format code using Ruff"
cmds:
- echo "Formatting code with Ruff..."
- "{{.PYTHON_INTERPRETER}} -m ruff format {{.CHECK_DIRS}}"
## Linting Code with Ruff
lint:
desc: "Run and auto-fix linting issues with Ruff"
cmds:
- task: format
- echo "Running Ruff lint checks and fixing issues..."
- "{{.PYTHON_INTERPRETER}} -m ruff check {{.CHECK_DIRS}} --select I --fix"
- "{{.PYTHON_INTERPRETER}} -m ruff check {{.CHECK_DIRS}} --select I -e"
## Check Code Quality
code_quality:
desc: "Validcate Code Quality with SonarQube"
cmds:
- echo "Validcate Code Quality using SonarQube"
- echo "sonar-python https://www.sonarsource.com/knowledge/languages/python/"
#################################################################################
# DATA MANAGEMENT #
#################################################################################
## Sync Data from Cloud Storage
sync_data_down:
desc: "Download data from S3 storage to local directory"
cmds:
- echo "Syncing data from S3 bucket to local directory..."
- aws s3 sync {{.DATA_BUCKET}}/ {{.DATA_LOCAL_DIR}}/
## Upload Data to Cloud Storage
sync_data_up:
desc: "Upload local data to S3 storage"
cmds:
- echo "Syncing local data to S3 bucket..."
- aws s3 sync {{.DATA_LOCAL_DIR}}/ {{.DATA_BUCKET}}/
#################################################################################
# BUILD AND PUBLISH #
#################################################################################
## Build the Project
build:
desc: "Build the project artifacts using pyproject.toml"
cmds:
- echo "Building artifacts with modern PEP 621 standards..."
- "{{.PYTHON_INTERPRETER}} -m build"
## Publish the Project
publish:
desc: "Publish the project package to PyPI"
cmds:
- echo "Publishing package to PyPI..."
# - "{{.PYTHON_INTERPRETER}} -m twine upload dist/* --username __token__ --password '{{.PUBLISH_TOKEN}}'"
- uv build
- uv publish --token $UV_PUBLISH_TOKEN
#################################################################################
# CI/CD PIPELINE TASKS #
#################################################################################
test:
desc: "Run tests with pytest and coverage"
cmds:
- echo "Running tests with pytest..."
- export PYTHONPATH=src:$PYTHONPATH
- uv run pytest tests/ --cov={{.CHECK_DIRS}} --cov-report=term-missing
## CI/CD Pipeline Automation
ci:
desc: "Run CI/CD pipeline tasks: clean, lint, format, and test"
cmds:
- task: clean
- task: lint
- task: code_quality
- export PYTHONPATH=src:$PYTHONPATH
- task: test
- task: build
#################################################################################
# DOCKER TASKS #
#################################################################################
## Build Docker Image
docker-build:
desc: "Build Docker image with multi-stage process"
cmds:
- echo "Building Docker image..."
- docker build -t {{.PROJECT_NAME}}:latest .
## Run Docker Container
docker-run:
desc: "Run the Docker container in interactive mode"
cmds:
- docker run -it {{.PROJECT_NAME}}:latest
## Clean Docker Images
docker-clean:
desc: "Remove Docker images and containers"
cmds:
- echo "Cleaning Docker resources..."
- docker system prune -af
#################################################################################
# DOCUMENTATION AND HELP #
#################################################################################
## Self-Documenting Help Menu
help:
desc: "List all available tasks with descriptions"
cmds:
- task --list