Repository navigation
117 lines (108 loc) · 3.74 KB
/
Copy pathpython_ci.yml
File metadata and controls
117 lines (108 loc) · 3.74 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
name: Param builder Python CI
on:
push:
paths:
- 'python/**'
- '.github/workflows/python_ci.yml'
- '.github/workflows/python_cd.yml'
tags-ignore:
- 'v*' # Ignores all tag pushes
branches:
- '**'
pull_request:
paths:
- 'python/**'
- '.github/workflows/python_ci.yml'
- '.github/workflows/python_cd.yml'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: python/capi_param_builder
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
name: CI Test on Python ${{ matrix.python-version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Unit test
run: |
python3 -m unittest discover -s test -t . -p 'test_*.py' -v
package:
runs-on: ubuntu-latest
defaults:
run:
working-directory: python/capi_param_builder
name: Validate Python distribution
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install packaging tools
run: python -m pip install build twine
- name: Build distribution
run: python -m build
- name: Verify distribution metadata
run: |
python -m twine check dist/*
python - <<'PY'
from email.parser import BytesParser
from email.policy import default
from pathlib import Path
import tarfile
import zipfile
project_root = Path.cwd()
dist_directory = project_root / 'dist'
expected_license = (project_root / 'LICENSE').read_bytes()
wheels = list(dist_directory.glob('*.whl'))
source_distributions = list(dist_directory.glob('*.tar.gz'))
assert len(wheels) == 1, wheels
assert len(source_distributions) == 1, source_distributions
with zipfile.ZipFile(wheels[0]) as archive:
metadata_name = next(
name
for name in archive.namelist()
if name.endswith('.dist-info/METADATA')
)
license_name = next(
name
for name in archive.namelist()
if name.endswith('.dist-info/licenses/LICENSE')
)
metadata = BytesParser(policy=default).parsebytes(
archive.read(metadata_name)
)
assert metadata['License'] == 'LICENSE.txt'
assert 'LICENSE' in metadata.get_all('License-File', [])
assert archive.read(license_name) == expected_license
with tarfile.open(source_distributions[0], 'r:gz') as archive:
members = {member.name: member for member in archive.getmembers()}
metadata_name = next(
name
for name in members
if name.endswith('/PKG-INFO') and name.count('/') == 1
)
license_name = next(
name for name in members if name.endswith('/LICENSE')
)
metadata_file = archive.extractfile(members[metadata_name])
license_file = archive.extractfile(members[license_name])
assert metadata_file is not None
assert license_file is not None
metadata = BytesParser(policy=default).parsebytes(
metadata_file.read()
)
assert metadata['License'] == 'LICENSE.txt'
assert 'LICENSE' in metadata.get_all('License-File', [])
assert license_file.read() == expected_license
PY