From 6c6fde6dd7edba0ad3ca68636d9647757c8206ad Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 15:19:56 -0400 Subject: [PATCH 1/9] Convert Travis to GHA --- .github/workflow/ci.yaml | 184 +++++++++++++++++++++++++++++++++++++++ .travis.yml | 63 -------------- 2 files changed, 184 insertions(+), 63 deletions(-) create mode 100644 .github/workflow/ci.yaml delete mode 100644 .travis.yml diff --git a/.github/workflow/ci.yaml b/.github/workflow/ci.yaml new file mode 100644 index 00000000..5474625a --- /dev/null +++ b/.github/workflow/ci.yaml @@ -0,0 +1,184 @@ +--- +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@v1" + - name: "Build Container" + run: "poetry run invoke build" + - name: "Run Tests" + run: "poetry run invoke unittest" + 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" \ No newline at end of file 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 From e0426e1c4bebaad2616a8b555060243d3dc556b9 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 15:22:16 -0400 Subject: [PATCH 2/9] Rename dir --- .github/{workflow => workflows}/ci.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/ci.yaml (100%) diff --git a/.github/workflow/ci.yaml b/.github/workflows/ci.yaml similarity index 100% rename from .github/workflow/ci.yaml rename to .github/workflows/ci.yaml From 58687009629d41dceccbb8b8425b64d71b2df08a Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 15:22:46 -0400 Subject: [PATCH 3/9] Rename ci file --- .github/workflows/{ci.yaml => ci.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{ci.yaml => ci.yml} (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflows/ci.yaml rename to .github/workflows/ci.yml From 62b732c621d9ed644fa1e193f7bf9d562ffcfffc Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 15:25:16 -0400 Subject: [PATCH 4/9] add new line --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5474625a..8e31a1c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -181,4 +181,4 @@ jobs: user: "__token__" password: "${{ secrets.PYPI_API_TOKEN }}" needs: - - "unittest" \ No newline at end of file + - "unittest" From a626212072afd79e0447ee4a47f5c5792df1db33 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 15:29:40 -0400 Subject: [PATCH 5/9] Rename build-image to build --- tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 8e758095e7426d5c1cd26475e37c7bbfaa2ed6bf Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 15:38:57 -0400 Subject: [PATCH 6/9] replace unittest with pytest in GHA --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e31a1c5..722acb68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,7 +124,7 @@ jobs: - name: "Build Container" run: "poetry run invoke build" - name: "Run Tests" - run: "poetry run invoke unittest" + run: "poetry run invoke pytest" needs: - "pylint" publish_gh: From 556a3bc75390d6d1fcf92669bfb59fd0d6409a81 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 15:47:30 -0400 Subject: [PATCH 7/9] Run pytest outside of docker --- .github/workflows/ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 722acb68..db77a562 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,10 +121,12 @@ jobs: uses: "actions/checkout@v2" - name: "Setup environment" uses: "networktocode/gh-action-setup-poetry-environment@v1" - - name: "Build Container" - run: "poetry run invoke build" + # - name: "Build Container" + # run: "poetry run invoke build" + - name: "Run poetry Install" + run: "poetry install" - name: "Run Tests" - run: "poetry run invoke pytest" + run: "poetry run invoke pytest --local" needs: - "pylint" publish_gh: From 9a00168e98b5c05adebc8ab996ef8a1ac0405001 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 17:12:53 -0400 Subject: [PATCH 8/9] Update .github/workflows/ci.yml Co-authored-by: Glenn Matthews --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db77a562..d65df699 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,7 +120,9 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v2" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v1" + uses: "networktocode/gh-action-setup-poetry-environment@v2" + with: + python-version: "${{ matrix.python-version }}"``` # - name: "Build Container" # run: "poetry run invoke build" - name: "Run poetry Install" From 28c40321deca7780a862baae7dc549bb3b3d8052 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Fri, 8 Oct 2021 17:15:55 -0400 Subject: [PATCH 9/9] Fix syntax error --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d65df699..0c1dbe5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,9 +122,7 @@ jobs: - name: "Setup environment" uses: "networktocode/gh-action-setup-poetry-environment@v2" with: - python-version: "${{ matrix.python-version }}"``` - # - name: "Build Container" - # run: "poetry run invoke build" + python-version: "${{ matrix.python-version }}" - name: "Run poetry Install" run: "poetry install" - name: "Run Tests"