Skip to content

Commit d862649

Browse files
committed
added wheel_rename to handle python tags in wheel distro
1 parent dfb6d23 commit d862649

File tree

2 files changed

+92
-66
lines changed

2 files changed

+92
-66
lines changed

.github/workflows/create-release.yml

Lines changed: 56 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,54 @@ jobs:
5252
PCAPKIT_TAG_EXISTS: ${{ steps.check_tag.outputs.exists }}
5353
PCAPKIT_CONDA_LABEL: ${{ steps.get_version.outputs.PCAPKIT_CONDA_LABEL }}
5454

55-
pypi_github:
56-
name: PyPI & GitHub Release # with Python ${{ matrix.python-version }}
55+
github:
56+
name: GitHub Release
5757
runs-on: ubuntu-latest
5858
needs: [ version_check ]
5959
if: ${{ startsWith(github.ref_name, 'v') || needs.version_check.outputs.PCAPKIT_TAG_EXISTS == 'false' }}
60-
# strategy:
61-
# matrix:
62-
# python-version:
63-
# - "3.7"
64-
# - "3.8"
65-
# - "3.9"
66-
# - "3.10"
67-
# - "3.11"
68-
# - "pypy3.7"
69-
# - "pypy3.8"
70-
# - "pypy3.9"
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v3
63+
with:
64+
fetch-depth: 0
65+
66+
- name: Changelog
67+
uses: Bullrich/generate-release-changelog@master
68+
id: changelog
69+
env:
70+
REPO: ${{ github.repository }}
71+
72+
- name: Create Release
73+
id: create_release
74+
uses: ncipollo/release-action@v1.12.0
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
77+
with:
78+
# allowUpdates: true
79+
# artifacts: |
80+
# dist/*
81+
# body: ${{ env.PCAPKIT_CHANGELOG }}
82+
body: |
83+
${{ steps.changelog.outputs.changelog }}
84+
# generateReleaseNotes: true
85+
# makeLatest: true
86+
name: PyPCAPKit v${{ needs.version_check.outputs.PCAPKIT_VERSION }}
87+
prerelease: ${{ needs.version_check.outputs.PCAPKIT_PRERELEASE }}
88+
tag: "v${{ needs.version_check.outputs.PCAPKIT_VERSION }}"
89+
token: "${{ secrets.GITHUB_TOKEN }}"
90+
91+
pypi:
92+
name: PyPI distribution for Python ${{ matrix.python-version }}
93+
runs-on: ubuntu-latest
94+
needs: [ github, version_check ]
95+
if: ${{ startsWith(github.ref_name, 'v') || needs.version_check.outputs.PCAPKIT_TAG_EXISTS == 'false' }}
96+
strategy:
97+
matrix:
98+
python-version:
99+
- "3.8"
100+
- "3.9"
101+
- "3.10"
102+
- "3.11"
71103
steps:
72104
- name: Checkout code
73105
uses: actions/checkout@v3
@@ -76,7 +108,7 @@ jobs:
76108

77109
- uses: actions/setup-python@v4
78110
with:
79-
python-version: '3.11' # ${{ matrix.python-version }}
111+
python-version: ${{ matrix.python-version }}
80112

81113
- name: Install and Setup
82114
run: |
@@ -85,15 +117,19 @@ jobs:
85117
python -m pip install -U pip setuptools wheel
86118
python -m pip install -U build
87119
88-
- name: Build Package (latest)
89-
#if: ${{ matrix.python-version == '3.11' }}
120+
- name: Build Package
121+
env:
122+
PCAPKIT_VERSION: ${{ needs.version_check.outputs.PCAPKIT_VERSION }}
90123
run: |
91124
python -m build
92125
93-
# - name: Build Package (others)
94-
# if: ${{ matrix.python-version != '3.11' }}
95-
# run: |
96-
# python -m build --wheel
126+
# rename wheel's python tag
127+
python util/wheel_rename.py dist/*.whl
128+
129+
- name: No Source Distribution for Python ${{ matrix.python-version }}
130+
if: ${{ matrix.python-version != '3.11' }}
131+
run: |
132+
rm dist/*.tar.gz
97133
98134
- name: Publish to PyPI
99135
uses: pypa/gh-action-pypi-publish@release/v1
@@ -108,52 +144,6 @@ jobs:
108144
repository-url: https://test.pypi.org/legacy/
109145
skip-existing: true
110146

111-
- name: Changelog
112-
uses: Bullrich/generate-release-changelog@master
113-
id: changelog
114-
env:
115-
REPO: ${{ github.repository }}
116-
117-
# run: |
118-
# # NOTE: inspired from Bullrich/generate-release-changelog
119-
# # https://github.com/Bullrich/generate-release-changelog/blob/master/entrypoint.sh
120-
121-
# tag=$(git tag --sort version:refname | tail -n 2 | head -n 1)
122-
# echo tag=$tag
123-
124-
# if [ "$tag" ]; then
125-
# changelog=$(git log --oneline --no-decorate $tag..HEAD)
126-
# else
127-
# changelog=$(git log --oneline --no-decorate)
128-
# fi
129-
130-
# echo $changelog
131-
132-
# changelog="${changelog//'%'/'%25'}"
133-
# changelog="${changelog//$'\n'/'%0A' - }"
134-
# changelog=" - ${changelog//$'\r'/'%0D'}"
135-
136-
# echo "PCAPKIT_CHANGELOG=$changelog" >> $GITHUB_ENV
137-
138-
- name: Create Release
139-
id: create_release
140-
uses: ncipollo/release-action@v1.12.0
141-
env:
142-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
143-
with:
144-
# allowUpdates: true
145-
artifacts: |
146-
dist/*
147-
# body: ${{ env.PCAPKIT_CHANGELOG }}
148-
body: |
149-
${{ steps.changelog.outputs.changelog }}
150-
# generateReleaseNotes: true
151-
# makeLatest: true
152-
name: PyPCAPKit v${{ needs.version_check.outputs.PCAPKIT_VERSION }}
153-
prerelease: ${{ needs.version_check.outputs.PCAPKIT_PRERELEASE }}
154-
tag: "v${{ needs.version_check.outputs.PCAPKIT_VERSION }}"
155-
token: "${{ secrets.GITHUB_TOKEN }}"
156-
157147
conda:
158148
name: Conda deployment of package with Python ${{ matrix.python-version }}
159149
runs-on: ubuntu-latest

util/wheel_rename.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import shutil
5+
import sys
6+
import warnings
7+
8+
# python implementation
9+
MAP_IMPL = {
10+
'cpython': 'cp',
11+
'pypy': 'pp',
12+
}
13+
implementation = MAP_IMPL.get(sys.implementation.name)
14+
if implementation is None:
15+
raise ValueError(f'Unknown Python implementation: {sys.implementation.name}')
16+
python = f'{implementation}%s%s' % sys.version_info[:2]
17+
18+
for file in sys.argv[1:]:
19+
root, name = os.path.split(file)
20+
if not name.endswith('.whl'):
21+
continue
22+
23+
# wheel name format
24+
# {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl
25+
try:
26+
distribution, version, _, abi, platform = os.path.splitext(name)[0].split('-')
27+
except ValueError:
28+
warnings.warn(f'Unknown filename: {name}')
29+
continue
30+
31+
if distribution != 'pypcapkit':
32+
warnings.warn(f'Unknown distribution: {distribution}')
33+
continue
34+
35+
new_file = f'pypcapkit-{version}-{python}-{abi}-{platform}.whl'
36+
shutil.move(file, os.path.join(root, new_file))

0 commit comments

Comments
 (0)