diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ddbd2e..43980f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,33 +1,80 @@ -# This is a basic workflow to help you get started with Actions - name: CI - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch on: push: - branches: [ master ] + branches: + - master + tags: + - v* pull_request: - branches: [ master ] -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest + tox: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + python-version: [3.6, 3.7, 3.8] + os: [macOS-latest, ubuntu-latest, windows-latest] - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - # Runs a single command using the runners shell - - name: Run a one-line script - run: echo Hello, world! + - name: Set Up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} - # Runs a set of commands using the runners shell - - name: Run a multi-line script + - name: Get pip cache dir + id: pip-cache run: | - echo Add other actions to build, - echo test, and deploy your project. + echo "::set-output name=dir::$(pip cache dir)" + + - name: pip cache + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: + ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml', 'setup.py', + 'setup.cfg') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install + run: | + pip install tox + + - name: tox + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: tox -e py,lint,coveralls,release + + - name: upload dist + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.os }}_${{ matrix.python-version}}_dist + path: dist + + all-successful: + # https://github.community/t/is-it-possible-to-require-all-github-actions-tasks-to-pass-without-enumerating-them/117957/4?u=graingert + runs-on: ubuntu-latest + needs: [tox] + steps: + - name: Download dists for PyPI + uses: actions/download-artifact@v2 + with: + name: ubuntu-latest_3.8_dist + path: dist + + - name: Display structure of donwloaded files + run: ls -R + + - name: Publish package + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.pypi_password }} + + - name: note that all tests succeeded + run: echo "🎉" diff --git a/django_js_reverse/tests/requirements.txt b/django_js_reverse/tests/requirements.txt index 10aa9e2..f4d34e4 100644 --- a/django_js_reverse/tests/requirements.txt +++ b/django_js_reverse/tests/requirements.txt @@ -8,7 +8,7 @@ pluggy==0.9.0 py==1.8.0 pycodestyle==2.5.0 pyflakes==2.1.1 -six==1.12.0 +six==1.15.0 toml==0.10.0 tox==3.9.0 virtualenv==16.5.0 diff --git a/django_js_reverse/tests/unit_tests.py b/django_js_reverse/tests/unit_tests.py index 41aea08..be2a074 100755 --- a/django_js_reverse/tests/unit_tests.py +++ b/django_js_reverse/tests/unit_tests.py @@ -9,7 +9,11 @@ import subprocess import sys import unittest +import tempfile +import contextlib +import shutil +import six import django from django.conf import settings from django.core.exceptions import ImproperlyConfigured @@ -28,11 +32,20 @@ from django.test.utils import override_settings # noqa: E402 isort:skip +@contextlib.contextmanager +def mkdtemp(*args, **kwargs): + v = tempfile.mkdtemp(*args, **kwargs) + try: + yield v + finally: + shutil.rmtree(v) + + def node_jseval(expr): module = 'console.log({});'.format(expr) stdout = ( subprocess - .check_output(['node', '-e', module.encode('utf8')]) + .check_output(['node', '-e', six.ensure_str(module)]) .decode('utf8') ) return re.sub(r'\n$', '', stdout) @@ -263,12 +276,11 @@ def test_reverse_js_file_save(self): call_command('collectstatic_js_reverse') def test_reverse_js_file_save_with_output_path_option(self): - js_output_path = os.path.join(os.path.dirname(__file__), 'tmp', 'some_path') - with override_settings(JS_REVERSE_OUTPUT_PATH=js_output_path): + with mkdtemp(__name__) as js_output_path, override_settings(JS_REVERSE_OUTPUT_PATH=js_output_path): call_command('collectstatic_js_reverse') - f = io.open(os.path.join(js_output_path, 'reverse.js')) - content1 = f.read() + with io.open(os.path.join(js_output_path, 'reverse.js')) as f: + content1 = f.read() r2 = self.client.get('/jsreverse/') content2 = r2.content.decode() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..bd0d1f1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = [ "setuptools >= 35.0.2", "wheel >= 0.29.0"] +build-backend = "setuptools.build_meta" diff --git a/tox.ini b/tox.ini index 10b4cd4..696a8c0 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = py{27}-django{111,110,19,18,17,16,15}, py34-django{20,111,110,19,18,17,16,15}, py{35,36,37}-django{22,21,20,111,110,19,18}, - check, + lint, prepare_npm [testenv] @@ -12,7 +12,7 @@ pip_pre = true commands = coverage run -p django_js_reverse/tests/unit_tests.py deps= coverage==4.5.1 - js2py==0.63 + js2py==0.70 django15: Django>=1.5,<1.6 django16: Django>=1.6,<1.7 django17: Django>=1.7,<1.8 @@ -25,13 +25,25 @@ deps= django22: Django>=2.2,<2.23 -[testenv:prepare_npm] -commands = python -m prepare_npm +[testenv:coveralls] +passenv = GITHUB_* deps = - django~=2.2.4 + coveralls + coverage>=5.3 +commands = coveralls +[testenv:release] +deps = + pep517 + django~=2.2.4 +whitelist_externals = + rm +commands = + rm -rf {toxinidir}/dist + python -m prepare_npm + {envpython} -m pep517.build --binary --source --out-dir={toxinidir}/dist {toxinidir} -[testenv:check] +[testenv:lint] commands = ./setup.py check --restructuredtext --strict --metadata deps = docutils==0.14