stop using cargo pkg version

One fewer thing to manage at release time.
This commit is contained in:
Scott Lamb 2023-10-17 09:36:32 -07:00
parent ef62ebfc6c
commit a76483a912
11 changed files with 90 additions and 42 deletions

View File

@ -25,7 +25,7 @@ If applicable, add screenshots to help explain your problem.
**Server (please complete the following information):** **Server (please complete the following information):**
- If using Docker: `docker ps` + `docker images` - If using Docker: `docker ps` + `docker images`
- If building from git: `git describe --dirty` + `moonfire-nvr --version` - If building from git: `moonfire-nvr --version`
- Attach a [log file](https://github.com/scottlamb/moonfire-nvr/blob/master/guide/troubleshooting.md#viewing-moonfire-nvrs-logs). Run with the `RUST_BACKTRACE=1` environment variable set if possible. - Attach a [log file](https://github.com/scottlamb/moonfire-nvr/blob/master/guide/troubleshooting.md#viewing-moonfire-nvrs-logs). Run with the `RUST_BACKTRACE=1` environment variable set if possible.
**Camera (please complete the following information):** **Camera (please complete the following information):**

View File

@ -17,10 +17,15 @@ jobs:
extra_args: "--features nightly --benches" extra_args: "--features nightly --benches"
- rust: stable - rust: stable
extra_components: rustfmt extra_components: rustfmt
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v4
with:
# `git describe` output gets baked into the binary for `moonfire-nvr --version`.
# Fetch all revs so it can see tag history.
fetch-depth: 0
filter: 'tree:0'
- name: Cache - name: Cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
@ -62,9 +67,9 @@ jobs:
strategy: strategy:
matrix: matrix:
node: [ "14", "16", "18" ] node: [ "14", "16", "18" ]
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v4
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}

View File

@ -35,10 +35,9 @@ There's no support yet for motion detection, no https/TLS support (you'll
need a proxy server, as described [here](guide/secure.md)), and only a need a proxy server, as described [here](guide/secure.md)), and only a
console-based (rather than web-based) configuration UI. console-based (rather than web-based) configuration UI.
Moonfire NVR is currently at version 0.7.7. Until version 1.0, there will be no Moonfire NVR is pre-1.0, with will be no compatibility guarantees:
compatibility guarantees: configuration and storage formats may change from configuration and storage formats may change from version to version. There is
version to version. There is an [upgrade procedure](guide/schema.md) but it is an [upgrade procedure](guide/schema.md) but it is not for the faint of heart.
not for the faint of heart.
I hope to add features such as video analytics. In time, we can build I hope to add features such as video analytics. In time, we can build
a full-featured hobbyist-oriented multi-camera NVR that requires nothing but a full-featured hobbyist-oriented multi-camera NVR that requires nothing but

View File

@ -141,10 +141,7 @@ Releases are currently a bit manual. From a completely clean git work tree,
1. manually verify the current commit is pushed to github's master branch and 1. manually verify the current commit is pushed to github's master branch and
has a green checkmark indicating CI passed. has a green checkmark indicating CI passed.
2. update versions: 2. update version in `CHANGELOG.md`.
* update `server/Cargo.toml` version by hand; run `cargo test --workspace`
to update `Cargo.lock`.
* ensure `README.md` and `CHANGELOG.md` refer to the new version.
3. run commands: 3. run commands:
```bash ```bash
VERSION=x.y.z VERSION=x.y.z

31
server/Cargo.lock generated
View File

@ -621,6 +621,28 @@ dependencies = [
"wasi 0.11.0+wasi-snapshot-preview1", "wasi 0.11.0+wasi-snapshot-preview1",
] ]
[[package]]
name = "git-version"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6b0decc02f4636b9ccad390dcbe77b722a77efedfa393caf8379a51d5c61899"
dependencies = [
"git-version-macro",
"proc-macro-hack",
]
[[package]]
name = "git-version-macro"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe69f1cbdb6e28af2bac214e943b99ce8a0a06b447d15d3e61161b0423139f3f"
dependencies = [
"proc-macro-hack",
"proc-macro2",
"quote",
"syn 1.0.107",
]
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.15" version = "0.3.15"
@ -1092,7 +1114,7 @@ dependencies = [
[[package]] [[package]]
name = "moonfire-nvr" name = "moonfire-nvr"
version = "0.7.7" version = "0.0.0"
dependencies = [ dependencies = [
"base64", "base64",
"blake3", "blake3",
@ -1104,6 +1126,7 @@ dependencies = [
"flate2", "flate2",
"fnv", "fnv",
"futures", "futures",
"git-version",
"h264-reader", "h264-reader",
"http", "http",
"http-serve", "http-serve",
@ -1429,6 +1452,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6fa0831dd7cc608c38a5e323422a0077678fa5744aa2be4ad91c4ece8eec8d5" checksum = "c6fa0831dd7cc608c38a5e323422a0077678fa5744aa2be4ad91c4ece8eec8d5"
[[package]]
name = "proc-macro-hack"
version = "0.5.20+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.63" version = "1.0.63"

View File

@ -1,6 +1,6 @@
[package] [package]
name = "moonfire-nvr" name = "moonfire-nvr"
version = "0.7.7" version = "0.0.0"
authors = ["Scott Lamb <slamb@slamb.org>"] authors = ["Scott Lamb <slamb@slamb.org>"]
edition = "2021" edition = "2021"
resolver = "2" resolver = "2"
@ -73,6 +73,7 @@ ulid = "1.0.0"
url = "2.1.1" url = "2.1.1"
uuid = { version = "1.1.2", features = ["serde", "std", "v4"] } uuid = { version = "1.1.2", features = ["serde", "std", "v4"] }
flate2 = "1.0.26" flate2 = "1.0.26"
git-version = "0.3.5"
[build-dependencies] [build-dependencies]
blake3 = "1.0.0" blake3 = "1.0.0"

View File

@ -54,7 +54,10 @@ pub fn run(conn: &mut rusqlite::Connection, opts: &Options) -> Result<i32, Error
error!("Schema version is not as expected:\n{}", e); error!("Schema version is not as expected:\n{}", e);
printed_error = true; printed_error = true;
} else { } else {
info!("Schema at expected version {}.", db::EXPECTED_VERSION); info!(
"Schema at expected version {}.",
db::EXPECTED_SCHEMA_VERSION
);
} }
// Compare schemas. // Compare schemas.

View File

@ -60,7 +60,7 @@ use tracing::{error, info, trace};
use uuid::Uuid; use uuid::Uuid;
/// Expected schema version. See `guide/schema.md` for more information. /// Expected schema version. See `guide/schema.md` for more information.
pub const EXPECTED_VERSION: i32 = 7; pub const EXPECTED_SCHEMA_VERSION: i32 = 7;
/// Length of the video index cache. /// Length of the video index cache.
/// The actual data structure is one bigger than this because we insert before we remove. /// The actual data structure is one bigger than this because we insert before we remove.
@ -2238,9 +2238,10 @@ pub fn init(conn: &mut rusqlite::Connection) -> Result<(), Error> {
} }
/// Gets the schema version from the given database connection. /// Gets the schema version from the given database connection.
/// A fully initialized database will return `Ok(Some(version))` where `version` is an integer that /// A fully initialized database will return `Ok(Some(schema_version))` where `schema_version` is
/// can be compared to `EXPECTED_VERSION`. An empty database will return `Ok(None)`. A partially /// an integer that can be compared to `EXPECTED_SCHEMA_VERSION`. An empty database will return
/// initialized database (in particular, one without a version row) will return some error. /// `Ok(None)`. A partially initialized database (in particular, one without a version row) will
/// return some error.
pub fn get_schema_version(conn: &rusqlite::Connection) -> Result<Option<i32>, Error> { pub fn get_schema_version(conn: &rusqlite::Connection) -> Result<Option<i32>, Error> {
let ver_tables: i32 = conn.query_row_and_then( let ver_tables: i32 = conn.query_row_and_then(
"select count(*) from sqlite_master where name = 'version'", "select count(*) from sqlite_master where name = 'version'",
@ -2282,11 +2283,11 @@ pub(crate) fn check_schema_version(conn: &rusqlite::Connection) -> Result<(), Er
<https://github.com/scottlamb/moonfire-nvr/blob/master/guide/schema.md>."), <https://github.com/scottlamb/moonfire-nvr/blob/master/guide/schema.md>."),
) )
}; };
match ver.cmp(&EXPECTED_VERSION) { match ver.cmp(&EXPECTED_SCHEMA_VERSION) {
std::cmp::Ordering::Less => bail!( std::cmp::Ordering::Less => bail!(
FailedPrecondition, FailedPrecondition,
msg( msg(
"database schema version {ver} is too old (expected {EXPECTED_VERSION}); \ "database schema version {ver} is too old (expected {EXPECTED_SCHEMA_VERSION}); \
see upgrade instructions in guide/upgrade.md" see upgrade instructions in guide/upgrade.md"
), ),
), ),
@ -2294,7 +2295,7 @@ pub(crate) fn check_schema_version(conn: &rusqlite::Connection) -> Result<(), Er
std::cmp::Ordering::Greater => bail!( std::cmp::Ordering::Greater => bail!(
FailedPrecondition, FailedPrecondition,
msg( msg(
"database schema version {ver} is too new (expected {EXPECTED_VERSION}); \ "database schema version {ver} is too new (expected {EXPECTED_SCHEMA_VERSION}); \
must use a newer binary to match" must use a newer binary to match"
), ),
), ),

View File

@ -6,7 +6,7 @@
//! //!
//! See `guide/schema.md` for more information. //! See `guide/schema.md` for more information.
use crate::db::{self, EXPECTED_VERSION}; use crate::db::{self, EXPECTED_SCHEMA_VERSION};
use base::{bail, Error}; use base::{bail, Error};
use nix::NixPath; use nix::NixPath;
use rusqlite::params; use rusqlite::params;
@ -23,8 +23,6 @@ mod v4_to_v5;
mod v5_to_v6; mod v5_to_v6;
mod v6_to_v7; mod v6_to_v7;
const UPGRADE_NOTES: &str = concat!("upgraded using moonfire-db ", env!("CARGO_PKG_VERSION"));
#[derive(Debug)] #[derive(Debug)]
pub struct Args<'a> { pub struct Args<'a> {
pub sample_file_dir: Option<&'a std::path::Path>, pub sample_file_dir: Option<&'a std::path::Path>,
@ -46,7 +44,12 @@ fn set_journal_mode(conn: &rusqlite::Connection, requested: &str) -> Result<(),
Ok(()) Ok(())
} }
fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Result<(), Error> { fn upgrade(
args: &Args,
target_schema_ver: i32,
sw_version: &str,
conn: &mut rusqlite::Connection,
) -> Result<(), Error> {
let upgraders = [ let upgraders = [
v0_to_v1::run, v0_to_v1::run,
v1_to_v2::run, v1_to_v2::run,
@ -58,25 +61,31 @@ fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Res
]; ];
{ {
assert_eq!(upgraders.len(), db::EXPECTED_VERSION as usize); assert_eq!(upgraders.len(), db::EXPECTED_SCHEMA_VERSION as usize);
let old_ver = conn.query_row("select max(id) from version", params![], |row| row.get(0))?; let old_schema_ver =
if old_ver > EXPECTED_VERSION { conn.query_row("select max(id) from version", params![], |row| row.get(0))?;
if old_schema_ver > EXPECTED_SCHEMA_VERSION {
bail!( bail!(
FailedPrecondition, FailedPrecondition,
msg("database is at version {old_ver}, later than expected {EXPECTED_VERSION}"), msg("database is at version {old_schema_ver}, \
later than expected {EXPECTED_SCHEMA_VERSION}"),
); );
} else if old_ver < 0 { } else if old_schema_ver < 0 {
bail!( bail!(
FailedPrecondition, FailedPrecondition,
msg("Database is at negative version {old_ver}!") msg("Database is at negative version {old_schema_ver}!")
); );
} }
info!( info!(
"Upgrading database from version {} to version {}...", "Upgrading database from schema version {} to schema version {}...",
old_ver, target_ver old_schema_ver, target_schema_ver
); );
for ver in old_ver..target_ver { for ver in old_schema_ver..target_schema_ver {
info!("...from version {} to version {}", ver, ver + 1); info!(
"...from schema version {} to schema version {}",
ver,
ver + 1
);
let tx = conn.transaction()?; let tx = conn.transaction()?;
upgraders[ver as usize](args, &tx)?; upgraders[ver as usize](args, &tx)?;
tx.execute( tx.execute(
@ -84,7 +93,7 @@ fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Res
insert into version (id, unix_time, notes) insert into version (id, unix_time, notes)
values (?, cast(strftime('%s', 'now') as int32), ?) values (?, cast(strftime('%s', 'now') as int32), ?)
"#, "#,
params![ver + 1, UPGRADE_NOTES], params![ver + 1, format!("Upgraded using moonfire-nvr {sw_version}")],
)?; )?;
tx.commit()?; tx.commit()?;
} }
@ -93,11 +102,11 @@ fn upgrade(args: &Args, target_ver: i32, conn: &mut rusqlite::Connection) -> Res
Ok(()) Ok(())
} }
pub fn run(args: &Args, conn: &mut rusqlite::Connection) -> Result<(), Error> { pub fn run(args: &Args, sw_version: &str, conn: &mut rusqlite::Connection) -> Result<(), Error> {
db::check_sqlite_version()?; db::check_sqlite_version()?;
db::set_integrity_pragmas(conn)?; db::set_integrity_pragmas(conn)?;
set_journal_mode(conn, args.preset_journal)?; set_journal_mode(conn, args.preset_journal)?;
upgrade(args, EXPECTED_VERSION, conn)?; upgrade(args, EXPECTED_SCHEMA_VERSION, sw_version, conn)?;
// As in "moonfire-nvr init": try for page_size=16384 and wal for the reasons explained there. // As in "moonfire-nvr init": try for page_size=16384 and wal for the reasons explained there.
// //
@ -291,9 +300,10 @@ mod tests {
no_vacuum: false, no_vacuum: false,
}, },
*ver, *ver,
"test",
&mut upgraded, &mut upgraded,
) )
.map_err(|e| err!(e, msg("upgrade to version {ver} failed")))?; .map_err(|e| err!(e, msg("upgrade to schema version {ver} failed")))?;
if let Some(f) = fresh_sql { if let Some(f) = fresh_sql {
compare(&upgraded, *ver, f)?; compare(&upgraded, *ver, f)?;
} }

View File

@ -39,6 +39,7 @@ pub fn run(args: Args) -> Result<i32, Error> {
preset_journal: &args.preset_journal, preset_journal: &args.preset_journal,
no_vacuum: args.no_vacuum, no_vacuum: args.no_vacuum,
}, },
crate::VERSION,
&mut conn, &mut conn,
)?; )?;
Ok(0) Ok(0)

View File

@ -25,9 +25,11 @@ mod bundled_ui;
const DEFAULT_DB_DIR: &str = "/var/lib/moonfire-nvr/db"; const DEFAULT_DB_DIR: &str = "/var/lib/moonfire-nvr/db";
const VERSION: &str = git_version::git_version!(args = ["--always", "--dirty"]);
/// Moonfire NVR: security camera network video recorder. /// Moonfire NVR: security camera network video recorder.
#[derive(Bpaf, Debug)] #[derive(Bpaf, Debug)]
#[bpaf(options, version)] #[bpaf(options, version(VERSION))]
enum Args { enum Args {
// See docstrings of `cmds::*::Args` structs for a description of the respective subcommands. // See docstrings of `cmds::*::Args` structs for a description of the respective subcommands.
Check(#[bpaf(external(cmds::check::args))] cmds::check::Args), Check(#[bpaf(external(cmds::check::args))] cmds::check::Args),