Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Keep workflow filters and Rust dependency lists sorted

Manav Rathia1fa78552722
diff --git a/.github/checks/run.sh b/.github/checks/run.sh
index bac82c9b29..8a37903a3d 100755
--- a/.github/checks/run.sh
+++ b/.github/checks/run.sh
@@ -5,3 +5,5 @@ cd "$(dirname "$0")/../.."
node .github/checks/documentation-comments/check.mjs
node .github/checks/documentation-comments/test.mjs
+ruby .github/checks/workflow-paths/check.rb
+ruby .github/checks/workflow-paths/test.rb
diff --git a/.github/checks/workflow-paths/check.rb b/.github/checks/workflow-paths/check.rb
new file mode 100644
index 0000000000..5f93fdefb5
--- /dev/null
+++ b/.github/checks/workflow-paths/check.rb
@@ -0,0 +1,26 @@
+require "yaml"
+
+Dir.chdir(ARGV.fetch(0, "."))
+failed = false
+
+Dir[".github/workflows/*.{yml,yaml}"].sort.each do |path|
+ workflow = YAML.safe_load(File.read(path), aliases: true)
+ events = workflow["on"] || workflow[true]
+ next unless events.is_a?(Hash)
+
+ events.each do |event, config|
+ next unless config.is_a?(Hash)
+
+ %w[paths paths-ignore].each do |key|
+ patterns = config[key]
+ next unless patterns.is_a?(Array)
+ next if patterns.any? { |pattern| pattern.start_with?("!") }
+ next if patterns == patterns.sort
+
+ warn "#{path}: on.#{event}.#{key} must be sorted"
+ failed = true
+ end
+ end
+end
+
+exit(failed ? 1 : 0)
diff --git a/.github/checks/workflow-paths/test.rb b/.github/checks/workflow-paths/test.rb
new file mode 100644
index 0000000000..abf4164c66
--- /dev/null
+++ b/.github/checks/workflow-paths/test.rb
@@ -0,0 +1,51 @@
+require "fileutils"
+require "open3"
+require "rbconfig"
+require "tmpdir"
+
+CHECK = File.expand_path("check.rb", __dir__)
+
+def run(source)
+ Dir.mktmpdir("ente-workflow-paths-") do |root|
+ FileUtils.mkdir_p("#{root}/.github/workflows")
+ File.write("#{root}/.github/workflows/test.yml", source)
+ Open3.capture3(RbConfig.ruby, CHECK, root)
+ end
+end
+
+[
+ "on: [push, pull_request]\n",
+ "'on':\n push:\n paths: [a/**, b/**]\n",
+ "on:\n push:\n paths: [z/**, '!z/private/**', a/**]\n",
+ "on:\n push:\n paths: &paths [a/**, b/**]\n pull_request:\n paths: *paths\n",
+ <<~YAML,
+ on:
+ workflow_dispatch:
+ jobs:
+ check:
+ steps:
+ - uses: codeql
+ with:
+ config: |
+ paths-ignore: [z/**, a/**]
+ YAML
+].each do |source|
+ stdout, stderr, status = run(source)
+ raise stderr unless status.success? && stdout.empty? && stderr.empty?
+end
+
+source = <<~YAML
+ on:
+ push:
+ paths: [b/**, a/**]
+ pull_request:
+ paths-ignore:
+ - z/** # comment
+ - a/**
+YAML
+stdout, stderr, status = run(source)
+raise stderr unless status.exitstatus == 1 && stdout.empty?
+%w[push.paths pull_request.paths-ignore].each do |field|
+ expected = ".github/workflows/test.yml: on.#{field} must be sorted"
+ raise stderr unless stderr.include?(expected)
+end
diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml
index 417bc49fd0..b80456b951 100644
--- a/.github/workflows/dependency-review.yml
+++ b/.github/workflows/dependency-review.yml
@@ -3,7 +3,6 @@ name: "Dependency review"
on:
pull_request:
paths:
- - ".github/workflows/dependency-review.yml"
- "**/Cargo.lock"
- "**/Cargo.toml"
- "**/go.mod"
@@ -13,6 +12,7 @@ on:
- "**/pubspec.lock"
- "**/pubspec.yaml"
- "**/uv.lock"
+ - ".github/workflows/dependency-review.yml"
permissions:
contents: read
diff --git a/.github/workflows/desktop-lint.yml b/.github/workflows/desktop-lint.yml
index 3447e6bbe4..274b654331 100644
--- a/.github/workflows/desktop-lint.yml
+++ b/.github/workflows/desktop-lint.yml
@@ -5,12 +5,12 @@ on:
paths:
- ".github/workflows/desktop-lint.yml"
- "desktop/**"
+ - "rust/Cargo.lock"
+ - "rust/Cargo.toml"
- "rust/bindings/napi/**"
- "rust/crates/image/**"
- "rust/crates/ml/**"
- "rust/tools/codegen/**"
- - "rust/Cargo.toml"
- - "rust/Cargo.lock"
permissions:
contents: read
diff --git a/.github/workflows/docs-verify-build.yml b/.github/workflows/docs-verify-build.yml
index 50c24d2733..23fdfb149e 100644
--- a/.github/workflows/docs-verify-build.yml
+++ b/.github/workflows/docs-verify-build.yml
@@ -3,8 +3,8 @@ name: "Verify build (Docs)"
on:
pull_request:
paths:
- - "docs/**"
- ".github/workflows/docs-verify-build.yml"
+ - "docs/**"
permissions:
contents: read
diff --git a/.github/workflows/ensu-android-build.yml b/.github/workflows/ensu-android-build.yml
index 88928a7d33..e154478a52 100644
--- a/.github/workflows/ensu-android-build.yml
+++ b/.github/workflows/ensu-android-build.yml
@@ -3,16 +3,16 @@ name: "Build (Ensu Android)"
on:
pull_request:
paths:
+ - ".github/workflows/ensu-android-build.yml"
- "android/apps/ensu/**"
- "android/apps/ensu/rust/**"
- - "rust/tools/codegen/**"
- - "rust/crates/core/**"
- - "rust/crates/ensu/**"
- - "rust/bindings/uniffi/**"
- "rust/.cargo/config.toml"
- - "rust/Cargo.toml"
- "rust/Cargo.lock"
- - ".github/workflows/ensu-android-build.yml"
+ - "rust/Cargo.toml"
+ - "rust/bindings/uniffi/**"
+ - "rust/crates/core/**"
+ - "rust/crates/ensu/**"
+ - "rust/tools/codegen/**"
permissions:
contents: read
diff --git a/.github/workflows/ensu-ios-build.yml b/.github/workflows/ensu-ios-build.yml
index 77c1d00daf..8b7b33341f 100644
--- a/.github/workflows/ensu-ios-build.yml
+++ b/.github/workflows/ensu-ios-build.yml
@@ -3,16 +3,16 @@ name: "Build (Ensu iOS)"
on:
pull_request:
paths:
+ - ".github/workflows/ensu-ios-build.yml"
- "apple/apps/ensu/**"
- "apple/packages/EnteOnnxRuntime/**"
- - "rust/tools/codegen/**"
- - "rust/crates/core/**"
- - "rust/crates/ensu/**"
- - "rust/bindings/uniffi/**"
- "rust/.cargo/config.toml"
- - "rust/Cargo.toml"
- "rust/Cargo.lock"
- - ".github/workflows/ensu-ios-build.yml"
+ - "rust/Cargo.toml"
+ - "rust/bindings/uniffi/**"
+ - "rust/crates/core/**"
+ - "rust/crates/ensu/**"
+ - "rust/tools/codegen/**"
permissions:
contents: read
diff --git a/.github/workflows/mobile-crowdin-push-sources.yml b/.github/workflows/mobile-crowdin-push-sources.yml
index c6ae4504e3..c5dbd703f8 100644
--- a/.github/workflows/mobile-crowdin-push-sources.yml
+++ b/.github/workflows/mobile-crowdin-push-sources.yml
@@ -5,8 +5,8 @@ on:
branches: [main]
paths:
- ".github/workflows/mobile-crowdin-push-sources.yml"
- - "mobile/packages/strings/lib/l10n/arb/strings_en.arb"
- "mobile/packages/strings/crowdin.yml"
+ - "mobile/packages/strings/lib/l10n/arb/strings_en.arb"
concurrency:
group: ${{ github.workflow }}
diff --git a/.github/workflows/mobile-lint.yml b/.github/workflows/mobile-lint.yml
index 60a7a032f7..a1ef77123a 100644
--- a/.github/workflows/mobile-lint.yml
+++ b/.github/workflows/mobile-lint.yml
@@ -5,10 +5,9 @@ on:
paths:
- ".github/workflows/mobile-lint.yml"
- "mobile/**"
- - "rust/tools/codegen/**"
- - "rust/bindings/frb/**"
- "rust/Cargo.lock"
- "rust/Cargo.toml"
+ - "rust/bindings/frb/**"
- "rust/crates/cast/**"
- "rust/crates/contacts/**"
- "rust/crates/core/**"
@@ -16,6 +15,7 @@ on:
- "rust/crates/locker/**"
- "rust/crates/ml/**"
- "rust/crates/photos/**"
+ - "rust/tools/codegen/**"
workflow_dispatch:
permissions:
diff --git a/.github/workflows/mobile-podfile-lock.yml b/.github/workflows/mobile-podfile-lock.yml
index 70ebcc976c..5b2b8b2010 100644
--- a/.github/workflows/mobile-podfile-lock.yml
+++ b/.github/workflows/mobile-podfile-lock.yml
@@ -5,11 +5,11 @@ on:
paths:
- ".github/workflows/mobile-podfile-lock.yml"
- "apple/packages/EnteOnnxRuntime/EnteOnnxRuntime.podspec"
- - "mobile/**/pubspec.yaml"
- - "mobile/**/pubspec.lock"
+ - "mobile/**/*.podspec"
- "mobile/**/Podfile"
- "mobile/**/Podfile.lock"
- - "mobile/**/*.podspec"
+ - "mobile/**/pubspec.lock"
+ - "mobile/**/pubspec.yaml"
workflow_dispatch:
permissions:
diff --git a/.github/workflows/web-crowdin-sync.yml b/.github/workflows/web-crowdin-sync.yml
index e3c681d267..0fcb5e9343 100644
--- a/.github/workflows/web-crowdin-sync.yml
+++ b/.github/workflows/web-crowdin-sync.yml
@@ -5,8 +5,8 @@ on:
branches: [main]
paths:
- ".github/workflows/web-crowdin-sync.yml"
- - "web/packages/base/locales/en-US/translation.json"
- "web/crowdin.yml"
+ - "web/packages/base/locales/en-US/translation.json"
schedule:
# Mondays at ~6:00 AM IST
- cron: "20 0 * * 1"
diff --git a/.github/workflows/web-lint.yml b/.github/workflows/web-lint.yml
index 0ad93bdc67..15201a36b3 100644
--- a/.github/workflows/web-lint.yml
+++ b/.github/workflows/web-lint.yml
@@ -3,7 +3,9 @@ name: "Lint (Web)"
on:
pull_request:
paths:
- - "web/**"
+ - ".github/workflows/web-lint.yml"
+ - "rust/Cargo.lock"
+ - "rust/Cargo.toml"
- "rust/bindings/wasm/**"
- "rust/crates/cast/**"
- "rust/crates/collections/**"
@@ -12,9 +14,7 @@ on:
- "rust/crates/locker/**"
- "rust/crates/paste/**"
- "rust/crates/space/**"
- - "rust/Cargo.lock"
- - "rust/Cargo.toml"
- - ".github/workflows/web-lint.yml"
+ - "web/**"
permissions:
contents: read
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 4d804ccd31..fb1657d484 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -89,8 +89,8 @@ regex = "1.11.1"
reqwest = { version = "0.12.28", default-features = false }
rusqlite = { version = "0.40.2", default-features = false, features = ["bundled"] }
serde = { version = "1.0.228", features = ["derive"] }
-serde_json = "1.0.149"
serde-wasm-bindgen = "0.6.5"
+serde_json = "1.0.149"
sha1 = "0.11.0"
sha2 = "0.11.0"
srp = { version = "0.7.0-rc.3", default-features = false }
diff --git a/rust/checks/cargo-workspace-dependencies/check.py b/rust/checks/cargo-workspace-dependencies/check.py
index 09597de5a8..ed4465d29d 100644
--- a/rust/checks/cargo-workspace-dependencies/check.py
+++ b/rust/checks/cargo-workspace-dependencies/check.py
@@ -32,14 +32,22 @@ for package in packages:
failed = False
-members = tomllib.loads((root / "rust/Cargo.toml").read_text())["workspace"]["members"]
-for previous, member in zip(members, members[1:]):
- if previous > member:
- print(
- f"rust/Cargo.toml: workspace.members {previous!r} precedes {member!r}; sort members",
- file=sys.stderr,
- )
- failed = True
+
+def check_order(entries, path, table):
+ entries = list(entries)
+ for previous, current in zip(entries, entries[1:]):
+ if previous > current:
+ print(
+ f"{path}: {table} must be sorted: {previous!r} precedes {current!r}",
+ file=sys.stderr,
+ )
+ return False
+ return True
+
+
+workspace = tomllib.loads((root / "rust/Cargo.toml").read_text())["workspace"]
+for table in ("members", "dependencies"):
+ failed |= not check_order(workspace.get(table, {}), "rust/Cargo.toml", f"workspace.{table}")
for package in packages:
manifest = Path(package["manifest_path"])
@@ -58,6 +66,7 @@ for package in packages:
for section in sections
]
for table, dependencies in tables:
+ failed |= not check_order(dependencies, path, table)
for name, declaration in dependencies.items():
if isinstance(declaration, dict) and declaration.get("workspace") is True:
continue
@@ -71,5 +80,6 @@ for package in packages:
file=sys.stderr,
)
failed = True
+ failed |= not check_order(cargo.get("features", {}), path, "features")
sys.exit(1 if failed else 0)
diff --git a/rust/checks/cargo-workspace-dependencies/test.py b/rust/checks/cargo-workspace-dependencies/test.py
index eb047848f0..c0f8ea5dcb 100644
--- a/rust/checks/cargo-workspace-dependencies/test.py
+++ b/rust/checks/cargo-workspace-dependencies/test.py
@@ -14,8 +14,8 @@ resolver = "2"
edition = "2024"
[workspace.dependencies]
-shared = { path = "shared" }
serde = "1.0.0"
+shared = { path = "shared" }
[workspace.lints.clippy]
allow_attributes = "deny"
@@ -32,15 +32,15 @@ workspace = true
"""
-def run(app_b, members='"app-*"', app_b_package=package):
+def run(app_b, members='"app-*"', app_b_package=package, workspace_toml=workspace):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
rust = root / "rust"
- write(rust / "Cargo.toml", workspace.replace('"app-*"', members))
+ write(rust / "Cargo.toml", workspace_toml.replace('"app-*"', members))
write(
rust / "app-a/Cargo.toml",
package.format("app-a")
- + "\n[dependencies]\nshared.workspace = true\nserde.workspace = true\n",
+ + "\n[dependencies]\nserde.workspace = true\nshared.workspace = true\n",
)
write(rust / "app-b/Cargo.toml", app_b_package.format("app-b") + app_b)
write(
@@ -103,7 +103,7 @@ assert "target.cfg(windows)" not in result.stderr
result = run("\n[dependencies]\nshared.workspace = true\n", '"app-b", "app-a"')
assert result.returncode == 1, result.stderr
-assert "rust/Cargo.toml: workspace.members 'app-b' precedes 'app-a'; sort members" in result.stderr
+assert "rust/Cargo.toml: workspace.members must be sorted: 'app-b' precedes 'app-a'" in result.stderr
result = run("\n[dependencies]\nshared.workspace = true\n", '"app-a", "app-b"')
assert result.returncode == 0, result.stderr
@@ -116,3 +116,28 @@ assert "rust/app-b/Cargo.toml: use edition.workspace = true" in result.stderr
result = run("", app_b_package=package.replace("\n[lints]\nworkspace = true\n", ""))
assert result.returncode == 1, result.stderr
assert "rust/app-b/Cargo.toml: use [lints] workspace = true" in result.stderr
+
+for section in (
+ "dependencies",
+ "dev-dependencies",
+ "build-dependencies",
+ "target.'cfg(unix)'.dependencies",
+):
+ result = run(f"\n[{section}]\nshared.workspace = true\nserde.workspace = true\n")
+ assert result.returncode == 1, result.stderr
+ table = section.replace("'", "")
+ assert f"{table} must be sorted" in result.stderr
+
+result = run("", workspace_toml=workspace.replace(
+ 'serde = "1.0.0"\nshared = { path = "shared" }',
+ 'shared = { path = "shared" }\nserde = "1.0.0"',
+))
+assert result.returncode == 1, result.stderr
+assert "workspace.dependencies must be sorted" in result.stderr
+
+result = run("\n[features]\nzeta = []\nalpha = []\n")
+assert result.returncode == 1, result.stderr
+assert "features must be sorted" in result.stderr
+
+result = run("\n[features]\nalpha = []\nzeta = []\n")
+assert result.returncode == 0, result.stderr
diff --git a/rust/checks/dependency-boundaries/check.mjs b/rust/checks/dependency-boundaries/check.mjs
index 4be8472c89..b42c0a885e 100644
--- a/rust/checks/dependency-boundaries/check.mjs
+++ b/rust/checks/dependency-boundaries/check.mjs
@@ -26,10 +26,13 @@ const domain = metadata.packages.filter((pkg) =>
);
const httpOwners = new Set([
- "rust/crates/core/Cargo.toml",
"rust/crates/assets/Cargo.toml",
+ "rust/crates/core/Cargo.toml",
"rust/tools/location-dataset/Cargo.toml",
]);
+if ([...httpOwners].some((path, i, paths) => i > 0 && paths[i - 1] > path)) {
+ throw new Error("httpOwners must be sorted");
+}
for (const pkg of metadata.packages) {
const manifest = pathFromRoot(pkg.manifest_path);
diff --git a/rust/crates/core/Cargo.toml b/rust/crates/core/Cargo.toml
index 7715750f78..d487e435e1 100644
--- a/rust/crates/core/Cargo.toml
+++ b/rust/crates/core/Cargo.toml
@@ -28,17 +28,17 @@ x25519-dalek = { version = "3.0.0", features = ["static_secrets"] }
zeroize.workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-reqwest = { workspace = true, features = ["stream"] }
bytes = "1.11.1"
futures-core = "0.3.32"
+reqwest = { workspace = true, features = ["stream"] }
tokio = { workspace = true, features = ["time"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
gloo-timers = { version = "0.3.0", features = ["futures"] }
[dev-dependencies]
-tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
mockito.workspace = true
+tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
[lints]
workspace = true