diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..0c1dbe5f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,186 @@ +--- +name: "CI" +on: + - "push" + - "pull_request" +jobs: + black: + runs-on: "ubuntu-20.04" + env: + INVOKE_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v1" + - name: "Linting: black" + run: "poetry run invoke black" + bandit: + runs-on: "ubuntu-20.04" + env: + INVOKE_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v1" + - name: "Linting: bandit" + run: "poetry run invoke bandit" + needs: + - "black" + pydocstyle: + runs-on: "ubuntu-20.04" + env: + INVOKE_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v1" + - name: "Linting: pydocstyle" + run: "poetry run invoke pydocstyle" + needs: + - "black" + flake8: + runs-on: "ubuntu-20.04" + env: + INVOKE_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v1" + - name: "Linting: flake8" + run: "poetry run invoke flake8" + needs: + - "black" + mypy: + runs-on: "ubuntu-20.04" + env: + INVOKE_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v1" + - name: "Linting: flake8" + run: "poetry run invoke mypy" + needs: + - "black" + yamllint: + runs-on: "ubuntu-20.04" + env: + INVOKE_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v1" + - name: "Linting: yamllint" + run: "poetry run invoke yamllint" + needs: + - "black" + build: + runs-on: "ubuntu-20.04" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v1" + - name: "Build Container" + run: "poetry run invoke build" + needs: + - "bandit" + - "pydocstyle" + - "flake8" + - "yamllint" + - "mypy" + pylint: + runs-on: "ubuntu-20.04" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v1" + - name: "Build Container" + run: "poetry run invoke build" + - name: "Linting: Pylint" + run: "poetry run invoke pylint" + needs: + - "build" + unittest: + strategy: + fail-fast: true + matrix: + python-version: ["3.6", "3.7", "3.8", "3.9"] + runs-on: "ubuntu-20.04" + env: + PYTHON_VER: "${{ matrix.python-version }}" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v2" + with: + python-version: "${{ matrix.python-version }}" + - name: "Run poetry Install" + run: "poetry install" + - name: "Run Tests" + run: "poetry run invoke pytest --local" + needs: + - "pylint" + publish_gh: + name: "Publish to GitHub" + runs-on: "ubuntu-20.04" + if: "startsWith(github.ref, 'refs/tags/v')" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Set up Python" + uses: "actions/setup-python@v2" + with: + python-version: "3.9" + - name: "Install Python Packages" + run: "pip install poetry" + - name: "Set env" + run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV" + - name: "Run Poetry Version" + run: "poetry version $RELEASE_VERSION" + - name: "Run Poetry Build" + run: "poetry build" + - name: "Upload binaries to release" + uses: "svenstaro/upload-release-action@v2" + with: + repo_token: "${{ secrets.NTC_GITHUB_TOKEN }}" + file: "dist/*" + tag: "${{ github.ref }}" + overwrite: true + file_glob: true + needs: + - "unittest" + publish_pypi: + name: "Push Package to PyPI" + runs-on: "ubuntu-20.04" + if: "startsWith(github.ref, 'refs/tags/v')" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v2" + - name: "Set up Python" + uses: "actions/setup-python@v2" + with: + python-version: "3.9" + - name: "Install Python Packages" + run: "pip install poetry" + - name: "Set env" + run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV" + - name: "Run Poetry Version" + run: "poetry version $RELEASE_VERSION" + - name: "Run Poetry Build" + run: "poetry build" + - name: "Push to PyPI" + uses: "pypa/gh-action-pypi-publish@release/v1" + with: + user: "__token__" + password: "${{ secrets.PYPI_API_TOKEN }}" + needs: + - "unittest" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e5ff4ba9..00000000 --- a/.travis.yml +++ /dev/null @@ -1,63 +0,0 @@ ---- -# Add additional stages in the order of execution here, and then under the job:include: key -dist: "focal" # Ubuntu 20.04 -stages: - - name: "lint" - - name: "build" - - name: "test" - - name: "deploy" - if: "branch = master" - -language: "python" -python: - - 3.6 - - 3.7 - - 3.8 - - 3.9 - -services: - - "docker" - -# Script & Before Script for test stage -before_script: - - "pip install invoke poetry toml" - - "poetry install" -script: - - "invoke pytest --local" - -jobs: - include: - - stage: "lint" - env: - - "INVOKE_LOCAL=True" - before_script: - - "pip install invoke poetry toml" - - "poetry install --no-interaction --no-ansi --no-root" - script: - - "invoke black" - - "invoke bandit" # Bandit fails to function on > Py3.8 https://github.com/PyCQA/bandit/issues/639 - - "invoke pydocstyle" - - "invoke mypy" - - "invoke flake8" - - "invoke yamllint" - - "invoke pylint" - python: 3.7 - - - stage: "build" - before_script: - - "pip install invoke poetry toml" - script: - - "invoke build-image --nocache" - - "poetry build" - python: 3.7 - - - stage: "deploy" - script: "skip" - deploy: - provider: "script" - script: "poetry config pypi-token.pypi $PYPI_TOKEN && poetry publish --build" - skip_cleanup: true - "on": - tags: true - branch: "master" - python: 3.7 diff --git a/tasks.py b/tasks.py index fc138b10..e10027bf 100644 --- a/tasks.py +++ b/tasks.py @@ -82,7 +82,7 @@ def run_cmd(context, exec_cmd, name=NAME, image_ver=IMAGE_VER, local=INVOKE_LOCA @task -def build_image( +def build( context, name=NAME, python_ver=PYTHON_VER, image_ver=IMAGE_VER, nocache=False, forcerm=False ): # pylint: disable=too-many-arguments """This will build an image with the provided name and python version. @@ -123,7 +123,7 @@ def clean_image(context, name=NAME, image_ver=IMAGE_VER): @task -def rebuild_image(context, name=NAME, python_ver=PYTHON_VER, image_ver=IMAGE_VER): +def rebuild(context, name=NAME, python_ver=PYTHON_VER, image_ver=IMAGE_VER): """This will clean the image and then rebuild image without using cache. Args: @@ -133,7 +133,7 @@ def rebuild_image(context, name=NAME, python_ver=PYTHON_VER, image_ver=IMAGE_VER image_ver (str): Define image version """ clean_image(context, name, image_ver) - build_image(context, name, python_ver, image_ver) + build(context, name, python_ver, image_ver) @task