From 1c87958e3cc44bbbdc8083a83d6d80c7b6a33a21 Mon Sep 17 00:00:00 2001 From: btschwertfeger Date: Tue, 7 May 2024 15:52:48 +0200 Subject: [PATCH 1/3] update the publishing process --- .github/workflows/_build.yaml | 34 +++++++++++--- .github/workflows/_pypi_publish.yaml | 48 ++++++-------------- .github/workflows/_pypi_test_publish.yaml | 39 ++++++++++++++++ .github/workflows/_test_futures_private.yaml | 4 +- .github/workflows/_test_futures_public.yaml | 4 +- .github/workflows/_test_nft_private.yaml | 4 +- .github/workflows/_test_nft_public.yaml | 4 +- .github/workflows/_test_spot_private.yaml | 4 +- .github/workflows/_test_spot_public.yaml | 4 +- .github/workflows/cicd.yaml | 6 +-- Makefile | 2 +- 11 files changed, 93 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/_pypi_test_publish.yaml diff --git a/.github/workflows/_build.yaml b/.github/workflows/_build.yaml index 303f4b78..331fd04b 100644 --- a/.github/workflows/_build.yaml +++ b/.github/workflows/_build.yaml @@ -25,7 +25,9 @@ jobs: runs-on: ${{ inputs.os }} steps: - name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + with: + fetch-depth: 0 # IMPORTANT: otherwise the current tag does not get fetched and the build version gets worse - name: Set up Python ${{ inputs.python-version }} uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 @@ -34,8 +36,8 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install build + python -m pip install --user --upgrade pip + python -m pip install --user build - name: Check git status (not Windows) if: runner.os != 'Windows' @@ -59,19 +61,37 @@ jobs: exit 1 } - - name: Build the package - run: python -m build --outdir . + - name: Build Linux + if: runner.os == 'linux' + run: python -m build + + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + # upload artifacts with the oldest supported version + if: runner.os == 'linux' && inputs.python-version == '3.11' + with: + name: python-package-distributions + path: dist/ + + - name: Build macOS + if: runner.os == 'macOS' + run: python -m build + + - name: Build Windows + if: runner.os == 'Windows' + # put it here to avoid more filtering + run: python -m build -o . - name: Install the package on Linux or MacOS if: runner.os != 'Windows' - run: python -m pip install python_kraken_sdk*.whl + run: python -m pip install --user dist/python_kraken_sdk*.whl - name: Install the package on Windows if: runner.os == 'Windows' run: | try { $WHEEL = Get-ChildItem -Path . -Filter "python_kraken_sdk*.whl" -ErrorAction Stop - python -m pip install $WHEEL + python -m pip install --user $WHEEL } catch { Write-Error "Error: .whl file not found in the current directory." exit 1 diff --git a/.github/workflows/_pypi_publish.yaml b/.github/workflows/_pypi_publish.yaml index 99596105..a304e3ba 100644 --- a/.github/workflows/_pypi_publish.yaml +++ b/.github/workflows/_pypi_publish.yaml @@ -3,18 +3,13 @@ # GitHub: https://github.com/btschwertfeger # # Template workflow to build the project and publish -# the package to PyPI. It can be used to publish on the -# test index and the "live" PyPI index. +# the package to PyPI. # name: PyPI Publish on: workflow_call: - inputs: - REPOSITORY_URL: - type: string - required: true secrets: API_TOKEN: required: true @@ -22,43 +17,26 @@ on: permissions: read-all jobs: - PyPI-Publish: - name: Upload to ${{ inputs.REPOSITORY_URL }} + publish-to-pypi: + name: Publish Python distribution to PyPI runs-on: ubuntu-latest + permissions: id-token: write # IMPORTANT: this permission is mandatory for OIDC publishing - steps: - - name: Checkout repository - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - with: - fetch-depth: 0 # IMPORTANT: otherwise the current tag does not get fetched and the build version gets worse + environment: + name: pypi + url: https://pypi.org/p/python-cmethods - - name: Set up Python 3.11 - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 + steps: + - name: Download all the distributions + uses: actions/download-artifact@v4 with: - python-version: 3.11 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install build - - - name: Check git status - run: | - if [[ -z "$(git status --porcelain)" ]]; then - echo "No changes found." - else - echo "Changes detected. Please commit or discard changes before publishing." - git status --porcelain - exit 1 - fi - - - name: Build the package - run: python -m build . + name: python-package-distributions + path: dist/ - name: Publish package distributions to PyPI (optional - testpypi) uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.API_TOKEN }} - repository-url: ${{ inputs.REPOSITORY_URL }} + repository-url: https://upload.pypi.org/legacy/ diff --git a/.github/workflows/_pypi_test_publish.yaml b/.github/workflows/_pypi_test_publish.yaml new file mode 100644 index 00000000..454f8a66 --- /dev/null +++ b/.github/workflows/_pypi_test_publish.yaml @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2024 Benjamin Thomas Schwertfeger +# GitHub: https://github.com/btschwertfeger +# +# Template workflow to build the project and publish +# the package to test PyPI. +# + +name: PyPI Publish + +on: + workflow_call: + secrets: + API_TOKEN: + required: true + +permissions: read-all + +jobs: + publish-to-test-pypi: + name: Publish Python distribution to PyPI + runs-on: ubuntu-latest + permissions: + id-token: write # IMPORTANT: this permission is mandatory for OIDC publishing + environment: + name: testpypi + url: https://test.pypi.org/p/python-cmethods + steps: + - name: Download all the distributions + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + + - name: Publish package distributions to PyPI (optional - testpypi) + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.API_TOKEN }} + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/_test_futures_private.yaml b/.github/workflows/_test_futures_private.yaml index 739f7e5d..4c8e771a 100644 --- a/.github/workflows/_test_futures_private.yaml +++ b/.github/workflows/_test_futures_private.yaml @@ -47,10 +47,10 @@ jobs: - name: Update Pip run: | - python -m pip install --upgrade pip + python -m pip install --user --upgrade pip - name: Install package - run: python -m pip install ".[test]" + run: python -m pip install --user ".[test]" ## Unit tests of the private Futures REST clients and endpoints ## diff --git a/.github/workflows/_test_futures_public.yaml b/.github/workflows/_test_futures_public.yaml index 2d1bb239..cd403159 100644 --- a/.github/workflows/_test_futures_public.yaml +++ b/.github/workflows/_test_futures_public.yaml @@ -37,10 +37,10 @@ jobs: - name: Update Pip run: | - python -m pip install --upgrade pip + python -m pip install --user --upgrade pip - name: Install package - run: python -m pip install ".[test]" + run: python -m pip install --user ".[test]" ## Unit tests of the public Futures REST clients and endpoints ## diff --git a/.github/workflows/_test_nft_private.yaml b/.github/workflows/_test_nft_private.yaml index 4a47d10f..63a33412 100644 --- a/.github/workflows/_test_nft_private.yaml +++ b/.github/workflows/_test_nft_private.yaml @@ -39,10 +39,10 @@ jobs: - name: Update Pip run: | - python -m pip install --upgrade pip + python -m pip install --user --upgrade pip - name: Install package - run: python -m pip install ".[test]" + run: python -m pip install --user ".[test]" ## Unit tests of private Spot NFT clients and endpoints ## diff --git a/.github/workflows/_test_nft_public.yaml b/.github/workflows/_test_nft_public.yaml index d0866fe8..f3251c73 100644 --- a/.github/workflows/_test_nft_public.yaml +++ b/.github/workflows/_test_nft_public.yaml @@ -35,10 +35,10 @@ jobs: - name: Update Pip run: | - python -m pip install --upgrade pip + python -m pip install --user --upgrade pip - name: Install package - run: python -m pip install ".[test]" + run: python -m pip install --user ".[test]" ## Unit tests of the public Spot NFT clients and endpoints ## diff --git a/.github/workflows/_test_spot_private.yaml b/.github/workflows/_test_spot_private.yaml index 6bfbb66e..8cc77ae7 100644 --- a/.github/workflows/_test_spot_private.yaml +++ b/.github/workflows/_test_spot_private.yaml @@ -44,10 +44,10 @@ jobs: - name: Update Pip run: | - python -m pip install --upgrade pip + python -m pip install --user --upgrade pip - name: Install package - run: python -m pip install ".[test]" + run: python -m pip install --user ".[test]" ## Unit tests of private Spot REST clients and endpoints ## diff --git a/.github/workflows/_test_spot_public.yaml b/.github/workflows/_test_spot_public.yaml index 881fac73..6f4dc6a2 100644 --- a/.github/workflows/_test_spot_public.yaml +++ b/.github/workflows/_test_spot_public.yaml @@ -37,10 +37,10 @@ jobs: - name: Update Pip run: | - python -m pip install --upgrade pip + python -m pip install --user --upgrade pip - name: Install package - run: python -m pip install ".[test]" + run: python -m pip install --user ".[test]" ## Unit tests of the public Spot REST clients and endpoints ## diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 67d10c73..ca1b2a44 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -230,9 +230,7 @@ jobs: - CodeQL - CodeCov name: Upload development version to Test PyPI - uses: ./.github/workflows/_pypi_publish.yaml - with: - REPOSITORY_URL: https://test.pypi.org/legacy/ + uses: ./.github/workflows/_pypi_test_publish.yaml secrets: API_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }} @@ -251,7 +249,5 @@ jobs: - CodeCov name: Upload release to PyPI uses: ./.github/workflows/_pypi_publish.yaml - with: - REPOSITORY_URL: https://upload.pypi.org/legacy/ secrets: API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} diff --git a/Makefile b/Makefile index d40b8601..8cc1600e 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ # GitHub: https://github.com/btschwertfeger # -PYTHON := venv/bin/python +PYTHON := python PYTEST := $(PYTHON) -m pytest PYTEST_OPTS := -vv --junit-xml=pytest.xml PYTEST_COV_OPTS := $(PYTEST_OPTS) --cov --cov-report=xml:coverage.xml --cov-report=term From 37d5fbcc9a2957673ed0faa4dd92b484776c3182 Mon Sep 17 00:00:00 2001 From: btschwertfeger Date: Wed, 15 May 2024 20:34:37 +0200 Subject: [PATCH 2/3] fix the failing tests --- kraken/nft/trade.py | 4 ++++ tests/nft/test_nft_trade.py | 24 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/kraken/nft/trade.py b/kraken/nft/trade.py index d22e862e..0ac608a1 100644 --- a/kraken/nft/trade.py +++ b/kraken/nft/trade.py @@ -136,6 +136,8 @@ def modify_auction( """ Modify an existing auction owned by the user + - https://docs.kraken.com/rest/#tag/NFT-Trading/operation/modifyAuction + :param auction_id: ID referencing the auction :type auction_id: str :param ask_price: New ask price (only for fixed price auction type), @@ -183,6 +185,8 @@ def cancel_auction( """ Cancel an existing auction owned by the user + - https://docs.kraken.com/rest/#tag/NFT-Trading/operation/cancelAuction + :param auction_id: IDs referencing the auctions to cancel :type auction_id: list[str] :param otp: One time password, defaults to None diff --git a/tests/nft/test_nft_trade.py b/tests/nft/test_nft_trade.py index 998cc2bc..9d0c4eff 100644 --- a/tests/nft/test_nft_trade.py +++ b/tests/nft/test_nft_trade.py @@ -16,7 +16,6 @@ from datetime import datetime, timedelta from kraken.exceptions import ( - KrakenAuctionNotOwnedByUserError, KrakenInvalidArgumentBelowMinError, KrakenInvalidArgumentOfferNotFoundError, KrakenNFTNotAvailableError, @@ -59,15 +58,24 @@ def test_nft_trade_create_auction(nft_auth_trade: Trade) -> None: @pytest.mark.nft_auth() @pytest.mark.nft_trade() def test_nft_trade_modify_auction(nft_auth_trade: Trade) -> None: - """Checks the ``modify_auction`` endpoint.""" + """ + Checks the ``modify_auction`` endpoint. + It is sufficient here to check that the request is valid, even if the + auction is not valid. + """ - with pytest.raises(KrakenAuctionNotOwnedByUserError): - nft_auth_trade.modify_auction( - auction_id="AT2POJ-4CH3O-4TH6JH", - ask_price="0.3", - ) + response = nft_auth_trade.modify_auction( + auction_id="AT2POJ-4CH3O-4TH6JH", + ask_price="0.3", + ) + assert isinstance(response, dict) + assert response.get( + "error", + [], + ) == ["EAPI:Invalid arguments:No auction with the provided ID"] +@pytest.mark.wip() @pytest.mark.nft() @pytest.mark.nft_auth() @pytest.mark.nft_trade() @@ -83,7 +91,7 @@ def test_nft_trade_cancel_auction(nft_auth_trade: Trade) -> None: assert isinstance(result["statuses"][0], dict) assert result["statuses"][0].get("id") == "AT2POJ-4CH3O-4TH6JH" assert result["statuses"][0].get("status") == "failed" - assert result["statuses"][0].get("reason") == "no permission" + assert result["statuses"][0].get("reason") == "not found" @pytest.mark.nft() From 08fbb5e979ff1bec912be8bd1806953183b22048 Mon Sep 17 00:00:00 2001 From: btschwertfeger Date: Wed, 15 May 2024 20:35:01 +0200 Subject: [PATCH 3/3] add dependabot automerge workflow --- .../workflows/dependabot_auto_approve.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/dependabot_auto_approve.yaml diff --git a/.github/workflows/dependabot_auto_approve.yaml b/.github/workflows/dependabot_auto_approve.yaml new file mode 100644 index 00000000..d550d546 --- /dev/null +++ b/.github/workflows/dependabot_auto_approve.yaml @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2024 Benjamin Thomas Schwertfeger +# GitHub: https://github.com/btschwertfeger +# +# Workflow that approves and merges all pull requests from the dependabot[bot] +# author. +# +# Source (May, 2024): +# - https://blog.somewhatabstract.com/2021/10/11/setting-up-dependabot-with-github-actions-to-approve-and-merge/ + +name: Dependabot auto-merge +on: pull_request_target + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + - name: Dependabot metadata + id: dependabot-metadata + uses: dependabot/fetch-metadata@v1.1.1 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + - name: Approve a PR + run: gh pr review --approve "$PR_URL" + env: + PR_URL: ${{ github.event.pull_request.html_url }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Enable auto-merge for Dependabot PRs + if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }} + run: gh pr merge --auto --squash "$PR_URL" + env: + PR_URL: ${{ github.event.pull_request.html_url }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}