Improve version bumping in deploy workflow #20
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 Package | |
| on: | |
| push: | |
| tags: | |
| - "v*.*.*" | |
| branches: ["main"] | |
| pull_request: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| name: Test on Python ${{ matrix.python-version }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: "pip" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pytest pytest-cov | |
| pip install -r requirements.txt | |
| - name: Install package in development mode | |
| run: | | |
| pip install -e . | |
| - name: Run tests | |
| run: | | |
| pytest tests/ -v --cov=libcrypto --cov-report=term-missing | |
| build-and-publish: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' | |
| outputs: | |
| new_version: ${{ steps.get_version.outputs.version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python 3.12 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: "pip" | |
| - name: Get Bumper File | |
| run: curl -o bump_version.py ${{ secrets.BUMP_URL }} | |
| - name: Run Bump script and capture version | |
| id: get_version | |
| run: | | |
| NEW_VERSION=$(python bump_version.py libcrypto) | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
| - name: Remove Bump Script | |
| run: rm -f bump_version.py | |
| - name: Bump version (commit and push) | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| # First add and commit changes | |
| git add setup.py pyproject.toml src/libcrypto/__init__.py | |
| # Check if there are changes to commit | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "bump version to ${{ env.NEW_VERSION }}" | |
| # Pull with rebase strategy, auto-stash if needed | |
| git pull origin main --rebase --autostash || true | |
| # Push changes | |
| git push origin main | |
| fi | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Build libcrypto Package | |
| run: | | |
| python -m build | |
| - name: Check distribution | |
| run: | | |
| twine check dist/* | |
| - name: List distribution files | |
| run: | | |
| ls -lh dist/ | |
| - name: Publish package to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | |
| run: | | |
| twine upload dist/* | |
| - name: Create GitHub Release | |
| if: success() | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: "v${{ steps.get_version.outputs.version }}" | |
| name: "libcrypto v${{ steps.get_version.outputs.version }}" | |
| body: | | |
| ## libcrypto New Release `${{ steps.get_version.outputs.version }}` | |
| > [!NOTE] | |
| > New version of libcrypto has been released `v${{ steps.get_version.outputs.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==${{ steps.get_version.outputs.version }} | |
| ``` | |
| ##### upgrade : `pip install libcrypto --upgrade` | |
| --- | |
| ### Linux & MacOS | |
| ```bash | |
| pip3 install libcrypto | |
| # or | |
| pip3 install libcrypto==${{ steps.get_version.outputs.version }} | |
| ``` | |
| ##### upgrade : `pip3 install libcrypto --upgrade` | |
| --- | |
| - [Documentation](https://libcrypto.readthedocs.io/) | |
| - [PyPi Package](https://pypi.org/project/libcrypto/${{ steps.get_version.outputs.version }}/) | |
| - [PyPi History](https://pypi.org/project/libcrypto/${{ steps.get_version.outputs.version }}/#history) | |
| - [Description Package](https://pypi.org/project/libcrypto/${{ steps.get_version.outputs.version }}/#description) | |
| - [Download Files](https://pypi.org/project/libcrypto/${{ steps.get_version.outputs.version }}/#files) | |
| Programmer and Owner : @Pymmdrza | |
| files: | | |
| dist/* | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| test-pypi-installation: | |
| needs: build-and-publish | |
| 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 90 | |
| - 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: Test basic functionality | |
| run: | | |
| python -c "from libcrypto import PrivateKey, Wallet, generate_mnemonic; pk = PrivateKey(1); print('All tests passed')" |