Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
171 lines (153 loc) · 6.11 KB
/
Copy pathTaskfile.yml
File metadata and controls
171 lines (153 loc) · 6.11 KB
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
---
# https://taskfile.dev
version: '3'
set:
- nounset
- errexit
- pipefail
vars:
PROJECT_NAME: skills
RUN_SCRIPT: 'uv run --frozen'
silent: true
tasks:
init-uv:
desc: Initialize a uv virtual environment
requires:
vars:
# This is a bool, so we cannot use enum because taskfile only supports strings here
- DEV_DEPS
internal: true
# We intentionally don't use sources because uv is super fast so we re-sync every time
preconditions:
- which uv
- uv --version
cmds:
# Create lockfile if it doesn't exist
- '[ -f uv.lock ] || uv lock {{if .DEBUG}}-v{{end}}'
# --all-extras: Only installs optional dependencies which are depended on in the **current** project's pyproject.toml
- uv sync --frozen --all-extras {{if not .DEV_DEPS}}--no-dev{{end}} {{if .DEBUG}}-v{{end}}
init-prek:
desc: Setup prek, a drop-in pre-commit replacement that resolves hook environments far faster
internal: true
sources:
- .pre-commit-config.yaml
status:
# Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag
# https://yaml.org/spec/1.2.2/#691-node-tags
- '! test -d .git'
cmds:
# --exclude-newer gives a freshly published (potentially compromised) release time to be caught before we pull it in
- uv tool install prek --exclude-newer "7 days"
# Don't run this in pipelines
# --overwrite replaces any pre-commit-generated shim outright; without it prek keeps the old one as .legacy and runs both on every commit
- '{{if ne .GITHUB_ACTIONS "true"}}prek install --overwrite{{else}}echo "Detected a github actions pipeline; skipping the prek install"{{end}}'
init:
desc: Initialize the repo for local use; intended to be run after git clone
cmds:
- task: init-uv
vars:
DEV_DEPS: true
- task: init-prek
update:
desc: >
Update the project dev and runtime dependencies, the lock files, and then install the updates
preconditions:
- which uv
- uv --version
cmds:
- uv tool upgrade --all
- uv tool run prek update --freeze
# Pin the README pre-commit example to our latest major tag (v1 -> v2 on a v2 release)
- ./scripts/pin-precommit-rev.sh
- uv lock --upgrade
- task: init-uv
vars:
# We want the dev deps because this initializes the environment with the upgraded deps for a developer's use
DEV_DEPS: true
lint:
desc: Run the linter(s)
deps: [init-prek]
cmds:
- prek run --all-files
# Drop hook environments that are no longer referenced so we don't cache garbage in CI
- prek cache gc 1>/dev/null
validate:
desc: Validate the pre-commit config
deps: [init-prek]
cmds:
# prek needs the paths explicitly; with no arguments it exits zero having checked nothing
- prek validate-config .pre-commit-config.yaml
- prek validate-manifest .pre-commit-hooks.yaml
test:
desc: Run the project tests
cmds:
- task: test-plugin
- task: test-scripts
- task: test-assessment-scripts
- task: test-pr-metrics-scripts
- task: test-report-template
- task: test-skills-cli
test-plugin:
desc: Validate the z plugin structure
cmds:
- '{{.RUN_SCRIPT}} python tests/zenable_skills/validate_structure.py'
test-skills-cli:
desc: Confirm `npx skills` discovers every skill in this repo
preconditions:
- sh: which npx
msg: "npx (node 18+) is required to exercise the skills CLI"
cmds:
- '{{.RUN_SCRIPT}} python tests/zenable_skills/validate_skills_cli.py'
test-scripts:
desc: Exercise the prfeedback helper scripts against a stubbed gh
preconditions:
# The scripts shell out to jq; without it every check would fail for the wrong reason
- sh: which jq
msg: "jq is required to test the prfeedback scripts"
cmds:
- '{{.RUN_SCRIPT}} python tests/zenable_skills/validate_scripts.py'
test-assessment-scripts:
desc: Test the assessment skill's report-generation tooling
preconditions:
- which uv
- uv --version
cmds:
# pytest is pulled ephemerally rather than locked: this repo ships a plugin,
# not a package, and keeping `dependencies = []` keeps its supply-chain
# surface at zero. --exclude-newer gives a freshly published (potentially
# compromised) release time to be caught before we pull it in.
- uv run --with pytest --exclude-newer "7 days" --no-project pytest plugins/z/skills/assessment/scripts/tests -q
test-pr-metrics-scripts:
desc: Test the pr-metrics skill's fetch script against a stubbed zenable CLI
preconditions:
- which uv
- uv --version
cmds:
# Same ephemeral, age-gated pytest as test-assessment-scripts, in its own run
# because both test directories ship a conftest.py of the same module name.
- uv run --with pytest --exclude-newer "7 days" --no-project pytest plugins/z/skills/pr-metrics/scripts/tests -q
test-report-template:
desc: Test the assessment report template's render pipeline (app.js)
preconditions:
# node ships the test runner as a builtin, so this needs no npm install and
# adds no dependency to a repo that deliberately has none
- sh: which node
msg: "node (18+) is required to test the report template"
cmds:
# The glob is expanded by the shell, not by node: passing plain file paths
# works on every node version that has --test, while glob-as-argument
# support arrived later.
- node --test plugins/z/skills/assessment/tests/*.test.js
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
- find . -type d -name __pycache__ -exec rm -rf {} + || true
- find . -type d -name .mypy_cache -exec rm -rf {} + || true
- find . -type d -name .ruff_cache -exec rm -rf {} + || true
- find . -type f -name '*.pyc' -delete || true