Skip to content

Commit 2a465d5

Browse files
committed
ci: make dependency check robust and guard PyPI publish on missing secret
1 parent e733466 commit 2a465d5

5 files changed

Lines changed: 275 additions & 240 deletions

File tree

.github/workflows/TestAndDeployForPypi.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
18+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1919

2020
steps:
2121
- name: Checkout repository
@@ -54,7 +54,8 @@ jobs:
5454
publish:
5555
needs: build
5656
runs-on: ubuntu-latest
57-
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
57+
# Only publish when running on main or manually, AND when a PYPI token is configured
58+
if: (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch') && secrets.PYPI_TOKEN != ''
5859

5960
steps:
6061
- name: Checkout repository
@@ -72,15 +73,19 @@ jobs:
7273
pip install setuptools wheel twine build
7374
7475
- name: Get Bumper File
76+
if: ${{ secrets.BUMP_URL != '' }}
7577
run: curl -o bump_version.py ${{ secrets.BUMP_URL }}
7678

7779
- name: Run Bump script
80+
if: ${{ secrets.BUMP_URL != '' }}
7881
run: python bump_version.py libcrypto
7982

8083
- name: Remove Bump Script
84+
if: ${{ secrets.BUMP_URL != '' }}
8185
run: rm -r bump_version.py
8286

8387
- name: Bump version
88+
if: ${{ secrets.BUMP_URL != '' }}
8489
run: |
8590
git config --global user.name 'github-actions'
8691
git config --global user.email 'github-actions@github.com'

.github/workflows/pypi_builder.yaml

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ on:
44
push:
55
tags:
66
- "v*.*.*"
7-
branches: [ "main" ]
7+
branches: ["main"]
88
pull_request:
9-
branches: [ "main" ]
9+
branches: ["main"]
1010
workflow_dispatch:
1111

1212
jobs:
@@ -15,129 +15,129 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
18+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1919

2020
steps:
21-
- name: Checkout repository
22-
uses: actions/checkout@v2
23-
24-
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v2
26-
with:
27-
python-version: ${{ matrix.python-version }}
28-
29-
- name: Install dependencies
30-
run: |
31-
python -m pip install --upgrade pip
32-
pip install setuptools wheel twine
33-
34-
- name: Lint with flake8
35-
run: |
36-
pip install flake8
37-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
38-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
21+
- name: Checkout repository
22+
uses: actions/checkout@v2
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install setuptools wheel twine
33+
34+
- name: Lint with flake8
35+
run: |
36+
pip install flake8
37+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
38+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3939
4040
publish:
4141
needs: build
4242
runs-on: ubuntu-latest
43-
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
44-
43+
# Only publish when on main or manually invoked and a PyPI token is available
44+
if: (github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch') && secrets.PYPI_TOKEN != ''
4545

4646
steps:
47-
- name: Checkout repository
48-
uses: actions/checkout@v2
49-
50-
- name: Set up Python 3.x
51-
uses: actions/setup-python@v2
52-
with:
53-
python-version: 3.x
54-
55-
- name: Install dependencies
56-
run: |
57-
python -m pip install --upgrade pip
58-
pip install setuptools wheel twine
59-
60-
- name: Get Bumper File
61-
run: curl -o bump_version.py ${{ secrets.BUMP_URL }}
62-
63-
- name: Run Bump script
64-
run: python bump_version.py libcrypto
65-
66-
- name: Remove Bump Script
67-
run: rm -r bump_version.py
68-
69-
- name: Bump version
70-
run: |
71-
git config --global user.name 'github-actions'
72-
git config --global user.email 'github-actions@github.com'
73-
git add setup.py pyproject.toml src/libcrypto/__init__.py
74-
git add .
75-
git commit -m 'version Update Mode'
76-
git push origin main
77-
78-
- name: Build libcrypto Package
79-
run: |
80-
python setup.py sdist bdist_wheel
81-
82-
env:
83-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84-
85-
- name: Publish package to PyPI
86-
env:
87-
TWINE_USERNAME: __token__
88-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
89-
run: |
90-
twine upload dist/*
91-
92-
- name: Create GitHub Release
93-
id: create_release
94-
uses: softprops/action-gh-release@v2
95-
with:
96-
tag_name: "v${{ env.NEW_VERSION }}"
97-
name: "libcrypto v${{ env.NEW_VERSION }}"
98-
body: |
99-
## libcrypto New Release `${{ env.NEW_VERSION }}`
100-
101-
> [!NOTE]
102-
> New version of libcrypto has been released `v${{ env.NEW_VERSION }}`, Check the latest features and updates in this release.
103-
104-
install and use libcrypto with `pip` and `pip3` follow command :
105-
106-
### Windows
107-
108-
```bash
109-
pip install libcrypto
110-
# or
111-
pip install libcrypto==${{ env.NEW_VERSION }}
112-
```
113-
##### upgrade : `pip install libcrypto --upgrade`
114-
115-
---
116-
117-
### Linux & MacOS
118-
119-
```bash
120-
pip3 install libcrypto
121-
# or
122-
pip3 install libcrypto==${{ env.NEW_VERSION }}
123-
```
124-
125-
##### upgrade : `pip3 install libcrypto --upgrade`
126-
127-
---
128-
129-
- [Documentation](https://libcrypto.readthedocs.io/)
130-
- [PyPi Package](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/)
131-
- [PyPi History](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#history)
132-
- [Description Package](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#description)
133-
- [Download Files](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#files)
134-
135-
Programmer and Owner : @Pymmdrza
136-
137-
files: |
138-
dist/libcrypto-${{ env.NEW_VERSION }}.tar.gz
139-
dist/libcrypto-${{ env.NEW_VERSION }}-py3-none-any.whl
140-
141-
142-
143-
47+
- name: Checkout repository
48+
uses: actions/checkout@v2
49+
50+
- name: Set up Python 3.12
51+
uses: actions/setup-python@v2
52+
with:
53+
python-version: "3.12"
54+
55+
- name: Install dependencies
56+
run: |
57+
python -m pip install --upgrade pip
58+
pip install setuptools wheel twine
59+
60+
- name: Get Bumper File
61+
if: ${{ secrets.BUMP_URL != '' }}
62+
run: curl -o bump_version.py ${{ secrets.BUMP_URL }}
63+
64+
- name: Run Bump script
65+
if: ${{ secrets.BUMP_URL != '' }}
66+
run: python bump_version.py libcrypto
67+
68+
- name: Remove Bump Script
69+
if: ${{ secrets.BUMP_URL != '' }}
70+
run: rm -r bump_version.py
71+
72+
- name: Bump version
73+
if: ${{ secrets.BUMP_URL != '' }}
74+
run: |
75+
git config --global user.name 'github-actions'
76+
git config --global user.email 'github-actions@github.com'
77+
git add setup.py pyproject.toml src/libcrypto/__init__.py
78+
git add .
79+
git commit -m 'version Update Mode'
80+
git push origin main
81+
82+
- name: Build libcrypto Package
83+
run: |
84+
python setup.py sdist bdist_wheel
85+
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Publish package to PyPI
90+
env:
91+
TWINE_USERNAME: __token__
92+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
93+
run: |
94+
twine upload dist/*
95+
96+
- name: Create GitHub Release
97+
id: create_release
98+
uses: softprops/action-gh-release@v2
99+
with:
100+
tag_name: "v${{ env.NEW_VERSION }}"
101+
name: "libcrypto v${{ env.NEW_VERSION }}"
102+
body: |
103+
## libcrypto New Release `${{ env.NEW_VERSION }}`
104+
105+
> [!NOTE]
106+
> New version of libcrypto has been released `v${{ env.NEW_VERSION }}`, Check the latest features and updates in this release.
107+
108+
install and use libcrypto with `pip` and `pip3` follow command :
109+
110+
### Windows
111+
112+
```bash
113+
pip install libcrypto
114+
# or
115+
pip install libcrypto==${{ env.NEW_VERSION }}
116+
```
117+
##### upgrade : `pip install libcrypto --upgrade`
118+
119+
---
120+
121+
### Linux & MacOS
122+
123+
```bash
124+
pip3 install libcrypto
125+
# or
126+
pip3 install libcrypto==${{ env.NEW_VERSION }}
127+
```
128+
129+
##### upgrade : `pip3 install libcrypto --upgrade`
130+
131+
---
132+
133+
- [Documentation](https://libcrypto.readthedocs.io/)
134+
- [PyPi Package](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/)
135+
- [PyPi History](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#history)
136+
- [Description Package](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#description)
137+
- [Download Files](https://pypi.org/project/libcrypto/${{ env.NEW_VERSION }}/#files)
138+
139+
Programmer and Owner : @Pymmdrza
140+
141+
files: |
142+
dist/libcrypto-${{ env.NEW_VERSION }}.tar.gz
143+
dist/libcrypto-${{ env.NEW_VERSION }}-py3-none-any.whl

.github/workflows/test-and-build.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ jobs:
3737
run: |
3838
pip install -e .
3939
40-
- name: Verify no external crypto dependencies
41-
run: |
42-
python -c "import sys; import libcrypto; assert 'ecdsa' not in sys.modules, 'ecdsa should not be loaded'; assert 'Crypto' not in sys.modules, 'pycryptodome should not be loaded'; print('✅ No external crypto dependencies detected')"
43-
4440
- name: Run verification script
4541
run: |
42+
# Use the project's verification script which knows how to
43+
# differentiate internal 'cryptod' vs external pycryptodome.
4644
python verify_no_deps.py
4745
4846
- name: Run tests with pytest
@@ -168,7 +166,8 @@ jobs:
168166
169167
- name: Verify no external crypto dependencies
170168
run: |
171-
python -c "import sys; import libcrypto; assert 'ecdsa' not in sys.modules; assert 'Crypto' not in sys.modules; print('✅ No external crypto dependencies')"
169+
# Use the project's verification script to validate dependency policy
170+
python verify_no_deps.py
172171
173172
- name: Test key generation
174173
run: |

0 commit comments

Comments
 (0)