This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
481 lines (463 loc) · 17.5 KB
/
testing.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
name: Tests
on:
workflow_dispatch: null
push:
branches:
- main
paths-ignore:
- 'docs/arch/**'
pull_request:
paths-ignore:
- 'docs/arch/**'
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- "3.12"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.cfg') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dev dependencies
run: |
pip install -U pip setuptools wheel build
pip install -U sbom4python
pip install -U https://github.com/scitt-community/scitt-api-emulator/archive/e89a60584fa717382f279ae24b8a1a93d458bb4d.zip
pip install -e .[dev]
python -m pip freeze
- name: Build
run: |
python -m build .
- name: Generate SBOM
id: generate-sbom
uses: anthonyharrison/sbom4python@5b458354df89357bf0253e62ea4567b1807120e2
with:
python-version: ${{ matrix.python-version }}
module-name: dffml
output-directory: sbom
- name: in-toto attestation for cyclonedx SBOM
id: in-toto-cyclonedx
env:
MODULE_NAME: dffml
run: |
echo "attestation<<GITHUB_OUTPUT_EOF" >> $GITHUB_OUTPUT
(python -m json.tool --sort-keys | tee -a $GITHUB_OUTPUT) <<EOF
{
"_type": "https://in-toto.io/Statement/v0.1",
"subject": [
{
"name": "$(cd dist/ && echo *.tar.gz)",
"digest": {"sha256": "$(cd dist/ && sha256sum $(echo *.tar.gz) | awk '{print $1}')"}
},
{
"name": "$(cd dist/ && echo *.whl)",
"digest": {"sha256": "$(cd dist/ && sha256sum $(echo *.whl) | awk '{print $1}')"}
}
],
"predicateType": "https://cyclonedx.org/bom/v1.4",
"predicate": $(cat "${MODULE_NAME}-py${{ matrix.python-version }}.json")
}
EOF
echo "GITHUB_OUTPUT_EOF" >> $GITHUB_OUTPUT
- name: Checkout public-keys branch
uses: actions/checkout@v4
with:
ref: public-keys
path: public-keys
- name: Generate keypair to sign SCITT statement
id: scitt-gen-keypair
run: |
ssh-keygen -q -f ssh-private -t ecdsa -b 384 -N '' -C "$(head -n 100 /dev/urandom | sha384sum | awk '{print $1}')" -I "$(date -Iseconds)" <<<y
cat ssh-private | python -c 'import sys; from cryptography.hazmat.primitives import serialization; print(serialization.load_ssh_private_key(sys.stdin.buffer.read(), password=None).private_bytes(encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption()).decode().rstrip())' > private-key.pem
# cat ssh-private.pub | tee -a public-keys/x509
- name: SSH key as x509
shell: python -u {0}
run: |
from cryptography import x509
from cryptography.x509.oid import NameOID
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
from jwcrypto import jwk, jws
import datetime
import pathlib
key = jwk.JWK.from_pem(pathlib.Path("private-key.pem").read_bytes())
rsa_public_key = jwk.JWK.from_json(key.export_public())
# Convert the JWK to a public key
public_key = rsa_public_key.get_op_key('verify')
# Create a builder for the X.509 certificate
subject = issuer = x509.Name([
x509.NameAttribute(NameOID.COUNTRY_NAME, "US"),
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Oregon"),
x509.NameAttribute(NameOID.LOCALITY_NAME, "Portland"),
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "SCITT Emulator"),
x509.NameAttribute(NameOID.COMMON_NAME, "example.com"),
])
cert_builder = x509.CertificateBuilder(
subject_name=subject,
issuer_name=issuer,
public_key=public_key,
serial_number=x509.random_serial_number(),
not_valid_before=datetime.datetime.utcnow(),
not_valid_after=datetime.datetime.utcnow() + datetime.timedelta(days=1), # Certificate valid for 1 day
extensions=[]
)
# Self-sign the certificate with the private key
private_key_op = key.get_op_key('sign')
cert = cert_builder.sign(private_key=private_key_op, algorithm=hashes.SHA256(), backend=default_backend())
# Serialize the certificate
cert_pem = cert.public_bytes(encoding=Encoding.PEM)
# Save the PEM encoded certificate
pathlib.Path("public-keys", "x509").write_bytes(cert_pem)
- name: Remove ssh private
run: |
rm -v ssh-private
- name: Push new public key
env:
GH_TOKEN: ${{ github.token }}
run: |
set -xe
cd public-keys
gh auth setup-git
git config --global --add safe.directory "${PWD}"
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add -A
# If no delta clean exit
git commit -sm "Snapshot" || exit 0
git push -uf origin "HEAD:public-keys"
# Wait for propagation
# TODO x509 style polling?
sleep 10s
- name: Submit SBOM to SCITT
id: scitt-submit-sbom
uses: scitt-community/scitt-api-emulator@f1f5c16630a28511e970b6903fbc4c0db6c07654
with:
issuer: did:web:raw.githubusercontent.com:intel:dffml:public-keys:x509
subject: pkg:github/${{ github.repository }}@${{ github.sha }}
payload: ${{ steps.in-toto-cyclonedx.outputs.attestation }}
private-key-pem: private-key.pem
scitt-url: https://scitt.unstable.chadig.com
- name: Create Pull Request
if: ${{ steps.generate-sbom.outputs.changed }}
uses: peter-evans/[email protected]
with:
commit-message: "chore: update SBOM for Python ${{ matrix.python-version }}"
title: "chore: update SBOM for Python ${{ matrix.python-version }}"
branch: chore-sbom-py${{ matrix.python-version }}
delete-branch: true
author: GitHub Actions <[email protected]>
add-paths: sbom
- uses: openvex/generate-vex@159b7ee4845fb48f1991395ce8501d6263407360
name: Run vexctl
id: vexctl
with:
product: pkg:github/${{ github.repository }}@${{ github.sha }}
- name: Submit OpenVEX to SCITT
id: scitt-submit-openvex
uses: scitt-community/scitt-api-emulator@f1f5c16630a28511e970b6903fbc4c0db6c07654
with:
issuer: did:web:raw.githubusercontent.com:intel:dffml:public-keys:x509
subject: pkg:github/${{ github.repository }}@${{ github.sha }}
payload: ${{ steps.vexctl.outputs.openvex }}
private-key-pem: private-key.pem
scitt-url: https://scitt.unstable.chadig.com
- name: Remove private key used in keypair to sign SCITT statement
run: |
rm -v private-key.pem
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 40
matrix:
check: [changelog, whitespace, commit, lines]
python-version: [3.7]
node-version: [12.x]
steps:
- uses: actions/checkout@v4
- name: Checkout full upstream repo
run: |
git remote set-url origin https://github.com/intel/dffml
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
git config --global user.email "[email protected]"
git config --global user.name "DFFML CI/CD"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
set -x
./.ci/deps.sh ${{ matrix.check }}
- name: Run check
run: |
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
SSH_DFFML_GH_PAGES=${{ secrets.SSH_DFFML_GH_PAGES }} ./.ci/run.sh ${{ matrix.check }}
container:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
set -x
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io
- name: Run check
run: |
./.ci/run.sh container
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 100
matrix:
plugin:
- model/daal4py
- model/tensorflow
- model/scratch
- model/scikit
- model/vowpalWabbit
- model/autosklearn
- model/xgboost
- operations/binsec
- operations/data
- operations/deploy
- operations/image
- operations/nlp
- source/mysql
- feature/git
- feature/auth
- service/http
- configloader/yaml
- configloader/image
- source/mongodb
- entities/alice
python-version:
- "3.12"
steps:
- uses: actions/checkout@v4
- name: Checkout full upstream repo
run: |
git remote set-url origin https://github.com/intel/dffml
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
git config --global user.email "[email protected]"
git config --global user.name "DFFML CI/CD"
- name: Remove unused software
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: shouldi test binary cache
uses: actions/cache@v3
with:
path: examples/shouldi/tests/downloads
key: ${{ hashFiles('examples/shouldi/tests/binaries.py') }}
restore-keys: |
${{ runner.os }}-shouldi-test-binaries-
- name: Install dependencies
run: |
set -x
./.ci/deps.sh ${{ matrix.plugin }}
- name: Test
run: |
set -x
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
export PYTHON=python${{ matrix.python-version }}
export PLUGIN=${{ matrix.plugin }}
export LOGGING=debug
export PATH="${HOME}/.local/bin:${PATH}"
export PYPI_TOKENS=$(mktemp)
cat > ${PYPI_TOKENS} <<EOF
examples/shouldi=${{ secrets.PYPI_SHOULDI }}
model/daal4py=${{ secrets.PYPI_MODEL_DAAL4PY }}
model/tensorflow=${{ secrets.PYPI_MODEL_TENSORFLOW }}
model/tensorflow_hub=${{ secrets.PYPI_MODEL_TENSORFLOW_HUB }}
model/scratch=${{ secrets.PYPI_MODEL_SCRATCH }}
model/scikit=${{ secrets.PYPI_MODEL_SCIKIT }}
model/spacy=${{ secrets.PYPI_MODEL_SPACY }}
model/vowpalWabbit=${{ secrets.PYPI_MODEL_VOWPALWABBIT }}
model/autosklearn=${{ secrets.PYPI_MODEL_AUTOSKLEARN }}
model/pytorch=${{ secrets.PYPI_MODEL_PYTORCH }}
model/xgboost=${{ secrets.PYPI_MODEL_XGBOOST }}
source/mysql=${{ secrets.PYPI_SOURCE_MYSQL }}
source/mongodb=${{ secrets.PYPI_SOURCE_MONGODB }}
feature/git=${{ secrets.PYPI_FEATURE_GIT }}
feature/auth=${{ secrets.PYPI_FEATURE_AUTH }}
operations/binsec=${{ secrets.PYPI_OPERATIONS_BINSEC }}
operations/data=${{ secrets.PYPI_OPERATIONS_DATA }}
operations/deploy=${{ secrets.PYPI_OPERATIONS_DEPLOY }}
operations/image=${{ secrets.PYPI_OPERATIONS_IMAGE }}
operations/nlp=${{ secrets.PYPI_OPERATIONS_NLP }}
service/http=${{ secrets.PYPI_SERVICE_HTTP }}
configloader/yaml=${{ secrets.PYPI_CONFIG_YAML }}
configloader/image=${{ secrets.PYPI_CONFIG_IMAGE }}
EOF
export TWINE_USERNAME=__token__
if [ "x${PLUGIN}" = "x." ]; then
export TWINE_PASSWORD=${{ secrets.PYPI_DFFML }}
else
export TWINE_PASSWORD=$(grep "${PLUGIN}=" "${PYPI_TOKENS}" | sed 's/^[^=]*=//g')
fi
rm ${PYPI_TOKENS}
./.ci/run.sh "${PLUGIN}"
if [ "x${PLUGIN}" = "x." ]; then
CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} codecov
fi
tutorials:
runs-on: ubuntu-latest
if: false
strategy:
fail-fast: false
max-parallel: 100
matrix:
python-version: [3.7]
docs:
- docs/cli.rst
- docs/examples/dataflows.rst
- docs/examples/integration.rst
- docs/examples/or_covid_data_by_county.rst
- docs/examples/shouldi.rst
- docs/examples/innersource/swportal.rst
- docs/examples/innersource/microservice.rst
- docs/examples/innersource/kubernetes.rst
- docs/examples/icecream_sales.rst
- docs/examples/data_cleanup/data_cleanup.rst
- docs/examples/data_cleanup/data_cleanup_classfication.rst
- docs/installation.rst
- docs/troubleshooting.rst
- docs/tutorials/accuracy/mse.rst
- docs/tutorials/dataflows/io.rst
- docs/tutorials/dataflows/nlp.rst
- docs/tutorials/models/iris.rst
- docs/tutorials/models/package.rst
- docs/tutorials/models/docs.rst
- docs/tutorials/models/slr.rst
- docs/tutorials/sources/complex.rst
- docs/tutorials/sources/file.rst
steps:
- uses: actions/checkout@v4
- name: Checkout full upstream repo
run: |
git remote set-url origin https://github.com/intel/dffml
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
git config --global user.email "[email protected]"
git config --global user.name "DFFML CI/CD"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
set -x
./.ci/deps.sh .
- name: Test
run: |
set -x
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
export PYTHON=python${{ matrix.python-version }}
export PLUGIN=${{ matrix.plugin }}
export LOGGING=debug
export PATH="${HOME}/.local/bin:${PATH}"
./.ci/run.sh consoletest ${{ matrix.docs }}
macos:
runs-on: macos-latest
if: false
strategy:
fail-fast: false
matrix:
python-version: [3.7]
steps:
- uses: actions/checkout@v4
- name: Checkout full upstream repo
run: |
git remote set-url origin https://github.com/intel/dffml
git fetch --prune --unshallow
git config --global user.email "[email protected]"
git config --global user.name "DFFML CI/CD"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Setup DFFML
run: |
pip install -U pip setuptools wheel
pip install -e .[dev]
dffml service dev install -skip model/daal4py
# XGBoost requires libomp on OSX
brew install libomp
- name: Test
run: |
python -m unittest discover -v
python -m pip freeze