From 8dc5fc111601321c96193aa5d11fbc9ac40e78c6 Mon Sep 17 00:00:00 2001 From: Zaccharie Ramzi Date: Fri, 23 Jul 2021 18:25:39 +0200 Subject: [PATCH] adds automatic publishing and github CI (#8) * removed travis CI * removed travis badge from readme * added github workflows for testing and publishing * added a script for package building * made sure setup py uses a placeholder for the version --- .github/workflows/publish.yml | 42 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 30 +++++++++++++++++++++++++ .travis.yml | 7 ------ README.md | 2 +- build_package.sh | 10 +++++++++ setup.py | 4 ++-- 6 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml create mode 100644 build_package.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b947bac --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,42 @@ +# This workflows will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries +# from https://github.com/grst/python-ci-versioneer/blob/master/.github/workflows/python-publish.yml +name: Upload Python Package + +on: + release: + types: [published] +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + - name: Autobump version + run: | + # from refs/tags/v1.2.3 get 1.2.3 + VERSION=$(echo $GITHUB_REF | sed 's#.*/v##') + PLACEHOLDER='__version__ = "develop"' + VERSION_FILE='setup.py' + + # ensure the placeholder is there. If grep doesn't find the placeholder + # it exits with exit code 1 and github actions aborts the build. + grep "$PLACEHOLDER" "$VERSION_FILE" + sed -i "s/$PLACEHOLDER/__version__ = \"${VERSION}\"/g" "$VERSION_FILE" + shell: bash + - name: Build and publish to testpypi + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} + run: | + sh build_package.sh + - name: Publish to pypi + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + twine upload dist/* \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..57796a8 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +# This workflow will install Python dependencies, run tests with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions +name: Continuous testing + +on: + push: + branches: + - 'master' + + pull_request: + branches: + - 'master' + +jobs: + test: + name: Test Code + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + pip install . + - name: Test with pytest + run: pytest tf_slice_assign_test.py diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bb3049c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: python -install: - - pip install pytest numpy - - pip install tensorflow - -script: - - pytest tf_slice_assign_test.py diff --git a/README.md b/README.md index 9695023..36e0c24 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # tf-slice-assign -[![Build Status](https://travis-ci.com/zaccharieramzi/tf-slice-assign.svg?token=wHL4tmyGD3TP6bSo6Mdh&branch=master)](https://travis-ci.com/zaccharieramzi/tf-slice-assign) +![GitHub Workflow Build Status](https://github.com/zaccharieramzi/tf-slice-assign/workflows/Continuous%20testing/badge.svg) A tool for assignment to a slice in TensorFlow. diff --git a/build_package.sh b/build_package.sh new file mode 100644 index 0000000..4e1af31 --- /dev/null +++ b/build_package.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +rm -f -r build/* +rm -f -r dist/* + +python -m pip install --upgrade pip +pip install --upgrade setuptools wheel twine + +python setup.py sdist bdist_wheel +twine upload --repository-url https://test.pypi.org/legacy/ dist/* diff --git a/setup.py b/setup.py index c472567..183430d 100644 --- a/setup.py +++ b/setup.py @@ -28,11 +28,11 @@ def load_requirements(path_dir=HERE, comment_char='#'): reqs.append(ln) return reqs - +__version__ = "develop" # https://packaging.python.org/discussions/install-requires-vs-requirements setup( name='tf-slice-assign', - version='0.0.1', + version=__version__, description='A package to perform slice assignment in TensorFlow', author='Zaccharie Ramzi', author_email='zaccharie.ramzi@gmail.com',