Skip to content

Commit e89246d

Browse files
authored
Refactor deploy-pypi-release workflow
Refactor GitHub Actions workflow for PyPI release, adding test job and updating version bumping process.
1 parent d9fa5ef commit e89246d

File tree

1 file changed

+85
-67
lines changed

1 file changed

+85
-67
lines changed

.github/workflows/deploy-pypi-release.yaml

Lines changed: 85 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
build:
13+
test:
14+
name: Test on Python ${{ matrix.python-version }}
1415
runs-on: ubuntu-latest
1516
strategy:
1617
fail-fast: false
@@ -24,28 +25,8 @@ jobs:
2425
- name: Set up Python ${{ matrix.python-version }}
2526
uses: actions/setup-python@v5
2627
with:
27-
python-version: ${{ matrix.python-version }}
28-
cache: "pip"
29-
30-
- name: bumper version
31-
run: curl -o bump_version.py ${{ secrets.BUMP_URL }}
32-
33-
- name: Run Bump script and set version to env
34-
run: python bump_version.py libcrypto
35-
36-
- name: Remove Bump Script
37-
run: rm -r bump_version.py
38-
39-
- name: Bump version
40-
run: |
41-
git config --global user.name 'github-actions'
42-
git config --global user.email '[email protected]'
43-
git fetch origin main --force
44-
git pull origin main --rebase
45-
git add setup.py pyproject.toml src/libcrypto/__init__.py
46-
git add .
47-
git commit -m 'version Update Mode' || echo "No changes to commit"
48-
git push origin main
28+
python-version: ${{ matrix.python-version }}
29+
cache: "pip"
4930

5031
- name: Install dependencies
5132
run: |
@@ -61,60 +42,64 @@ jobs:
6142
run: |
6243
pytest tests/ -v --cov=libcrypto --cov-report=term-missing
6344
64-
- name: Install build tools
65-
run: |
66-
pip install build twine
67-
68-
- name: Build package
69-
run: |
70-
python -m build
71-
72-
- name: Check distribution
73-
run: |
74-
twine check dist/*
75-
publish:
76-
needs: build
45+
build-and-publish:
46+
needs: test
7747
runs-on: ubuntu-latest
7848
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
49+
outputs:
50+
new_version: ${{ steps.get_version.outputs.version }}
7951

8052
steps:
8153
- name: Checkout repository
82-
uses: actions/checkout@v2
54+
uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 0
57+
token: ${{ secrets.GITHUB_TOKEN }}
8358

8459
- name: Set up Python 3.12
85-
uses: actions/setup-python@v2
60+
uses: actions/setup-python@v5
8661
with:
8762
python-version: "3.12"
88-
89-
- name: Install dependencies
90-
run: |
91-
python -m pip install --upgrade pip
92-
pip install setuptools wheel twine
63+
cache: "pip"
9364

9465
- name: Get Bumper File
9566
run: curl -o bump_version.py ${{ secrets.BUMP_URL }}
9667

97-
- name: Run Bump script
98-
run: python bump_version.py libcrypto
68+
- name: Run Bump script and capture version
69+
id: get_version
70+
run: |
71+
NEW_VERSION=$(python bump_version.py libcrypto)
72+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
73+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
9974
10075
- name: Remove Bump Script
101-
run: rm -r bump_version.py
76+
run: rm -f bump_version.py
10277

103-
- name: Bump version
78+
- name: Bump version (commit and push)
10479
run: |
105-
git config --global user.name 'github-actions'
106-
git config --global user.email '[email protected]'
80+
git config --global user.name 'github-actions[bot]'
81+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
82+
git pull origin main --rebase
10783
git add setup.py pyproject.toml src/libcrypto/__init__.py
108-
git add .
109-
git commit -m 'version Update Mode'
84+
git commit -m "chore: bump version to ${{ env.NEW_VERSION }}" || echo "No changes to commit"
11085
git push origin main
11186
87+
- name: Install build tools
88+
run: |
89+
python -m pip install --upgrade pip
90+
pip install build twine
91+
11292
- name: Build libcrypto Package
11393
run: |
114-
python setup.py sdist bdist_wheel
94+
python -m build
11595
116-
env:
117-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
- name: Check distribution
97+
run: |
98+
twine check dist/*
99+
100+
- name: List distribution files
101+
run: |
102+
ls -lh dist/
118103
119104
- name: Publish package to PyPI
120105
env:
@@ -124,16 +109,16 @@ jobs:
124109
twine upload dist/*
125110
126111
- name: Create GitHub Release
127-
id: create_release
112+
if: success()
128113
uses: softprops/action-gh-release@v2
129114
with:
130-
tag_name: "v${{ env.NEW_VERSION }}"
131-
name: "libcrypto v${{ env.NEW_VERSION }}"
115+
tag_name: "v${{ steps.get_version.outputs.version }}"
116+
name: "libcrypto v${{ steps.get_version.outputs.version }}"
132117
body: |
133-
## libcrypto New Release `${{ env.NEW_VERSION }}`
118+
## libcrypto New Release `${{ steps.get_version.outputs.version }}`
134119
135120
> [!NOTE]
136-
> New version of libcrypto has been released `v${{ env.NEW_VERSION }}`, Check the latest features and updates in this release.
121+
> New version of libcrypto has been released `v${{ steps.get_version.outputs.version }}`, Check the latest features and updates in this release.
137122
138123
install and use libcrypto with `pip` and `pip3` follow command :
139124
@@ -142,7 +127,7 @@ jobs:
142127
```bash
143128
pip install libcrypto
144129
# or
145-
pip install libcrypto==${{ env.NEW_VERSION }}
130+
pip install libcrypto==${{ steps.get_version.outputs.version }}
146131
```
147132
##### upgrade : `pip install libcrypto --upgrade`
148133
@@ -153,21 +138,54 @@ jobs:
153138
```bash
154139
pip3 install libcrypto
155140
# or
156-
pip3 install libcrypto==${{ env.NEW_VERSION }}
141+
pip3 install libcrypto==${{ steps.get_version.outputs.version }}
157142
```
158143
159144
##### upgrade : `pip3 install libcrypto --upgrade`
160145
161146
---
162147
163148
- [Documentation](https://libcrypto.readthedocs.io/)
164-
- [PyPi Package](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/)
165-
- [PyPi History](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#history)
166-
- [Description Package](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#description)
167-
- [Download Files](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#files)
149+
- [PyPi Package](https://pypi.org/project/libcrypto/${{ steps.get_version.outputs.version }}/)
150+
- [PyPi History](https://pypi.org/project/libcrypto/${{ steps.get_version.outputs.version }}/#history)
151+
- [Description Package](https://pypi.org/project/libcrypto/${{ steps.get_version.outputs.version }}/#description)
152+
- [Download Files](https://pypi.org/project/libcrypto/${{ steps.get_version.outputs.version }}/#files)
168153
169154
Programmer and Owner : @Pymmdrza
170155
171156
files: |
172-
dist/libcrypto-${{ env.NEW_VERSION }}.tar.gz
173-
dist/libcrypto-${{ env.NEW_VERSION }}-py3-none-any.whl
157+
dist/*
158+
draft: false
159+
prerelease: false
160+
env:
161+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
162+
163+
test-pypi-installation:
164+
needs: build-and-publish
165+
name: Test PyPI Installation
166+
runs-on: ${{ matrix.os }}
167+
strategy:
168+
matrix:
169+
os: [ubuntu-latest, windows-latest, macos-latest]
170+
python-version: ["3.8", "3.12"]
171+
172+
steps:
173+
- name: Set up Python ${{ matrix.python-version }}
174+
uses: actions/setup-python@v5
175+
with:
176+
python-version: ${{ matrix.python-version }}
177+
178+
- name: Wait for PyPI to update
179+
run: sleep 90
180+
181+
- name: Install from PyPI
182+
run: |
183+
pip install libcrypto --upgrade --no-cache-dir
184+
185+
- name: Test import
186+
run: |
187+
python -c "import libcrypto; print('LibCrypto version:', libcrypto.__version__)"
188+
189+
- name: Test basic functionality
190+
run: |
191+
python -c "from libcrypto import PrivateKey, Wallet, generate_mnemonic; pk = PrivateKey(1); print('All tests passed')"

0 commit comments

Comments
 (0)