Skip to content

Commit

Permalink
ci: fix ci errors and warnings with latest V 0.3.2 4747e70 (#136)
Browse files Browse the repository at this point in the history
* ci: run `v fmt -w .` to make the CI pass again with latest `V 0.3.2 4747e70`
* fix warnings about uninitialised reference fields, by explicitly setting them to nil by default
* small cleanup, use os.getenv so that test runs can be parametrised more easily without changing the test source
* ci: run tests on each individual PR as well, not just on master. Fix warnings/errors produced by yamllint.
* document how to use TIMES=10 for running vsql/btree_test.v, in docs/testing.rst
* fix `make docs` on Ubuntu 20.04 and `make cli-test` too

Co-authored-by: Elliot Chance <elliotchance@gmail.com>
  • Loading branch information
spytheman and elliotchance authored Feb 12, 2023
1 parent 8af2ddf commit 47b87bf
Show file tree
Hide file tree
Showing 52 changed files with 377 additions and 340 deletions.
179 changes: 94 additions & 85 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,100 @@ on:
paths-ignore:
- '**.md'
- '**.rst'
pull_request:
paths-ignore:
- "**.md"
- "**.rst"

concurrency:
group: ci-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
tests:
name: Tests
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Set up V version latest
uses: nocturlab/setup-vlang-action@v1
with:
v-version: master
id: v
- name: Set up V version latest
uses: nocturlab/setup-vlang-action@v1
with:
id: v
v-version: master

- name: Verify fmt
run: make fmt-verify
- name: Verify fmt
run: make fmt-verify

- name: Verify docs
run: |
pip install sphinx sphinx_rtd_theme
cd docs && python3 -m pip install -r requirements.txt && cd -
make clean-docs docs
git diff --exit-code
- name: Verify docs
run: |
pip install sphinx sphinx_rtd_theme
cd docs && python3 -m pip install -r requirements.txt && cd -
make clean-docs docs
git diff --exit-code
- name: Run SQL and B-tree tests
run: make test
- name: Run SQL and B-tree tests
run: make test

- name: Run examples
run: make examples
- name: Run examples
run: make examples

- name: Run CLI tests
run: make cli-test
- name: Run CLI tests
run: make cli-test

macos-binary:
name: Build for macOS
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up V version latest
uses: nocturlab/setup-vlang-action@v1
with:
v-version: master
id: v

- name: Build macOS binaries
run: |
sed -i -e "s/MISSING_VERSION/${GITHUB_REF##*/} `date +'%F'`/g" cmd/vsql/version.v
make bin/vsql
zip -j vsql-macos.zip bin/vsql
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
vsql-macos.zip
- name: Checkout
uses: actions/checkout@v2

- name: Set up V version latest
uses: nocturlab/setup-vlang-action@v1
with:
id: v
v-version: master


- name: Build macOS binaries
run: |
.github/workflows/set_version.sh
make bin/vsql
zip -j vsql-macos.zip bin/vsql
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
vsql-macos.zip
linux-binary:
name: Build for Linux
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up V version latest
uses: nocturlab/setup-vlang-action@v1
with:
v-version: master
id: v

- name: Build linux binaries
run: |
sed -i -e "s/MISSING_VERSION/${GITHUB_REF##*/} `date +'%F'`/g" cmd/vsql/version.v
make bin/vsql
zip -j vsql-linux.zip bin/vsql
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
vsql-linux.zip
- name: Checkout
uses: actions/checkout@v2

- name: Set up V version latest
uses: nocturlab/setup-vlang-action@v1
with:
id: v
v-version: master

- name: Build linux binaries
run: |
.github/workflows/set_version.sh
make bin/vsql
zip -j vsql-linux.zip bin/vsql
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
vsql-linux.zip
# I know it seems pretty silly that we're using macOS and cross compling for
# Windows. But I couldn't get window-latest to work. If you use windows please
Expand All @@ -98,25 +107,25 @@ jobs:
name: Build for Windows
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up V version latest
uses: nocturlab/setup-vlang-action@v1
with:
v-version: master
id: v

- name: Build Windows binaries
run: |
brew install mingw-w64
v -os windows -prod cmd/vsql
mv cmd/vsql/vsql.exe bin/vsql.exe
zip -j vsql-windows.zip bin/vsql.exe
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
vsql-windows.zip
- name: Checkout
uses: actions/checkout@v2

- name: Set up V version latest
uses: nocturlab/setup-vlang-action@v1
with:
id: v
v-version: master

- name: Build Windows binaries
run: |
brew install mingw-w64
v -os windows -prod cmd/vsql
mv cmd/vsql/vsql.exe bin/vsql.exe
zip -j vsql-windows.zip bin/vsql.exe
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
vsql-windows.zip
2 changes: 2 additions & 0 deletions .github/workflows/set_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sed -i -e "s/MISSING_VERSION/${GITHUB_REF##*/} `date +'%F'`/g" cmd/vsql/version.v
6 changes: 3 additions & 3 deletions cmd/vsql/bench.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ fn register_bench_command(mut cmd cli.Command) {
cmd.add_command(bench_cmd)
}

fn bench_command(cmd cli.Command) ? {
fn bench_command(cmd cli.Command) ! {
print_version()

mut file := cmd.flags.get_string('file') or { '' }
if file == '' {
file = 'bench.vsql'
}

mut conn := vsql.open(':memory:') or { panic('$err') }
mut conn := vsql.open(':memory:') or { panic('${err}') }

mut benchmark := vsql.new_benchmark(conn)
benchmark.start() or { panic('$err') }
benchmark.start() or { panic('${err}') }
}
6 changes: 3 additions & 3 deletions cmd/vsql/cli.v
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn register_cli_command(mut cmd cli.Command) {
cmd.add_command(cli_cmd)
}

fn cli_command(cmd cli.Command) ? {
fn cli_command(cmd cli.Command) ! {
print_version()

mut db := vsql.open(cmd.args[0]) or { return err }
Expand All @@ -32,7 +32,7 @@ fn cli_command(cmd cli.Command) ? {
mut total_rows := 0
for row in result {
for column in result.columns {
print('$column.name: ${row.get_string(column.name)} ')
print('${column.name}: ${row.get_string(column.name)} ')
}
total_rows++
}
Expand All @@ -41,7 +41,7 @@ fn cli_command(cmd cli.Command) ? {
println('')
}

println('$total_rows ${vsql.pluralize(total_rows, 'row')} (${time.ticks() - start} ms)')
println('${total_rows} ${vsql.pluralize(total_rows, 'row')} (${time.ticks() - start} ms)')
}

println('')
Expand Down
4 changes: 2 additions & 2 deletions cmd/vsql/in.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn register_in_command(mut cmd cli.Command) {
cmd.add_command(in_cmd)
}

fn in_command(cmd cli.Command) ? {
fn in_command(cmd cli.Command) ! {
mut db := vsql.open(cmd.args[0]) or { return err }

mut f := os.stdin()
Expand Down Expand Up @@ -69,7 +69,7 @@ fn in_command(cmd cli.Command) ? {
}
}

println('$error_count errors, $stmt_count statements, $timer.elapsed()')
println('${error_count} errors, ${stmt_count} statements, ${timer.elapsed()}')

if error_count > 0 {
exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/vsql/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
cmd.parse(os.args)
}

fn unknown_command(_ cli.Command) ? {
fn unknown_command(_ cli.Command) ! {
println('unknown or missing command, see "vsql help"')
exit(1)
}
10 changes: 5 additions & 5 deletions cmd/vsql/out.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn register_out_command(mut cmd cli.Command) {
cmd.add_command(out_cmd)
}

fn out_command(cmd cli.Command) ? {
fn out_command(cmd cli.Command) ! {
mut db := vsql.open(cmd.args[0]) or { return err }

// To make the output more deterministic the schemas and tables will ordered
Expand All @@ -36,23 +36,23 @@ fn out_command(cmd cli.Command) ? {
// Although, `-create-public-schema` can be used to enable it when
// dealing with other databases.
if schema.name == 'PUBLIC' && cmd.flags.get_bool('create-public-schema') or { false } {
println('$schema\n')
println('${schema}\n')
}

mut tables := db.schema_tables(schema.name) or { return err }

tables.sort(a.name > b.name)

for _, table in tables {
println('$table\n')
println('${table}\n')

for row in db.query('SELECT * FROM $table.name')! {
for row in db.query('SELECT * FROM ${table.name}')! {
mut data := []string{}
for col in table.column_names() {
data << (row.get(col)!).str()
}

println('INSERT INTO $table.name (${table.column_names().join(', ')}) VALUES (${data.join(', ')});')
println('INSERT INTO ${table.name} (${table.column_names().join(', ')}) VALUES (${data.join(', ')});')
}

println('')
Expand Down
2 changes: 1 addition & 1 deletion cmd/vsql/server.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn register_server_command(mut cmd cli.Command) {
cmd.add_command(server_cmd)
}

fn server_command(cmd cli.Command) ? {
fn server_command(cmd cli.Command) ! {
print_version()

mut port := cmd.flags.get_int('port') or { 0 }
Expand Down
4 changes: 2 additions & 2 deletions cmd/vsql/version.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn register_version_command(mut cmd cli.Command) {
cmd.add_command(version_cmd)
}

fn version_command(cmd cli.Command) ? {
fn version_command(cmd cli.Command) ! {
print_version()
}

Expand All @@ -23,6 +23,6 @@ fn print_version() {
if version.contains('MISSING') {
println('no version information available')
} else {
println('vsql $version')
println('vsql ${version}')
}
}
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# use index.rst instead of contents.rst:
master_doc = 'index'
12 changes: 12 additions & 0 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ suite alone with:
make btree-test
Note: by default, btree_test.v will do just one iteration, which is faster,
and ok while developing, but before making a PR or a release, you should use:

.. code-block:: sh
TIMES=10 make btree-test
or even ideally:
.. code-block:: sh
TIMES=100 make btree-test
CLI
^^^

Expand Down
4 changes: 2 additions & 2 deletions examples/error-handling.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn example() ! {

db.query('SELECT * FROM bar') or {
sqlstate := vsql.sqlstate_from_int(err.code())
println('$sqlstate: $err.msg()')
println('${sqlstate}: ${err.msg()}')
// 42P01: no such table: BAR

if err.code() == vsql.sqlstate_to_int('42P01') {
Expand All @@ -22,7 +22,7 @@ fn example() ! {
db.query('SELECT * FROM bar') or {
match err {
vsql.SQLState42P01 { // 42P01 = table not found
println("I knew '$err.table_name' did not exist!")
println("I knew '${err.table_name}' did not exist!")
}
else {
panic(err)
Expand Down
Loading

0 comments on commit 47b87bf

Please sign in to comment.