Repository: bbugyi200/funky (language: python)

Issue:
Migrate from TravisCI to GitHub Actions
See https://github.com/features/actions


Discussion / hints:

Fix patch:
diff --git a/.codecov.yaml b/.codecov.yaml
index f00bf03..c46fd8d 100644
--- a/.codecov.yaml
+++ b/.codecov.yaml
@@ -1,9 +1,9 @@
 codecov:
   notify:
-    require_ci_to_pass: yes
+    require_ci_to_pass: true
 
 ignore:
-    - "tests/*"
+  - "tests/*"
 
 coverage:
   precision: 2
@@ -11,19 +11,19 @@ coverage:
   range: "70...100"
 
   status:
-    project: yes
-    patch: yes
-    changes: no
+    project: true
+    patch: true
+    changes: false
 
 parsers:
   gcov:
     branch_detection:
-      conditional: yes
-      loop: yes
-      method: no
-      macro: no
+      conditional: true
+      loop: true
+      method: false
+      macro: false
 
 comment:
   layout: "header, diff"
   behavior: default
-  require_changes: no
+  require_changes: false
diff --git a/.coveragerc b/.coveragerc
index 3db3821..a677816 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -2,9 +2,6 @@
 source =
     funky
     scripts
-include =
-    scripts/post_install.py
-    scripts/shell/funky.sh
 branch = true
 omit =
     funky/__main__.py
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
new file mode 100644
index 0000000..d76a452
--- /dev/null
+++ b/.github/workflows/publish.yml
@@ -0,0 +1,37 @@
+name: pypi_upload
+on: [push]  # yamllint disable-line rule:truthy
+jobs:
+  build:
+    name: PyPI Upload
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Set up Python
+        uses: actions/setup-python@v2
+      - name: Install pypa/build
+        run: >-
+          python -m
+          pip install
+          build
+          --user
+      - name: Build a binary wheel and a source tarball
+        run: >-
+          python -m
+          build
+          --sdist
+          --wheel
+          --outdir dist/
+      - name: Build wheels
+        run: |
+          python setup.py sdist
+      - name: Publish distribution to Test PyPI
+        uses: pypa/gh-action-pypi-publish@master
+        with:
+          password: ${{ secrets.TEST_PYPI_API_TOKEN }}
+          repository_url: https://test.pypi.org/legacy/
+          skip_existing: true
+      - name: Publish distribution to PyPI
+        if: github.repository == 'bbugyi200/funky' && startsWith(github.ref, 'refs/tags')
+        uses: pypa/gh-action-pypi-publish@master
+        with:
+          password: ${{ secrets.PYPI_API_TOKEN }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 410ee23..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,66 +0,0 @@
-language: python
-
-python:
-    - 3.7
-    - 3.8
-    - 3.9
-
-sudo: required
-
-install: 
-    - pip install -U tox-travis
-    - pip install -r dev-requirements.txt
-    - ./scripts/install-system-dev-deps
-
-script:
-    - ./tests/runtests
-    - ./tests/scripts/shell/test_funky.sh
-
-os: linux
-dist: xenial
-
-addons:
-  apt:
-    packages:
-      - libcurl4-openssl-dev
-      - libelf-dev
-      - libdw-dev
-      - cmake
-
-after_success: |
-    # ---------- Generate Python Coverage Report ----------
-    coverage run --rcfile=.coveragerc ./tests/runtests &&
-    bash <(curl -s https://codecov.io/bash) -cF python &&
-    # ---------- Generate Shell Coverage Report ----------
-    deactivate &&
-    sudo apt-get install python3-setuptools &&
-    sudo apt install python3-pip &&
-    sudo pip3 install -r requirements.txt &&
-    sudo python3 setup.py install &&
-    wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
-    tar xzf master.tar.gz &&
-    cd kcov-master &&
-    mkdir build &&
-    cd build &&
-    cmake .. &&
-    make &&
-    sudo make install &&
-    cd ../.. &&
-    rm -rf kcov-master coverage &&
-    mkdir -p coverage &&
-    kcov coverage ./tests/scripts/shell/test_funky.sh &&
-    bash <(curl -s https://codecov.io/bash) -cF bash
-
-deploy:
-  provider: pypi
-  distributions: sdist
-  user: bbugyi200
-  password:
-    secure: TnVPO3geIfsNxIabWRB0O+VnwNVrDKfh/eCy7qkvNZFSbhrg7g08Z2ZrhebrR7Nw+Tktk+0c98K54hTSpk8f4GRWGlVCTxCRAqrvNHx2UPf5T8CN9PkQ/XXAL+PGlznEBW3wIhG82LfKoPbyIQML6CbeMkZyAF6Ptu8sA1WbrlO6u0x0cASkxcHGVwBI1BcJdFhv/Jl6VT9OgAxQShKNo3M3SI0o68mYDqRT2WmF6CHt0z01GGNz+9/ia7ySEvLZsvtUQIZuSoDhiX3dq0GqgoNf0LZlRN3Xlc/49SjzVxqVNJz3AO5yaJkAaqCeVHOey6rJ+I83SXmuIrCYTeSmgMxapioX5vu881iT5TOly6TcaoW6YqTUQtxwbQ7680O0YV7NlJqny6WcMZ8kfyN1+FGgarQova2S0vuJCd77f/FUVJPkna5TCWO1Ncccm9kVPbvO78lKif+5rGaHFY8xumvEw2DP2u6brsMzEL493PUDqIoaThKu2HjviMuBbNDg11jNHA72JCfrNXwFQF0o3rwZtrm36yNd/6U9Egck1zl1s+V6KHsYrQRh9l5P5gzwosVYV/XwlsDN1pcKRS/gefqQQBSWDBLIHZ/ytWIRL4Z3DQrI7DQQlOtYjs7fyhTrwy2gxkXqmuNRBjgB3QCReRJ90O8G7j2u5Ajq+DLi2CA=
-  edge:
-    source: ssbarnea/dpl
-    branch: master
-  on:
-    tags: true
-    repo: bbugyi200/funky
-    python: 3.8
diff --git a/Makefile b/Makefile
index 7ae04b2..6451ae4 100644
--- a/Makefile
+++ b/Makefile
@@ -27,16 +27,25 @@ clean-test: ## Remove test and coverage artifacts.
 	rm -fr htmlcov/
 	rm -fr .pytest_cache
 
+.PHONY: test
+test: test-python test-shell ## Run all tests.
+
+.PHONY: test
+test-python: check-python ## Run Python tests.
+
+.PHONY: test
+test-shell: check-shell ## Run Shell tests.
+
 .PHONY: check
-check: check-python check-shell ## Run all tests.
+check: check-python check-shell
 
 .PHONY: check-python
-check-python: ## Run Python tests.
+check-python:
 	@printf "\n%s\n" "---------- Running Python Tests ----------"
-	$(PWD)/tests/runtests $(pytest_opts)
+	tox -e py -- -v --cov
 
 .PHONY: check-shell
-check-shell: ## Run Shell tests.
+check-shell:
 	@printf "\n%s\n" "---------- Running Shell Tests ----------"
 	$(PWD)/tests/scripts/shell/test_funky.sh
 
diff --git a/README.md b/README.md
index 020ee87..18f2fb0 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,10 @@
 
 **Funky takes shell functions to the next level by making them easier to define, more flexible, and more interactive.**
 
-[![Build Status](https://travis-ci.org/bbugyi200/funky.svg?branch=master)](https://travis-ci.org/bbugyi200/funky) [![codecov](https://codecov.io/gh/bbugyi200/funky/branch/master/graph/badge.svg)](https://codecov.io/gh/bbugyi200/funky) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
+[![Test Workflow](https://github.com/bbugyi200/funky/actions/workflows/test.yml/badge.svg)](https://github.com/bbugyi200/funky/actions/workflows/test.yml)
+[![Publish Workflow](https://github.com/bbugyi200/funky/actions/workflows/publish.yml/badge.svg)](https://github.com/bbugyi200/funky/actions/workflows/publish.yml)
+[![Coverage](https://codecov.io/gh/bbugyi200/funky/branch/master/graph/badge.svg)](https://codecov.io/gh/bbugyi200/funky)
+[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
 
 ![demo]
 
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..2bd8c46
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,12 @@
+[tox]
+envlist = py{37,38,39}
+
+[testenv]
+skip_install = True
+deps =
+    -r{toxinidir}/dev-requirements.txt
+commands =
+    pip install -e .
+    coverage erase
+    pytest tests --cov {posargs}
+    coverage report


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..542434f
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,43 @@
+name: Test
+on:  # yamllint disable-line rule:truthy
+  push:
+    branches: [master]
+  pull_request:
+jobs:
+  build:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        python-version: ["3.7", "3.8", "3.9"]
+        os: [ubuntu-latest]
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 2
+
+      - name: Set up Python ${{ matrix.python-version }}
+        uses: actions/setup-python@v2
+        with:
+          python-version: ${{ matrix.python-version }}
+
+      - name: Install dependencies
+        run: |
+          python -m pip install -U pip tox
+
+      - name: Unit tests
+        run: |
+          make test-python
+
+      - name: Publish coverage to Coveralls
+        if: matrix.python-version == '3.9'
+        run: |
+          python -m pip install -U coverage
+          bash <(curl -s https://codecov.io/bash) -cF python
+
+      - name: Bash Tests
+        if: matrix.python-version == '3.9'
+        run: |
+          ./scripts/install-system-dev-deps
+          python -m pip install -e .
+          make test-shell
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..5f7fd7f
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,20 @@
+import os
+from pathlib import Path
+from typing import Iterator
+
+from pytest import fixture
+from _pytest.tmpdir import TempPathFactory
+
+
+@fixture
+def xdg_data_home(tmp_path_factory: TempPathFactory) -> Iterator[Path]:
+    result = tmp_path_factory.mktemp("xdg_data")
+    old_data_dir = os.environ.get("XDG_DATA_HOME", None)
+    os.environ["XDG_DATA_HOME"] = str(result)
+
+    yield result
+
+    if old_data_dir:
+        os.environ["XDG_DATA_HOME"] = old_data_dir
+    else:
+        del os.environ["XDG_DATA_HOME"]
diff --git a/tests/scripts/test_post_install.py b/tests/scripts/test_post_install.py
index 7cddf59..b53bf15 100644
--- a/tests/scripts/test_post_install.py
+++ b/tests/scripts/test_post_install.py
@@ -1,26 +1,16 @@
 from collections import namedtuple
 import os
-
-import pytest  # pylint: disable=unused-import
+from pathlib import Path
 
 from scripts import post_install
 
 
-def test_copy_sh_ext__ENVVAR_DEFINED():
-    old_data_dir = os.environ.get("XDG_DATA_HOME", None)
-    os.environ["XDG_DATA_HOME"] = "/tmp"
-
+def test_copy_sh_ext__ENVVAR_DEFINED(xdg_data_home: Path) -> None:
     Install = namedtuple("Install", ["root"])
     install = Install(None)
     post_install._copy_sh_ext(install)  # pylint: disable=protected-access
 
-    assert os.path.exists("/tmp/funky/funky.sh")
-    os.system("rm -rf /tmp/funky")
-
-    if old_data_dir:
-        os.environ["XDG_DATA_HOME"] = old_data_dir
-    else:
-        del os.environ["XDG_DATA_HOME"]
+    assert os.path.exists(f"{xdg_data_home}/funky/funky.sh")
 
 
 def test_copy_sh_ext__ENVVAR_NOT_DEFINED():
@@ -29,6 +19,11 @@ def test_copy_sh_ext__ENVVAR_NOT_DEFINED():
     if "XDG_DATA_HOME" in os.environ:
         del os.environ["XDG_DATA_HOME"]
 
+    delete_user = False
+    if "USER" not in os.environ:
+        delete_user = True
+        os.environ["USER"] = "bryan"
+
     Install = namedtuple("Install", ["root"])
     install = Install("/tmp/")
     post_install._copy_sh_ext(install)  # pylint: disable=protected-access
@@ -40,3 +35,6 @@ def test_copy_sh_ext__ENVVAR_NOT_DEFINED():
 
     if old_data_dir:
         os.environ["XDG_DATA_HOME"] = old_data_dir
+
+    if delete_user:
+        del os.environ["USER"]
diff --git a/tests/utils/test_log.py b/tests/utils/test_log.py
index 295ea70..cb286cb 100644
--- a/tests/utils/test_log.py
+++ b/tests/utils/test_log.py
@@ -1,12 +1,12 @@
 """Tests the funky.utils.log utilities."""
 
-import getpass
 import logging
 import os
+from pathlib import Path
 
 import pytest
 
-import funky.utils.log as log
+from funky.utils import log
 
 
 @pytest.mark.parametrize("debug", [False, True])
@@ -16,11 +16,11 @@ def test_init_logger(debug):
     assert log.logger.isEnabledFor(logging.DEBUG) == debug
 
 
-def test_logfile():
+def test_logfile(xdg_data_home: Path) -> None:
     """Tests that the debugging logfile is working correctly."""
     log.init_logger(debug=True)
     log.logger.debug("TEST")
-    logfile = "/home/{}/.local/share/funky/debug.log".format(getpass.getuser())
+    logfile = f"{xdg_data_home}/funky/debug.log"
     assert os.path.isfile(logfile)
     with open(logfile, "r") as f:
         assert "TEST" in f.read()