Skip to content

Commit

Permalink
Merge pull request #517 from LedgerHQ/pypi
Browse files Browse the repository at this point in the history
Eth client Python package only deployed on pypi.org
  • Loading branch information
lpascal-ledger authored Feb 7, 2024
2 parents 1dc403f + 08077ff commit df74ace
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 57 deletions.
93 changes: 40 additions & 53 deletions .github/workflows/python-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: Python client checks, package build and deployment
on:
workflow_dispatch:
push:
tags:
- 'client-*'
branches:
- develop
- master
Expand All @@ -22,9 +24,9 @@ jobs:
steps:
- name: Clone
uses: actions/checkout@v3
- run: pip install flake8
- run: pip install flake8 flake8-pyproject
- name: Flake8 lint Python code
run: (cd client && find src/ -type f -name '*.py' -exec flake8 --max-line-length=120 '{}' '+')
run: (cd client && flake8 src/)

mypy:
name: Type checking
Expand All @@ -36,58 +38,43 @@ jobs:
- name: Mypy type checking
run: (cd client && mypy src/)

get-develop-version:
name: Get develop version
package_and_deploy:
name: Build and deploy Ethereum Client Python package
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.base_ref == 'develop' }}
outputs:
develop_version: ${{ steps.get-version.outputs.develop_version }}
needs: [lint, mypy]
steps:
- name: Check Out Code
uses: actions/checkout@v3
with:
ref: develop
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12.0
- name: Get version
id: get-version
env:
PYTHONPATH: client/src/ledger_app_clients
run: |
echo "develop_version=$(python -c 'from ethereum import __version__; print(__version__)')" >> $GITHUB_OUTPUT

version-check:
name: Check Version when opening a PR against develop
runs-on: ubuntu-latest
needs: get-develop-version
steps:
- name: Check Out Code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12.0
- name: Check Version Bump
env:
DEVELOP_VERSION: ${{needs.get-develop-version.outputs.develop_version}}
PYTHONPATH: client/src/ledger_app_clients
run: |
current_version=$(python -c "from ethereum import __version__; print(__version__)")
if [[ "$current_version" == "$DEVELOP_VERSION" ]]; then
echo "Version in __init__.py hasn't been bumped. Please bump the version before merging."
exit 1
fi
- name: Clone
uses: actions/checkout@v3
with:
fetch-depth: 0

packaging:
needs: [lint, mypy]
name: Build, test and deploy the Python package
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_pypi_deployment.yml@v1
with:
package_directory: "client/"
stable_deployment: ${{ github.ref == 'refs/heads/master' }}
check_changelog_version: true
publish: ${{ github.event_name == 'push' }}
secrets:
pypi_token: ${{ github.ref == 'refs/heads/master' && secrets.PYPI_PUBLIC_API_TOKEN || secrets.TEST_PYPI_PUBLIC_API_TOKEN }}
- name: Build Python package
run: |
pip install --upgrade pip build twine
cd client/
python -m build;
python -m twine check dist/*
pip install .;
echo "TAG_VERSION=$(python -c 'from ledger_app_clients.ethereum import __version__; print(__version__)')" >> "$GITHUB_ENV"
- name: Check version against CHANGELOG
if: startsWith(github.ref, 'refs/tags/')
run: |
CHANGELOG_VERSION=$(grep -Po '(?<=## \[)(\d+\.)+[^\]]' client/CHANGELOG.md | head -n 1)
if [ "${{ env.TAG_VERSION }}" == "${CHANGELOG_VERSION}" ];
then
echo 'Package and CHANGELOG versions match!';
exit 0;
else
echo "Tag '${{ env.TAG_VERSION }}' and CHANGELOG '${CHANGELOG_VERSION}' versions mismatch!";
exit 1;
fi
- name: Publish Python package on pypi.org
if: success() && github.event_name == 'push'
run: (cd client && python -m twine upload --verbose dist/*)
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PUBLIC_API_TOKEN }}
TWINE_NON_INTERACTIVE: 1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build/

# Python
*.pyc

__version__.py

# JS
tests/node_modules
Expand Down
6 changes: 6 additions & 0 deletions client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.1] - 2023-12-01

### Fixed

- v0.2.0 version already published on pypi.org

## [0.2.0] - 2023-12-01

### Added
Expand Down
11 changes: 9 additions & 2 deletions client/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ dependencies = [
[tools.setuptools]
include-package-data = true

[tool.setuptools.dynamic]
version = {attr = "ledger_app_clients.ethereum.__version__"}
[tool.setuptools_scm]
version_file = "src/ledger_app_clients/ethereum/__version__.py"
local_scheme = "no-local-version"
root = "../"
git_describe_command = "git describe --dirty --tags --long --match client-*[0-9]*"
fallback_version = "0.0.0"

[project.urls]
Home = "https://github.com/LedgerHQ/app-ethereum"

[tool.mypy]
ignore_missing_imports = true

[tool.flake8]
max-line-length = 120
5 changes: 4 additions & 1 deletion client/src/ledger_app_clients/ethereum/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
__version__ = "0.2.0"
try:
from ledger_app_clients.ethereum.__version__ import __version__ # noqa
except ImportError:
__version__ = "unknown version" # noqa

0 comments on commit df74ace

Please sign in to comment.