Skip to content

Commit

Permalink
update the publishing process
Browse files Browse the repository at this point in the history
  • Loading branch information
btschwertfeger committed May 7, 2024
1 parent a0ef358 commit 1c87958
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 60 deletions.
34 changes: 27 additions & 7 deletions .github/workflows/_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand Down
48 changes: 13 additions & 35 deletions .github/workflows/_pypi_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,40 @@
# 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

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/
39 changes: 39 additions & 0 deletions .github/workflows/_pypi_test_publish.yaml
Original file line number Diff line number Diff line change
@@ -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/
4 changes: 2 additions & 2 deletions .github/workflows/_test_futures_private.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
##
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_test_futures_public.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
##
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_test_nft_private.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
##
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_test_nft_public.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
##
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_test_spot_private.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
##
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_test_spot_public.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
##
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c87958

Please sign in to comment.