Skip to content

Commit

Permalink
Merge pull request #68 from keboola/PST-585-pypi-1
Browse files Browse the repository at this point in the history
PST-585 push to pypi in gh actions
  • Loading branch information
pivnicek authored Feb 24, 2023
2 parents e465793 + dd0ea44 commit b53ad71
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 31 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

name: Build test and release

on:
workflow_dispatch:
push:

env:
KBC_TEST_TOKEN: ${{ secrets.KBC_TEST_TOKEN }}
KBC_TEST_API_URL: https://connection.keboola.com
KBC_AZ_TEST_TOKEN: ${{ secrets.KBC_AZ_TEST_TOKEN }}
KBC_AZ_TEST_API_URL: https://connection.north-europe.azure.keboola.com

jobs:
build_and_test:
runs-on: ubuntu-latest
outputs:
is_semantic_tag: ${{steps.tag.outputs.is_semantic_tag}}
steps:
- name: Checkout the repo
uses: actions/checkout@v3
- name: Print Docker version
run: |
docker -v
- name: Docker login
if: env.DOCKERHUB_TOKEN
run: docker login --username "$DOCKERHUB_USER" --password "$DOCKERHUB_TOKEN"
- name: build
run: docker-compose build sapi-python-client
- name: show images
run: docker images
- name: run tests flake8
run: docker-compose run --rm --entrypoint=flake8 sapi-python-client
- name: run tests aws
run: docker-compose run --rm -e KBC_TEST_TOKEN=$KBC_TEST_TOKEN -e KBC_TEST_API_URL=$KBC_TEST_API_URL -e SKIP_ABS_TEST=1 sapi-python-client -m unittest discover
- name: run tests azure
run: docker-compose run --rm -e KBC_TEST_TOKEN=$KBC_AZ_TEST_TOKEN -e KBC_TEST_API_URL=$KBC_AZ_TEST_API_URL sapi-python-client -m unittest discover

- name: Check if tag is semantic
id: tag
run: |
TAG="${GITHUB_REF##*/}"
IS_SEMANTIC_TAG=$(echo "$TAG" | grep -q '^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$' && echo true || echo false)
echo "Tag = '$TAG', is semantic tag = '$IS_SEMANTIC_TAG'"
echo "is_semantic_tag=$IS_SEMANTIC_TAG" >> $GITHUB_OUTPUT
deploy_to_pypi:
needs:
- build_and_test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') && needs.build_and_test.outputs.is_semantic_tag == 'true'
steps:
- name: Checkout the repo
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ FROM python:3.8

WORKDIR /code
COPY . /code/
RUN pip3 install --no-cache-dir flake8 responses
RUN pip3 install --no-cache-dir flake8 responses typing_extensions
RUN python setup.py install
ENTRYPOINT ["python"]
4 changes: 3 additions & 1 deletion kbcstorage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,6 @@ def _delete(self, *args, **kwargs):
except requests.HTTPError:
# Handle different error codes
raise
# Should delete return something on success?

if 'application/json' in r.headers.get('Content-Type', ''):
return r.json()
15 changes: 12 additions & 3 deletions kbcstorage/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
http://docs.keboola.apiary.io/#reference/buckets/
"""
from kbcstorage.base import Endpoint
from kbcstorage.jobs import Jobs


class Buckets(Endpoint):
Expand Down Expand Up @@ -100,7 +101,7 @@ def create(self, name, stage='in', description='', backend=None):

return self._post(self.base_url, data=body)

def delete(self, bucket_id, force=False):
def delete(self, bucket_id, force=False, asynchronous=True):
"""
Delete a bucket referenced by ``bucket_id``.
Expand All @@ -112,12 +113,20 @@ def delete(self, bucket_id, force=False):
bucket_id (str): The id of the bucket to be deleted.
force (bool): If ``True``, deletes the bucket even if it is not
empty. Default ``False``.
asynchronous (bool): if asynchronous then the
"""
# How does the API handle it when force == False and the bucket is non-
# empty?
url = '{}/{}'.format(self.base_url, bucket_id)
params = {'force': force}
self._delete(url, params=params)
params = {'force': force, 'async': asynchronous}
if (asynchronous):
job = self._delete(url, params=params)
jobs = Jobs(self.root_url, self.token)
job = jobs.block_until_completed(job['id'])
if job['status'] == 'error':
raise RuntimeError(job['error']['message'])
else:
self._delete(url, params=params)

def link(self, *args, **kwargs):
"""
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
test_suite='tests',
tests_require=['responses'],
long_description=readme,
long_description_content_type='text/markdown',
license="MIT"
)
1 change: 1 addition & 0 deletions tests/functional/test_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def setUp(self):
except exceptions.HTTPError as e:
if e.response.status_code != 404:
raise

# https://github.com/boto/boto3/issues/454
warnings.simplefilter("ignore", ResourceWarning)

Expand Down
1 change: 0 additions & 1 deletion tests/functional/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class TestFiles(unittest.TestCase):
def setUp(self):

# timeout for files from previous tests to appear
time.sleep(1)
self.files = Files(os.getenv('KBC_TEST_API_URL'),
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def setUp(self):
except exceptions.HTTPError as e:
if e.response.status_code != 404:
raise

# https://github.com/boto/boto3/issues/454
warnings.simplefilter("ignore", ResourceWarning)

Expand Down
4 changes: 2 additions & 2 deletions tests/mocks/test_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def test_delete(self):
responses.add(
responses.Response(
method='DELETE',
url='https://connection.keboola.com/v2/storage/buckets/1',
url='https://connection.keboola.com/v2/storage/buckets/1?force=False&async=False',
json={}
)
)
bucket_id = '1'
deleted_detail = self.buckets.delete(bucket_id)
deleted_detail = self.buckets.delete(bucket_id, asynchronous=False)
assert deleted_detail is None

@responses.activate
Expand Down

0 comments on commit b53ad71

Please sign in to comment.