-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
191 lines (159 loc) · 5.08 KB
/
Taskfile.yml
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
# NOTICE: If you are familiar with the python eco system you may ignore this file
# Otherwise, it offers some minimal workflow automation using https://taskfile.dev/
version: '3'
vars:
# Put this in the root of the repo for vscode autodection
VENV_DIR: venv
PACKAGE_NAME: datatrails_scitt_samples
tasks:
install:dev:
desc: Install the package in development mode (in the virtual environment)
deps:
- task: venv
cmds:
- |
set -e
source {{.VENV_DIR}}/bin/activate
trap deactivate EXIT
python -m pip install -e .
audit:
desc: Audit the code
deps:
- task: venv
cmds:
- |
set -e
source {{.VENV_DIR}}/bin/activate
trap deactivate EXIT
pip-audit -r requirements.txt
check:
desc: Check the style, bug and quality of the code
deps:
- task: venv
cmds:
- |
set -e
source {{.VENV_DIR}}/bin/activate
trap deactivate EXIT
python3 --version
ruff check {{ .PACKAGE_NAME }} tests
python3 -m pyright --stats {{ .PACKAGE_NAME }} tests
clean:
desc: Clean git repo
cmds:
- find -name '*,cover' -type f -delete
- git clean -fdX
format:
desc: Format code using black
deps:
- task: venv
cmds:
- |
set -e
source {{ .VENV_DIR }}/bin/activate
trap deactivate EXIT
black {{ .PACKAGE_NAME }} tests
ruff check {{ .PACKAGE_NAME }} tests --fix
test:
desc: Run simple tests
deps:
- task: venv
cmds:
- |
set -e
source {{ .VENV_DIR }}/bin/activate
trap deactivate EXIT
python3 -m unittest
test:wheel:
desc: |
Build and install the package, then register a signed statement with the datatrails server
** REQUIRES ENVIRONMENT VARIABLES **
DATATRAILS_URL
DATATRAILS_CLIENT_ID
DATATRAILS_CLIENT_SECRET
Add them to .env.token for maximal convenience
deps:
- task: wheel
cmds:
- |
source {{ .VENV_DIR }}/bin/activate
trap deactivate EXIT
pip install --force-reinstall dist/*.whl
task registration-demo
registration-demo:
envfile: .env.token
desc: |
Build and install the package, then register a signed statement with the datatrails server
** REQUIRES ENVIRONMENT VARIABLES **
DATATRAILS_URL
DATATRAILS_CLIENT_ID
DATATRAILS_CLIENT_SECRET
Add them to .env.token for maximal convenience
vars:
CONTENT_TYPE: "application/json"
ISSUER: "github.com/datatrails/datatrails-scitt-samples/Taskfile.yml"
METADATA: '{\"key1\": \"value\", \"key2\": \"42\"}'
METADATA_FILE: "metadata.json"
SIGNED_STATEMENT_FILE: "signed-statement.cbor"
SIGNING_KEY: "my-signing-key.pem"
PAYLOAD: '{\"name\": \"R2D2\"}'
PAYLOAD_FILE: "payload.json"
PAYLOAD_LOCATION: "https://storage.example/{{ .SUBJECT }}"
SUBJECT: "test:wheel"
cmds:
- |
set -e
# DONT source the env here, it breaks the windows ci
echo "DATATRAILS_ xxx var value char counts"
echo "$DATATRAILS_URL" | wc -c
echo "$DATATRAILS_CLIENT_ID" | wc -c
echo "$DATATRAILS_CLIENT_SECRET" | wc -c
echo "Generating ephemeral issuer key"
datatrails-sciit-demo-generate-example-key \
--signing-key-file {{.SIGNING_KEY}}
echo "Creating the statement"
echo {{ .PAYLOAD }} > {{ .PAYLOAD_FILE }}
echo {{ .METADATA }} > {{ .METADATA_FILE }}
create-signed-statement \
--content-type {{ .CONTENT_TYPE }} \
--issuer {{ .ISSUER }} \
--metadata-file {{ .METADATA_FILE }} \
--output-file {{ .SIGNED_STATEMENT_FILE }} \
--payload-file {{ .PAYLOAD_FILE }} \
--payload-location {{ .PAYLOAD_LOCATION }} \
--signing-key-file {{.SIGNING_KEY}} \
--subject {{ .SUBJECT }}
echo "Registering the statement"
register-signed-statement \
--signed-statement-file {{ .SIGNED_STATEMENT_FILE }} \
--output-file transparent-statement.cbor \
--output-receipt-file statement-receipt.cbor
echo "The statement has been registered, and its receipt fully verified"
echo -n "Transparent Statement: "
cat transparent-statement.cbor | base64
echo -n "Receipt : "
cat statement-receipt.cbor | base64
venv:
desc: Builds python environment
cmds:
- |
set -e
if [ ! -d {{ .VENV_DIR }} ]
then
python3 -m venv {{ .VENV_DIR }}
source {{ .VENV_DIR }}/bin/activate
trap deactivate EXIT
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-dev.txt
fi
wheel:
desc: Builds python wheel package
cmds:
- |
set -e
rm -rf dist/*
source {{ .VENV_DIR }}/bin/activate
trap deactivate EXIT
python3 -m build --sdist
python3 -m build --wheel
twine check dist/*