Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

Add scripts/check.ps1, the local CI gate, and a dependency policy

Bee37417a920693
diff --git a/Cargo.toml b/Cargo.toml
index c79d80e..5a53816 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,8 +15,8 @@ authors = ["The Nectarlink contributors"]
repository = "https://github.com/thtbee/nectarlink"
[workspace.dependencies]
-nectarlink-protocol = { path = "core/nectarlink-protocol" }
-nectarlink-core = { path = "core/nectarlink-core" }
+nectarlink-protocol = { path = "core/nectarlink-protocol", version = "0.0.1" }
+nectarlink-core = { path = "core/nectarlink-core", version = "0.0.1" }
anyhow = "1"
ciborium = "0.2"
diff --git a/deny.toml b/deny.toml
new file mode 100644
index 0000000..3eb9e8f
--- /dev/null
+++ b/deny.toml
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Dependency policy, enforced by `cargo deny check` (run by scripts/check.ps1).
+
+[graph]
+all-features = true
+
+[advisories]
+# Known vulnerabilities fail the build; unmaintained crates are reported
+# only when they are direct dependencies.
+unmaintained = "workspace"
+yanked = "deny"
+
+[licenses]
+# Permissive and weak-copyleft licenses that are compatible with both the
+# MPL-2.0 core libraries and the GPL-3.0-or-later apps (see LICENSE).
+allow = [
+ "Apache-2.0",
+ "Apache-2.0 WITH LLVM-exception",
+ "BSD-2-Clause",
+ "BSD-3-Clause",
+ "BSL-1.0",
+ "CC0-1.0",
+ "CDLA-Permissive-2.0",
+ "ISC",
+ "MIT",
+ "MIT-0",
+ "MPL-2.0",
+ "Unicode-3.0",
+ "Unlicense",
+ "Zlib",
+]
+confidence-threshold = 0.9
+# The apps themselves are GPL; nothing else may be, so a GPL dependency can
+# never end up in the MPL core by accident.
+exceptions = [
+ { crate = "nectarlink-cli", allow = ["GPL-3.0-or-later"] },
+ { crate = "s1-qt-rust", allow = ["GPL-3.0-or-later"] },
+]
+
+[bans]
+multiple-versions = "allow"
+wildcards = "deny"
+allow-wildcard-paths = true
+
+[sources]
+unknown-registry = "deny"
+unknown-git = "deny"
diff --git a/scripts/check.ps1 b/scripts/check.ps1
new file mode 100644
index 0000000..8be5114
--- /dev/null
+++ b/scripts/check.ps1
@@ -0,0 +1,121 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+<#
+.SYNOPSIS
+ Runs the same checks as CI: formatting, lints, tests, license headers and
+ the dependency policy. Exits non-zero if any step fails.
+
+.DESCRIPTION
+ Every step runs even after a failure, so one run shows everything that
+ needs fixing. Steps that need Qt (the desktop crates) use QMAKE or the
+ qmake on PATH.
+
+.PARAMETER Arm64
+ Also cross-compiles the workspace for Windows ARM64.
+
+.PARAMETER Fast
+ Skips the slow steps (tests and the dependency audit).
+
+.EXAMPLE
+ ./scripts/check.ps1
+ ./scripts/check.ps1 -Arm64
+#>
+param(
+ [switch]$Arm64,
+ [switch]$Fast
+)
+$ErrorActionPreference = "Stop"
+$root = Split-Path -Parent $PSScriptRoot
+Push-Location $root
+
+$results = New-Object System.Collections.Generic.List[object]
+
+function Invoke-Step {
+ param([string]$Name, [scriptblock]$Body)
+ Write-Host ""
+ Write-Host "==> $Name" -ForegroundColor Cyan
+ $timer = [System.Diagnostics.Stopwatch]::StartNew()
+ $ok = $true
+ $global:LASTEXITCODE = 0 # a previous step's exit code must not leak in
+ # Windows PowerShell turns a native tool's stderr (cargo's progress
+ # output) into errors when output is redirected; judge by exit code.
+ $ErrorActionPreference = "Continue"
+ try {
+ & $Body
+ if ($LASTEXITCODE -ne 0) { $ok = $false }
+ } catch {
+ Write-Host $_ -ForegroundColor Red
+ $ok = $false
+ }
+ $results.Add([pscustomobject]@{ Step = $Name; Ok = $ok; Seconds = [math]::Round($timer.Elapsed.TotalSeconds, 1) })
+}
+
+# Which license a source file must declare (mirrors LICENSE).
+function Get-ExpectedLicense([string]$path) {
+ if ($path -like "core/nectarlink-cli/*") { return "GPL-3.0-or-later" }
+ if ($path -like "core/*") { return "MPL-2.0" }
+ return "GPL-3.0-or-later"
+}
+
+function Test-SpdxHeaders {
+ $extensions = @(".rs", ".qml", ".cpp", ".h", ".hpp", ".ps1", ".sh", ".kt", ".kts")
+ $files = @(git ls-files --cached --others --exclude-standard) |
+ Where-Object { $extensions -contains [System.IO.Path]::GetExtension($_) } |
+ Where-Object { Test-Path $_ }
+ $problems = 0
+ foreach ($file in $files) {
+ $head = Get-Content $file -TotalCount 5 -ErrorAction SilentlyContinue
+ $line = $head | Where-Object { $_ -match "SPDX-License-Identifier:\s*(\S+)" } | Select-Object -First 1
+ if (-not $line) {
+ Write-Host " missing SPDX header: $file" -ForegroundColor Red
+ $problems++
+ continue
+ }
+ $null = $line -match "SPDX-License-Identifier:\s*(\S+)"
+ $expected = Get-ExpectedLicense $file
+ if ($Matches[1] -ne $expected) {
+ Write-Host " wrong license in $file ($($Matches[1]), expected $expected)" -ForegroundColor Red
+ $problems++
+ }
+ }
+ Write-Host " $($files.Count) files checked, $problems problem(s)"
+ $global:LASTEXITCODE = [int]($problems -gt 0)
+}
+
+try {
+ Invoke-Step "Format" { cargo fmt --all --check }
+ Invoke-Step "Clippy" { cargo clippy --workspace --all-targets --locked -- -D warnings }
+ if (-not $Fast) {
+ Invoke-Step "Tests" { cargo test --workspace --locked }
+ }
+ Invoke-Step "License headers" { Test-SpdxHeaders }
+ if (-not $Fast) {
+ Invoke-Step "Dependency policy" {
+ if (-not (Get-Command cargo-deny -ErrorAction SilentlyContinue)) {
+ throw "cargo-deny is not installed: cargo install --locked cargo-deny"
+ }
+ cargo deny --log-level error check
+ }
+ }
+ if ($Arm64) {
+ Invoke-Step "ARM64 build" {
+ $previous = $env:QMAKE
+ try {
+ $env:QMAKE = & (Join-Path $PSScriptRoot "qmake-arm64.ps1")
+ cargo build --workspace --release --locked --target aarch64-pc-windows-msvc
+ } finally {
+ $env:QMAKE = $previous
+ }
+ }
+ }
+} finally {
+ Pop-Location
+}
+
+Write-Host ""
+$results | Format-Table -AutoSize @{ L = "Step"; E = { $_.Step } }, @{ L = "Result"; E = { if ($_.Ok) { "ok" } else { "FAILED" } } }, @{ L = "Time (s)"; E = { $_.Seconds } }
+$failed = @($results | Where-Object { -not $_.Ok }).Count
+if ($failed -gt 0) {
+ Write-Host "$failed step(s) failed." -ForegroundColor Red
+ exit 1
+}
+Write-Host "All checks passed." -ForegroundColor Green
diff --git a/spikes/s1-qt-rust/qml/App.qml b/spikes/s1-qt-rust/qml/App.qml
index 8a8b90d..9c068e4 100644
--- a/spikes/s1-qt-rust/qml/App.qml
+++ b/spikes/s1-qt-rust/qml/App.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import app.nectarlink.spike
diff --git a/spikes/s1-qt-rust/qml/DeckKey.qml b/spikes/s1-qt-rust/qml/DeckKey.qml
index 3201ac0..0462578 100644
--- a/spikes/s1-qt-rust/qml/DeckKey.qml
+++ b/spikes/s1-qt-rust/qml/DeckKey.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
Rectangle {
diff --git a/spikes/s1-qt-rust/qml/Icon.qml b/spikes/s1-qt-rust/qml/Icon.qml
index ec08d90..dfb99fd 100644
--- a/spikes/s1-qt-rust/qml/Icon.qml
+++ b/spikes/s1-qt-rust/qml/Icon.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Shapes
diff --git a/spikes/s1-qt-rust/qml/Main.qml b/spikes/s1-qt-rust/qml/Main.qml
index ff2a8b5..d722364 100644
--- a/spikes/s1-qt-rust/qml/Main.qml
+++ b/spikes/s1-qt-rust/qml/Main.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Effects
import app.nectarlink.spike
diff --git a/spikes/s1-qt-rust/qml/MirrorPanel.qml b/spikes/s1-qt-rust/qml/MirrorPanel.qml
index 58c4d3e..0fe97c8 100644
--- a/spikes/s1-qt-rust/qml/MirrorPanel.qml
+++ b/spikes/s1-qt-rust/qml/MirrorPanel.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Effects
import app.nectarlink.spike
diff --git a/spikes/s1-qt-rust/qml/NotificationCard.qml b/spikes/s1-qt-rust/qml/NotificationCard.qml
index 9186fdc..642a585 100644
--- a/spikes/s1-qt-rust/qml/NotificationCard.qml
+++ b/spikes/s1-qt-rust/qml/NotificationCard.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
Item {
diff --git a/spikes/s1-qt-rust/qml/QuickAction.qml b/spikes/s1-qt-rust/qml/QuickAction.qml
index 1779aad..dbbba25 100644
--- a/spikes/s1-qt-rust/qml/QuickAction.qml
+++ b/spikes/s1-qt-rust/qml/QuickAction.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
Rectangle {
diff --git a/spikes/s1-qt-rust/qml/StatsPanel.qml b/spikes/s1-qt-rust/qml/StatsPanel.qml
index 22db7f0..45f7408 100644
--- a/spikes/s1-qt-rust/qml/StatsPanel.qml
+++ b/spikes/s1-qt-rust/qml/StatsPanel.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import app.nectarlink.spike
diff --git a/spikes/s1-qt-rust/qml/Theme.qml b/spikes/s1-qt-rust/qml/Theme.qml
index 1280e75..51d0dda 100644
--- a/spikes/s1-qt-rust/qml/Theme.qml
+++ b/spikes/s1-qt-rust/qml/Theme.qml
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
pragma Singleton
import QtQuick