From c3a86c93bfc37a8a5e13c3ed09c40ca28cfa012e Mon Sep 17 00:00:00 2001 From: "S. Andrew Sheppard" Date: Fri, 16 Apr 2021 11:10:41 +0900 Subject: [PATCH] move to github actions and update readme --- .github/workflows/test.yml | 110 ++++++++++++++++++ .travis.yml | 52 --------- README.md | 44 +++---- packages/cra-template/package.json | 6 +- packages/rollup-plugin/package.json | 6 +- .../src/__tests__/fixtures/project/input.js | 4 +- .../src/__tests__/fixtures/project/output.js | 6 +- runtests.sh | 6 - set_dev_version.sh | 9 ++ setup.py | 3 +- tests/expected/config1.json | 7 ++ tests/expected/config2.json | 7 ++ tests/expected/config3.json | 9 +- tests/test-deploy.sh | 25 ++-- 14 files changed, 184 insertions(+), 110 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml delete mode 100755 runtests.sh create mode 100755 set_dev_version.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2150ff3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,110 @@ +name: Tests + +on: [push, pull_request] + +jobs: + create: + name: ${{ matrix.variant }} + runs-on: ubuntu-20.04 + env: + TEST_VARIANT: ${{ matrix.variant }} + strategy: + matrix: + variant: [spatialite, postgis, npm] + python-version: [3.9] + django-version: [3.2] + drf-version: [3.12.4] + steps: + - uses: actions/checkout@v2 + with: + submodules: true + fetch-depth: 0 + - 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 --upgrade pip + python -m pip install flake8 pytest wheel + python -m pip install django==${{ matrix.django-version }} + python -m pip install djangorestframework==${{ matrix.drf-version }} + python -m pip install xlsconv + python -m pip install git+https://github.com/wq/wq.build.git#egg=wq.build + python -m pip install git+https://github.com/wq/wq.app.git#egg=wq.app + python -m pip install git+https://github.com/wq/wq.db.git#egg=wq.db + python -m pip install . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --exclude django_project,tests --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --exclude django_project,tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Set up SpatiaLite + if: ${{ matrix.variant != 'postgis' }} + run: | + sudo apt-get update + sudo apt-get install libsqlite3-mod-spatialite gdal-bin + - name: Set up PostgreSQL + if: ${{ matrix.variant == 'postgis' }} + run: | + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + sudo apt-get update + sudo apt-get install postgresql-13-postgis-3 + # postgresql is already installed on image + sudo systemctl start postgresql.service + sudo -u postgres createuser --superuser $USER + createdb test_project + psql test_project -c "CREATE EXTENSION postgis;" + python -m pip install psycopg2-binary + - name: CLI Tests + run: | + cd tests + ./test-deploy.sh + npm: + name: "@wq/${{ matrix.package }}" + runs-on: ubuntu-20.04 + env: + PACKAGE: ${{ matrix.package }} + strategy: + matrix: + python-version: [3.9] + node-version: [14] + package: + - cra-template + - rollup-plugin + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Node ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + if: ${{ matrix.package != 'cra-template' }} + run: | + cd packages/$PACKAGE + npm ci + - name: Lint with ESLint + if: ${{ matrix.package != 'cra-template' }} + run: | + cd packages/$PACKAGE + npm run lint + - name: Test with Jest + if: ${{ matrix.package != 'cra-template' }} + run: | + cd packages/$PACKAGE + npm run test + - name: Publish to Github Packages + if: ${{ github.event_name == 'push' }} + run: | + ./set_dev_version.sh + cd packages/$PACKAGE + echo "registry=https://npm.pkg.github.com/wq" > .npmrc + echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc + npm publish diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 10c72ab..0000000 --- a/.travis.yml +++ /dev/null @@ -1,52 +0,0 @@ -language: python -python: 3.8 -dist: bionic -env: - global: - - DJANGO="Django==3.1.1" - - DRF="djangorestframework==3.11.1" - - WQ_CORE="wq.core==1.3.0a1" - - WQ_APP="wq.app==1.3.0a1" - - WQ_DB="wq.db==1.3.0a1" - - XLSCONV="xlsconv==1.2.0" -install: - - pip install $DJANGO $DRF $XLSCONV - - pip install $WQ_CORE $WQ_APP $WQ_DB - - pip install . -addons: - apt: - packages: - - libsqlite3-mod-spatialite - - gdal-bin -matrix: - include: - - name: "wq start (Python 3.8, SpatialLite, No NPM)" - - name: "Python 3.7" - python: 3.7 - - name: "Python 3.6" - python: 3.6 - - name: "PostGIS" - env: - - POSTGRES=1 - addons: - postgresql: "10" - apt: - packages: - - postgresql-10-postgis-2.4 - - name: "NPM" - env: - - WITH_NPM=1 - - name: "@wq/rollup-plugin" - install: - - cd packages/rollup-plugin - - npm ci - script: - - npm test - - npm run lint - - name: "Python Lint" - env: - - LINT=1 - install: - - pip install flake8 -script: - - ./runtests.sh diff --git a/README.md b/README.md index 673c031..7d0aa2e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![wq.create](https://raw.github.com/wq/wq/master/images/256/wq.create.png)](https://wq.io/wq.create) +[![wq.create][logo]][docs] -[wq.create](https://wq.io/wq.create) (formerly wq.start) provides a simple command-line interface (`wq create`) for starting a new project with the [wq framework], with [wq.app] for the front end and [wq.db] as the backend. wq.create also provides a `wq addform` command that can generate and configure new Django apps from an [XLSForm](http://xlsform.org) definition. +[**wq.create**][docs] (formerly wq.start) provides a simple command-line interface (`wq create`) for starting a new project with the [wq framework], with [wq.app] for the front end and [wq.db] as the backend. wq.create also provides a `wq addform` command that can generate and configure new Django apps from an [XLSForm] definition. [![Latest PyPI Release](https://img.shields.io/pypi/v/wq.create.svg)](https://pypi.org/project/wq.create) [![Release Notes](https://img.shields.io/github/release/wq/wq.create.svg)](https://github.com/wq/wq.create/releases) @@ -9,37 +9,27 @@ [![GitHub Forks](https://img.shields.io/github/forks/wq/wq.create.svg)](https://github.com/wq/wq.create/network) [![GitHub Issues](https://img.shields.io/github/issues/wq/wq.create.svg)](https://github.com/wq/wq.create/issues) -[![Travis Build Status](https://img.shields.io/travis/wq/wq.create/master.svg)](https://travis-ci.org/wq/wq.create) +[![Tests](https://github.com/wq/wq.create/actions/workflows/test.yml/badge.svg)](https://github.com/wq/wq.create/actions/workflows/test.yml) [![Python Support](https://img.shields.io/pypi/pyversions/wq.create.svg)](https://pypi.org/project/wq.create) [![Django Support](https://img.shields.io/pypi/djversions/wq.create.svg)](https://pypi.org/project/wq.create) -### Usage -```bash -# Recommended: create virtual environment -# python3 -m venv venv -# . venv/bin/activate -python3 -m pip install wq +### [Documentation][docs] -wq create [directory] -cd /db -wq addform ~/my-odk-form.xlsx -``` +[**Getting Started**][setup] +• +[`wq create`][create] +• +[`wq addform`][addform] -See the [Getting Started] docs for more information. - -### Commands - - * `wq create [directory]`: Create a new Django project from the [wq Django template] and (optionally) the [@wq Create React App template][@wq/cra-template] - * `wq addform ~/my-odk-form.xlsx`: Create a new Django app from the provided XLSForm (uses [xlsform-converter]) - * `wq maketemplates`: Create templates for use with [@wq/jquery-mobile][@wq/jquery-mobile] (deprecated) +[logo]: https://wq.io/images/wq.create.svg +[docs]: https://wq.io/wq.create/ +[setup]: https://wq.io/overview/setup +[create]: https://wq.io/wq.create/create +[addform]: https://wq.io/wq.create/addform [wq framework]: https://wq.io/ -[wq.app]: https://wq.io/wq.app -[wq.db]: https://wq.io/wq.db -[wq Django template]: https://github.com/wq/wq-django-template -[@wq/cra-template]: https://github.com/wq/wq.create/tree/master/packages/cra-template -[@wq/jquery-mobile]: https://github.com/wq/wq.app/tree/master/packages/jquery-mobile -[xlsform-converter]: https://github.com/wq/xlsform-converter -[Getting Started]: https://wq.io/docs/setup +[wq.app]: https://wq.io/wq.app/ +[wq.db]: https://wq.io/wq.db/ +[XLSForm]: https://xlsform.org/ diff --git a/packages/cra-template/package.json b/packages/cra-template/package.json index 464d88a..7e83718 100644 --- a/packages/cra-template/package.json +++ b/packages/cra-template/package.json @@ -5,7 +5,7 @@ "main": "template.json", "repository": { "type": "git", - "url": "https://github.com/wq/wq.start.git", + "url": "https://github.com/wq/wq.create.git", "directory": "packages/cra-template" }, "keywords": [ @@ -19,9 +19,9 @@ "author": "S. Andrew Sheppard", "license": "MIT", "bugs": { - "url": "https://github.com/wq/wq.start/issues" + "url": "https://github.com/wq/wq.create/issues" }, - "homepage": "https://wq.io/wq.start", + "homepage": "https://wq.io/@wq/cra-template", "files": [ "template", "template.json" diff --git a/packages/rollup-plugin/package.json b/packages/rollup-plugin/package.json index e7c342f..1d4091d 100644 --- a/packages/rollup-plugin/package.json +++ b/packages/rollup-plugin/package.json @@ -10,7 +10,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/wq/wq.start.git", + "url": "git+https://github.com/wq/wq.create.git", "directory": "packages/rollup-plugin" }, "keywords": [ @@ -24,9 +24,9 @@ "author": "S. Andrew Sheppard", "license": "MIT", "bugs": { - "url": "https://github.com/wq/wq.start/issues" + "url": "https://github.com/wq/wq.create/issues" }, - "homepage": "https://wq.io/wq.start", + "homepage": "https://wq.io/@wq/rollup-plugin", "dependencies": {}, "devDependencies": { "@babel/core": "^7.12.3", diff --git a/packages/rollup-plugin/src/__tests__/fixtures/project/input.js b/packages/rollup-plugin/src/__tests__/fixtures/project/input.js index 68f9643..54c2d36 100644 --- a/packages/rollup-plugin/src/__tests__/fixtures/project/input.js +++ b/packages/rollup-plugin/src/__tests__/fixtures/project/input.js @@ -1,6 +1,6 @@ import app from '@wq/app'; import material from '@wq/material'; -import mapbox from '@wq/mapbox'; +import mapgl from '@wq/map-gl'; import myPlugin from './plugin.js'; -app.use([material, mapbox, myPlugin]); +app.use([material, mapgl, myPlugin]); diff --git a/packages/rollup-plugin/src/__tests__/fixtures/project/output.js b/packages/rollup-plugin/src/__tests__/fixtures/project/output.js index 1430dd8..c79fce0 100644 --- a/packages/rollup-plugin/src/__tests__/fixtures/project/output.js +++ b/packages/rollup-plugin/src/__tests__/fixtures/project/output.js @@ -6,7 +6,7 @@ const { '@wq/app': app } = modules; const { '@wq/material': material } = modules; const materialPlugin = material.default; -const { '@wq/mapbox': mapbox } = modules; -const mapboxPlugin = mapbox.default; +const { '@wq/map-gl': mapgl } = modules; +const mapglPlugin = mapgl.default; -app.use([materialPlugin, mapboxPlugin, myPlugin]); +app.use([materialPlugin, mapglPlugin, myPlugin]); diff --git a/runtests.sh b/runtests.sh deleted file mode 100755 index 47ec81b..0000000 --- a/runtests.sh +++ /dev/null @@ -1,6 +0,0 @@ -set -e -if [ "$LINT" ]; then - flake8 {forms,projects}.py -else - cd tests && ./test-deploy.sh -fi diff --git a/set_dev_version.sh b/set_dev_version.sh new file mode 100755 index 0000000..19bbcfe --- /dev/null +++ b/set_dev_version.sh @@ -0,0 +1,9 @@ +#!/bin/bash +VERSION=`python3 setup.py --version | \ + sed s/\.dev/-dev/ | \ + sed s/+/./ | \ + sed "s/\.d[0-9]\{8\}$//" | \ + sed "s/^\([0-9]\+\.[0-9]\+\.[0-9]\+\)\(.\+\)/\1-\2/" | \ + sed "s/--/-/g"` +sed -i "s/\"version\": .*/\"version\": \"$VERSION\",/" packages/*/package.json +sed -i "s/\"@wq\/\(.\+\)\": \".\+\"/\"@wq\/\1\": \"\^$VERSION\"/" packages/*/package.json diff --git a/setup.py b/setup.py index 6c79514..1dde0ed 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup LONG_DESCRIPTION = """ -Project scaffolding tools for creating a new crowdsourcing or citizen science application with the wq framework. +Project scaffolding tools for creating a new application with the wq framework. """ @@ -41,6 +41,7 @@ def list_package_data(root): ]) return paths + create_wq_namespace() # Project template data diff --git a/tests/expected/config1.json b/tests/expected/config1.json index 6a5ab05..0dc81aa 100644 --- a/tests/expected/config1.json +++ b/tests/expected/config1.json @@ -8,5 +8,12 @@ "name": "logout", "url": "logout" } + }, + "router": { + "base_url": "" + }, + "store": { + "service": "", + "defaults": {"format": "json"} } } diff --git a/tests/expected/config2.json b/tests/expected/config2.json index b018c95..e8d1dc8 100644 --- a/tests/expected/config2.json +++ b/tests/expected/config2.json @@ -89,5 +89,12 @@ "name": "logout", "url": "logout" } + }, + "router": { + "base_url": "" + }, + "store": { + "service": "", + "defaults": {"format": "json"} } } diff --git a/tests/expected/config3.json b/tests/expected/config3.json index 40cbb8d..99d1123 100644 --- a/tests/expected/config3.json +++ b/tests/expected/config3.json @@ -91,7 +91,7 @@ { "hint": "The site where the observation was taken", "name": "location", - "type": "string", + "type": "select one", "wq:ForeignKey": "location", "label": "Site" }, @@ -123,5 +123,12 @@ "name": "logout", "url": "logout" } + }, + "router": { + "base_url": "" + }, + "store": { + "service": "", + "defaults": {"format": "json"} } } diff --git a/tests/test-deploy.sh b/tests/test-deploy.sh index f00626a..57792a4 100755 --- a/tests/test-deploy.sh +++ b/tests/test-deploy.sh @@ -6,29 +6,30 @@ rm -rf test_project rm -rf output mkdir output -if [ "$POSTGRES" ]; then - dropdb -Upostgres test_project --if-exists - createdb -Upostgres test_project - psql -Upostgres test_project -c "CREATE EXTENSION postgis"; - +if [[ "$TEST_VARIANT" == "postgis" ]]; then export DJANGO_SETTINGS_MODULE="test_project.settings.prod" + GIS_FLAG="--with-gis" +elif [[ "$TEST_VARIANT" == "spatialite" ]]; then + GIS_FLAG="--with-gis" +else + # FIXME: Support testing non-gis build + GIS_FLAG="--with-gis" fi; + MANAGE="test_project/db/manage.py" PORT=8000 -# wq start: Create new project +# wq create: Create new project rm -rf test_project -GIS_FLAG="--with-gis" - -if [ "$WITH_NPM" ]; then +if [[ "$TEST_VARIANT" == "npm" ]]; then NPM_FLAG="--with-npm" else NPM_FLAG="--without-npm" fi; -wq start test_project ./test_project -d test.wq.io $NPM_FLAG $GIS_FLAG +wq create test_project ./test_project -d test.wq.io $NPM_FLAG $GIS_FLAG # Verify ./deploy.sh works cd test_project @@ -36,8 +37,8 @@ cd test_project cd ..; # Load db and verify initial config -if [ "$POSTGRES" ]; then - sed -i "s/'USER': 'test_project'/'USER': 'postgres'/" test_project/db/test_project/settings/prod.py +if [[ "$TEST_VARIANT" == "postgis" ]]; then + sed -i "s/'USER': 'test_project'/'USER': '$USER'/" test_project/db/test_project/settings/prod.py sed -i "s/ALLOWED_HOSTS.*/ALLOWED_HOSTS = ['localhost']/" test_project/db/test_project/settings/prod.py fi; $MANAGE migrate