diff --git a/.github/workflows/python-client.yml b/.github/workflows/python-client.yml index af7a0e7..248c804 100644 --- a/.github/workflows/python-client.yml +++ b/.github/workflows/python-client.yml @@ -4,6 +4,8 @@ name: Python client checks, package build and deployment on: workflow_dispatch: push: + tags: + - 'client-*' branches: - develop - master @@ -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 @@ -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 }} - 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 - - 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 }} + steps: + + - name: Clone + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - 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 diff --git a/.gitignore b/.gitignore index 6779287..49c5a99 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ build/ # Python *.pyc - +__version__.py # JS tests/node_modules diff --git a/client/CHANGELOG.md b/client/CHANGELOG.md index 278db68..5aae46a 100644 --- a/client/CHANGELOG.md +++ b/client/CHANGELOG.md @@ -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 diff --git a/client/pyproject.toml b/client/pyproject.toml index 9229574..3a91961 100644 --- a/client/pyproject.toml +++ b/client/pyproject.toml @@ -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 \ No newline at end of file diff --git a/client/src/ledger_app_clients/ethereum/__init__.py b/client/src/ledger_app_clients/ethereum/__init__.py index d3ec452..ce05207 100644 --- a/client/src/ledger_app_clients/ethereum/__init__.py +++ b/client/src/ledger_app_clients/ethereum/__init__.py @@ -1 +1,4 @@ -__version__ = "0.2.0" +try: + from ledger_app_clients.ethereum.__version__ import __version__ # noqa +except ImportError: + __version__ = "unknown version" # noqa