diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f7f9a5e --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ + +BUILD="_build/default/lib/gmhive_client" +SCHEMA_OUT=$(BUILD)/priv/gmhc_schema.json + +schema: + ERL_LIBS=_build/default/lib \ + erl -run gmhc_config_schema export $(SCHEMA_OUT) -run init stop + scripts/update_readme_json.sh README.md $(SCHEMA_OUT) + + diff --git a/README.md b/README.md index 49e6202..7df0c93 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,16 @@ server. (For `"testnet"` this will be `"test.gajumining.com"`.) "pattern": "^ak_[1-9A-HJ-NP-Za-km-z]*$", "type": "string" }, + "report": { + "default": "silent", + "description": "Progress reporting", + "enum": [ + "debug", + "progress", + "silent" + ], + "type": "string" + }, "type": { "default": "worker", "description": "monitor mode can be used to see if a pool is alive", @@ -174,7 +184,7 @@ server. (For `"testnet"` this will be `"test.gajumining.com"`.) "properties": { "executable": { "default": "mean29-generic", - "description": "Executable binary of the worker. Can be a fully qualified path, but the software may apply default logic to locate a plain basename.", + "description": "Executable binary of the worker. Can be a fully qualified path, \nbut the software may apply default logic to locate a plain basename.", "type": "string" }, "extra_args": { diff --git a/ebin/gmhive_client.app b/ebin/gmhive_client.app index 7b8902a..ffa31b4 100644 --- a/ebin/gmhive_client.app +++ b/ebin/gmhive_client.app @@ -1,6 +1,6 @@ {application,gmhive_client, [{description,"Gajumaru Hive Client"}, - {vsn,"0.6.2"}, + {vsn,"0.6.3"}, {registered,[]}, {applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise, gmconfig,gmhive_protocol,gmhive_worker]}, diff --git a/rebar.config b/rebar.config index 35abaf3..cbfeeeb 100644 --- a/rebar.config +++ b/rebar.config @@ -5,6 +5,8 @@ {erl_opts, [debug_info]}. {plugins, [rebar3_hex]}. +{post_hooks, [{compile, "make schema"}]}. + {deps, [ {enoise, {git, "https://git.qpq.swiss/QPQ-AG/enoise.git", {ref, "029292817e"}}}, {gmhive_protocol, diff --git a/scripts/update_readme_json.sh b/scripts/update_readme_json.sh new file mode 100755 index 0000000..f015c95 --- /dev/null +++ b/scripts/update_readme_json.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +README="$1" +SCHEMA="$2" + +if [[ ! -f "$README" || ! -f "$SCHEMA" ]]; then + echo "Usage: $0 README.md schema.json" + exit 1 +fi + +tmpfile=$(mktemp) + +awk -v schema_file="$SCHEMA" ' + BEGIN { + in_json_block = 0 + in_schema_section = 0 + } + + /^##[[:space:]]+JSON[[:space:]]+Schema/ { + in_schema_section = 1 + print + next + } + + /^##[[:space:]]+/ && in_schema_section { + # Another section starts, end the schema section + in_schema_section = 0 + } + + in_schema_section && /^```json/ { + print "```json" + while ((getline line < schema_file) > 0) print line + close(schema_file) + in_json_block = 1 + next + } + + in_json_block && /^```$/ { + print "```" + in_json_block = 0 + next + } + + !(in_schema_section && in_json_block) { + print + } +' "$README" > "$tmpfile" + +mv "$tmpfile" "$README" +echo "✅ Updated JSON schema block in $README" diff --git a/src/gmhc_config_schema.erl b/src/gmhc_config_schema.erl index f4d8883..7276efa 100644 --- a/src/gmhc_config_schema.erl +++ b/src/gmhc_config_schema.erl @@ -2,7 +2,8 @@ -vsn("0.6.1"). -export([ schema/0 - , to_json/0 ]). + , to_json/0 + , export/1 ]). -import(gmconfig_schema_helpers, [ str/1 @@ -22,6 +23,17 @@ to_json() -> json:encode(schema()). +export(ToFile) -> + case file:open(ToFile, [write]) of + {ok, Fd} -> + try ok = io:put_chars(Fd, json:format(schema(), #{indent => 4})) + after + file:close(Fd) + end; + {error, _} = Error -> + Error + end. + schema() -> obj(schema_init(), #{ diff --git a/zomp.meta b/zomp.meta index 0aa1e39..e467016 100644 --- a/zomp.meta +++ b/zomp.meta @@ -1,10 +1,10 @@ {name,"gmhive_client"}. {type,app}. {modules,[]}. -{author,"Ulf Wiger, QPQ AG"}. {prefix,"gmhc"}. {desc,"Gajumaru Hive Client"}. -{package_id,{"uwiger","gmhive_client",{0,6,2}}}. +{author,"Ulf Wiger, QPQ AG"}. +{package_id,{"uwiger","gmhive_client",{0,6,3}}}. {deps,[{"uwiger","gmhive_worker",{0,5,1}}, {"uwiger","gmcuckoo",{1,2,4}}, {"otpr","eblake2",{1,0,1}}, diff --git a/zompify.sh b/zompify.sh index 66aca1c..8ce3a4e 100755 --- a/zompify.sh +++ b/zompify.sh @@ -38,5 +38,12 @@ rm "$IGNORE_TEMP" cp "$PWD/zomp.meta" "$DST/" cp "$PWD/Emakefile" "$DST/" +# copy generated schema +SCHEMA="$SRC/priv/gmhc_schema.json" +if [ -e "$SCHEMA" ]; then + mkdir -p "$DST/priv" + cp -a "$SCHEMA" "$DST/priv/$(basename "$SCHEMA")" +fi + # Clean up beam files just in case [ -d "$DST/ebin" ] && find "$DST/ebin" -name '*.beam' -exec rm -f {} + || true