From b5e0c8759bb7ff648e2dd2f41c55843c7db5cf5f Mon Sep 17 00:00:00 2001 From: Lucas PASCAL Date: Fri, 5 Jan 2024 15:48:20 +0100 Subject: [PATCH 1/4] [ci] Eth client Python package only deployed on pypi.org --- .github/workflows/python-client.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-client.yml b/.github/workflows/python-client.yml index af7a0e7..d4bdd4a 100644 --- a/.github/workflows/python-client.yml +++ b/.github/workflows/python-client.yml @@ -86,8 +86,8 @@ jobs: uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_pypi_deployment.yml@v1 with: package_directory: "client/" - stable_deployment: ${{ github.ref == 'refs/heads/master' }} + stable_deployment: true 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 }} + pypi_token: secrets.PYPI_PUBLIC_API_TOKEN From 99ba4a9eed5352f3dcf7342d653e597ea6e57e2d Mon Sep 17 00:00:00 2001 From: Lucas PASCAL Date: Fri, 5 Jan 2024 16:42:58 +0100 Subject: [PATCH 2/4] [ci][client] Eth Python client automatically infer its version from tags --- .github/workflows/python-client.yml | 48 ++----------------- .gitignore | 2 +- client/pyproject.toml | 8 +++- .../ledger_app_clients/ethereum/__init__.py | 5 +- 4 files changed, 14 insertions(+), 49 deletions(-) diff --git a/.github/workflows/python-client.yml b/.github/workflows/python-client.yml index d4bdd4a..3b16e18 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 @@ -36,50 +38,6 @@ jobs: - name: Mypy type checking run: (cd client && mypy src/) - get-develop-version: - name: Get develop version - 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 @@ -87,7 +45,7 @@ jobs: with: package_directory: "client/" stable_deployment: true - check_changelog_version: true + check_changelog_version: ${{ startsWith(github.ref,'refs/tags/') }} publish: ${{ github.event_name == 'push' }} secrets: pypi_token: secrets.PYPI_PUBLIC_API_TOKEN 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/pyproject.toml b/client/pyproject.toml index 9229574..660206b 100644 --- a/client/pyproject.toml +++ b/client/pyproject.toml @@ -34,8 +34,12 @@ 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" 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 From 0836e42ae1022a86f9f3b711e161dd35f7334ee4 Mon Sep 17 00:00:00 2001 From: Lucas PASCAL Date: Tue, 9 Jan 2024 09:30:06 +0100 Subject: [PATCH 3/4] v0.2.1 --- client/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) 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 From 08077ff252eadd47e7561185a5cd1ce4d89557f7 Mon Sep 17 00:00:00 2001 From: Lucas PASCAL Date: Tue, 9 Jan 2024 11:39:45 +0100 Subject: [PATCH 4/4] [ci][fix] Falling back to explicit package build, test & publish rather than using the reusable workflow --- .github/workflows/python-client.yml | 53 ++++++++++++++++++++++------- client/pyproject.toml | 3 ++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.github/workflows/python-client.yml b/.github/workflows/python-client.yml index 3b16e18..248c804 100644 --- a/.github/workflows/python-client.yml +++ b/.github/workflows/python-client.yml @@ -24,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 @@ -38,14 +38,43 @@ jobs: - name: Mypy type checking run: (cd client && mypy src/) - packaging: + package_and_deploy: + name: Build and deploy Ethereum Client Python package + runs-on: ubuntu-latest 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: true - check_changelog_version: ${{ startsWith(github.ref,'refs/tags/') }} - publish: ${{ github.event_name == 'push' }} - secrets: - pypi_token: secrets.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/client/pyproject.toml b/client/pyproject.toml index 660206b..3a91961 100644 --- a/client/pyproject.toml +++ b/client/pyproject.toml @@ -46,3 +46,6 @@ 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