Skip to content

Commit

Permalink
Merge pull request #98 from graingert/github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored Oct 1, 2020
2 parents 372992f + d1fd56e commit 44c1d1e
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 34 deletions.
91 changes: 69 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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.jparrowsec.cnmunity/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 "🎉"
2 changes: 1 addition & 1 deletion django_js_reverse/tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 17 additions & 5 deletions django_js_reverse/tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = [ "setuptools >= 35.0.2", "wheel >= 0.29.0"]
build-backend = "setuptools.build_meta"
24 changes: 18 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 44c1d1e

Please sign in to comment.