diff --git a/.travis.yml b/.travis.yml index fc01da26..b4a1e034 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,26 @@ language: python +# 3.6 is listed first so it gets used for the later build stages python: - - 3.5 - 3.6 + - 3.5 +# Executed for 3.5 AND 3.5 as the first "test" stage: script: - python setup.py test + +# This defines further stages that execute after the tests +jobs: + include: + - stage: deploy latest.datasette.io + script: + - pip install . + - npm install -g now + - python tests/fixtures.py fixtures.db fixtures.json + - echo '{"name":"datasette-latest","alias":"latest.datasette.io"}' > now.json + - datasette publish now fixtures.db -m fixtures.json --token=$NOW_TOKEN --branch=$TRAVIS_COMMIT --version-note=$TRAVIS_COMMIT + - now alias --token=$NOW_TOKEN + - export ALIAS=`echo $TRAVIS_COMMIT | cut -c 1-7` + - echo "{\"name\":\"datasette-latest\",\"alias\":\"$ALIAS.datasette.io\"}" > now.json + - now alias --token=$NOW_TOKEN + on: travis-deploy-now diff --git a/datasette/app.py b/datasette/app.py index 871a4bf1..70f2a93f 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -119,6 +119,7 @@ class Datasette: plugins_dir=None, static_mounts=None, config=None, + version_note=None, ): self.files = files self.cache_headers = cache_headers @@ -131,6 +132,7 @@ class Datasette: self.plugins_dir = plugins_dir self.static_mounts = static_mounts or [] self.config = dict(DEFAULT_CONFIG, **(config or {})) + self.version_note = version_note self.executor = futures.ThreadPoolExecutor( max_workers=self.config["num_sql_threads"] ) @@ -298,12 +300,14 @@ class Datasette: fts_versions.append(fts) except sqlite3.OperationalError: continue - + datasette_version = {"version": __version__} + if self.version_note: + datasette_version["note"] = self.version_note return { "python": { "version": ".".join(map(str, sys.version_info[:3])), "full": sys.version }, - "datasette": {"version": __version__}, + "datasette": datasette_version, "sqlite": { "version": sqlite_version, "fts_versions": fts_versions, diff --git a/datasette/cli.py b/datasette/cli.py index 2f61559a..ebba0244 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -111,6 +111,7 @@ def inspect(files, inspect_file, sqlite_extensions): @click.option("--extra-options", help="Extra options to pass to datasette serve") @click.option("--force", is_flag=True, help="Pass --force option to now") @click.option("--branch", help="Install datasette from a GitHub branch e.g. master") +@click.option("--token", help="Auth token to use for deploy (Now only)") @click.option( "--template-dir", type=click.Path(exists=True, file_okay=False, dir_okay=True), @@ -135,6 +136,7 @@ def inspect(files, inspect_file, sqlite_extensions): @click.option( "--spatialite", is_flag=True, help="Enable SpatialLite extension" ) +@click.option("--version-note", help="Additional note to show on /-/versions") @click.option("--title", help="Title for metadata") @click.option("--license", help="License label for metadata") @click.option("--license_url", help="License URL for metadata") @@ -148,11 +150,13 @@ def publish( extra_options, force, branch, + token, template_dir, plugins_dir, static, install, spatialite, + version_note, **extra_metadata ): """ @@ -198,10 +202,16 @@ def publish( static, install, spatialite, + version_note, extra_metadata, ): + args = [] if force: - call(["now", "--force"]) + args.append("--force") + if token: + args.append("--token={}".format(token)) + if args: + call(["now"] + args) else: call("now") @@ -366,6 +376,7 @@ def skeleton(files, metadata, sqlite_extensions): @click.option( "--spatialite", is_flag=True, help="Enable SpatialLite extension" ) +@click.option("--version-note", help="Additional note to show on /-/versions") @click.option("--title", help="Title for metadata") @click.option("--license", help="License label for metadata") @click.option("--license_url", help="License URL for metadata") @@ -382,6 +393,7 @@ def package( static, install, spatialite, + version_note, **extra_metadata ): "Package specified SQLite files into a new datasette Docker container" @@ -405,6 +417,7 @@ def package( static, install, spatialite, + version_note, extra_metadata, ): args = ["docker", "build"] @@ -471,6 +484,7 @@ def package( help="Set config option using configname:value datasette.readthedocs.io/en/latest/config.html", multiple=True, ) +@click.option("--version-note", help="Additional note to show on /-/versions") @click.option( "--help-config", is_flag=True, @@ -490,6 +504,7 @@ def serve( plugins_dir, static, config, + version_note, help_config, ): """Serve up specified SQLite database files with a web UI""" @@ -531,6 +546,7 @@ def serve( plugins_dir=plugins_dir, static_mounts=static, config=dict(config), + version_note=version_note, ) # Force initial hashing/table counting ds.inspect() diff --git a/datasette/utils.py b/datasette/utils.py index 033f2c22..a179eddf 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -241,7 +241,7 @@ def escape_sqlite(s): return '[{}]'.format(s) -def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, plugins_dir, static, install, spatialite): +def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, plugins_dir, static, install, spatialite, version_note): cmd = ['"datasette"', '"serve"', '"--host"', '"0.0.0.0"'] cmd.append('"' + '", "'.join(files) + '"') cmd.extend(['"--cors"', '"--port"', '"8001"', '"--inspect-file"', '"inspect-data.json"']) @@ -251,6 +251,8 @@ def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, p cmd.extend(['"--template-dir"', '"templates/"']) if plugins_dir: cmd.extend(['"--plugins-dir"', '"plugins/"']) + if version_note: + cmd.extend(['"--version-note"', '"{}"'.format(version_note)]) if static: for mount_point, _ in static: cmd.extend(['"--static"', '"{}:{}"'.format(mount_point, mount_point)]) @@ -293,6 +295,7 @@ def temporary_docker_directory( static, install, spatialite, + version_note, extra_metadata=None ): extra_metadata = extra_metadata or {} @@ -324,6 +327,7 @@ def temporary_docker_directory( static, install, spatialite, + version_note, ) os.chdir(datasette_dir) if metadata_content: diff --git a/tests/test_utils.py b/tests/test_utils.py index d12bf927..e168c3f2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -252,6 +252,7 @@ def test_temporary_docker_directory_uses_hard_link(): static=[], install=[], spatialite=False, + version_note=None, ) as temp_docker: hello = os.path.join(temp_docker, 'hello') assert 'world' == open(hello).read() @@ -278,6 +279,7 @@ def test_temporary_docker_directory_uses_copy_if_hard_link_fails(mock_link): static=[], install=[], spatialite=False, + version_note=None, ) as temp_docker: hello = os.path.join(temp_docker, 'hello') assert 'world' == open(hello).read()