Skip to content

Commit f47e7a8

Browse files
authored
Merge pull request #1187 from MODSetter/dev
feat: various fixes and streamlined versioning
2 parents c77098a + 43beb8e commit f47e7a8

102 files changed

Lines changed: 6774 additions & 5084 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/desktop-release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ jobs:
5252
VERSION=${TAG#beta-}
5353
VERSION=${VERSION#v}
5454
fi
55+
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
56+
echo "::error::Version '$VERSION' is not valid semver (expected X.Y.Z). Fix your tag name."
57+
exit 1
58+
fi
5559
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
5660
5761
- name: Setup pnpm

.github/workflows/docker-build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ jobs:
4040
- name: Read app version and calculate next Docker build version
4141
id: tag_version
4242
run: |
43-
APP_VERSION=$(grep -E '^version = ' surfsense_backend/pyproject.toml | sed 's/version = "\(.*\)"/\1/')
44-
echo "App version from pyproject.toml: $APP_VERSION"
43+
APP_VERSION=$(tr -d '[:space:]' < VERSION)
44+
echo "App version from VERSION file: $APP_VERSION"
4545
4646
if [ -z "$APP_VERSION" ]; then
47-
echo "Error: Could not read version from surfsense_backend/pyproject.toml"
47+
echo "Error: Could not read version from VERSION file"
4848
exit 1
4949
fi
5050

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.15

scripts/bump-version.ps1

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$RepoRoot = (Resolve-Path "$PSScriptRoot\..").Path
4+
$VersionFile = Join-Path $RepoRoot "VERSION"
5+
6+
if (-not (Test-Path $VersionFile)) {
7+
Write-Error "VERSION file not found at $VersionFile"
8+
exit 1
9+
}
10+
11+
$Version = (Get-Content $VersionFile -Raw).Trim()
12+
13+
if ($Version -notmatch '^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$') {
14+
Write-Error "'$Version' is not valid semver (expected X.Y.Z)"
15+
exit 1
16+
}
17+
18+
Write-Host "Bumping all packages to $Version"
19+
Write-Host "---------------------------------"
20+
21+
function Bump-Json {
22+
param([string]$File)
23+
if (-not (Test-Path $File)) {
24+
Write-Host " SKIP $File (not found)"
25+
return
26+
}
27+
$content = Get-Content $File -Raw
28+
$match = [regex]::Match($content, '"version"\s*:\s*"([^"]*)"')
29+
if (-not $match.Success) {
30+
Write-Host " SKIP $File (no version field found)"
31+
return
32+
}
33+
$old = $match.Groups[1].Value
34+
if ($old -eq $Version) {
35+
Write-Host " OK $File ($old -- already up to date)"
36+
} else {
37+
$content = $content -replace [regex]::Escape("`"version`": `"$old`""), "`"version`": `"$Version`""
38+
Set-Content $File -Value $content -NoNewline
39+
Write-Host " SET $File ($old -> $Version)"
40+
}
41+
}
42+
43+
function Bump-Toml {
44+
param([string]$File)
45+
if (-not (Test-Path $File)) {
46+
Write-Host " SKIP $File (not found)"
47+
return
48+
}
49+
$content = Get-Content $File -Raw
50+
$match = [regex]::Match($content, '(?m)^version\s*=\s*"([^"]*)"')
51+
if (-not $match.Success) {
52+
Write-Host " SKIP $File (no version field found)"
53+
return
54+
}
55+
$old = $match.Groups[1].Value
56+
if ($old -eq $Version) {
57+
Write-Host " OK $File ($old -- already up to date)"
58+
} else {
59+
$content = $content -replace ('(?m)^version\s*=\s*"' + [regex]::Escape($old) + '"'), "version = `"$Version`""
60+
Set-Content $File -Value $content -NoNewline
61+
Write-Host " SET $File ($old -> $Version)"
62+
}
63+
}
64+
65+
Bump-Json (Join-Path $RepoRoot "surfsense_web\package.json")
66+
Bump-Json (Join-Path $RepoRoot "surfsense_browser_extension\package.json")
67+
Bump-Json (Join-Path $RepoRoot "surfsense_desktop\package.json")
68+
Bump-Toml (Join-Path $RepoRoot "surfsense_backend\pyproject.toml")
69+
70+
Write-Host ""
71+
Write-Host "Syncing lock files..."
72+
if (Get-Command uv -ErrorAction SilentlyContinue) {
73+
Push-Location (Join-Path $RepoRoot "surfsense_backend")
74+
uv lock
75+
Pop-Location
76+
Write-Host " OK surfsense_backend/uv.lock"
77+
} else {
78+
Write-Host " SKIP uv not found -- run 'uv lock' in surfsense_backend/ manually"
79+
}
80+
81+
Write-Host "---------------------------------"
82+
Write-Host "Done. All packages set to $Version"

scripts/bump-version.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5+
VERSION_FILE="$REPO_ROOT/VERSION"
6+
7+
if [ ! -f "$VERSION_FILE" ]; then
8+
echo "ERROR: VERSION file not found at $VERSION_FILE" >&2
9+
exit 1
10+
fi
11+
12+
VERSION="$(tr -d '[:space:]' < "$VERSION_FILE")"
13+
14+
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
15+
echo "ERROR: '$VERSION' is not valid semver (expected X.Y.Z)" >&2
16+
exit 1
17+
fi
18+
19+
echo "Bumping all packages to $VERSION"
20+
echo "---------------------------------"
21+
22+
bump_json() {
23+
local file="$1"
24+
if [ ! -f "$file" ]; then
25+
echo " SKIP $file (not found)"
26+
return
27+
fi
28+
local old
29+
old="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$file" | head -1)"
30+
if [ "$old" = "$VERSION" ]; then
31+
echo " OK $file ($old -- already up to date)"
32+
else
33+
sed -i "s/\"version\": \"$old\"/\"version\": \"$VERSION\"/" "$file"
34+
echo " SET $file ($old -> $VERSION)"
35+
fi
36+
}
37+
38+
bump_toml() {
39+
local file="$1"
40+
if [ ! -f "$file" ]; then
41+
echo " SKIP $file (not found)"
42+
return
43+
fi
44+
local old
45+
old="$(sed -n 's/^version[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' "$file" | head -1)"
46+
if [ "$old" = "$VERSION" ]; then
47+
echo " OK $file ($old -- already up to date)"
48+
else
49+
sed -i "s/^version = \"$old\"/version = \"$VERSION\"/" "$file"
50+
echo " SET $file ($old -> $VERSION)"
51+
fi
52+
}
53+
54+
bump_json "$REPO_ROOT/surfsense_web/package.json"
55+
bump_json "$REPO_ROOT/surfsense_browser_extension/package.json"
56+
bump_json "$REPO_ROOT/surfsense_desktop/package.json"
57+
bump_toml "$REPO_ROOT/surfsense_backend/pyproject.toml"
58+
59+
echo ""
60+
echo "Syncing lock files..."
61+
if command -v uv &>/dev/null; then
62+
(cd "$REPO_ROOT/surfsense_backend" && uv lock)
63+
echo " OK surfsense_backend/uv.lock"
64+
else
65+
echo " SKIP uv not found -- run 'uv lock' in surfsense_backend/ manually"
66+
fi
67+
68+
echo "---------------------------------"
69+
echo "Done. All packages set to $VERSION"

surfsense_backend/app/db.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
from sqlalchemy.dialects.postgresql import JSONB, UUID
2727
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
28-
from sqlalchemy.orm import DeclarativeBase, Mapped, declared_attr, relationship
28+
from sqlalchemy.orm import DeclarativeBase, Mapped, backref, declared_attr, relationship
2929

3030
from app.config import config
3131

@@ -1086,7 +1086,9 @@ class DocumentVersion(BaseModel, TimestampMixin):
10861086
content_hash = Column(String, nullable=False)
10871087
title = Column(String, nullable=True)
10881088

1089-
document = relationship("Document", backref="versions")
1089+
document = relationship(
1090+
"Document", backref=backref("versions", passive_deletes=True)
1091+
)
10901092

10911093

10921094
class Chunk(BaseModel, TimestampMixin):

surfsense_backend/app/indexing_pipeline/connector_document.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ConnectorDocument(BaseModel):
1717
metadata: dict = {}
1818
connector_id: int | None = None
1919
created_by_id: str
20+
folder_id: int | None = None
2021

2122
@field_validator("title", "source_markdown", "unique_id", "created_by_id")
2223
@classmethod

surfsense_backend/app/indexing_pipeline/indexing_pipeline_service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ async def prepare_for_indexing(
268268
):
269269
existing.status = DocumentStatus.pending()
270270
existing.updated_at = datetime.now(UTC)
271+
if connector_doc.folder_id is not None:
272+
existing.folder_id = connector_doc.folder_id
271273
documents.append(existing)
272274
log_document_requeued(ctx)
273275
continue
@@ -294,6 +296,8 @@ async def prepare_for_indexing(
294296
existing.document_metadata = connector_doc.metadata
295297
existing.updated_at = datetime.now(UTC)
296298
existing.status = DocumentStatus.pending()
299+
if connector_doc.folder_id is not None:
300+
existing.folder_id = connector_doc.folder_id
297301
documents.append(existing)
298302
log_document_updated(ctx)
299303
continue
@@ -317,6 +321,7 @@ async def prepare_for_indexing(
317321
created_by_id=connector_doc.created_by_id,
318322
updated_at=datetime.now(UTC),
319323
status=DocumentStatus.pending(),
324+
folder_id=connector_doc.folder_id,
320325
)
321326
self.session.add(document)
322327
documents.append(document)

0 commit comments

Comments
 (0)