Skip to content

Commit 5f52cba

Browse files
committed
chore(tools): add cargo package metadata; fix formatting and clippy unused-result fixes
1 parent 76e44da commit 5f52cba

8 files changed

Lines changed: 212 additions & 22 deletions

File tree

.github/workflows/publish-snapshot.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ jobs:
7373
jq . "$OUT" || true
7474
exit 1
7575
fi
76-
# ensure each object has id and name fields
77-
if ! jq -e '.[0] | has("id") and has("name")' "$OUT" >/dev/null; then
78-
echo "Snapshot entries appear to be missing required fields (id/name)"
79-
jq '.[0]' "$OUT" || true
76+
# ensure every object has non-empty string id and name fields
77+
if ! jq -e 'all(.[]; (has("id") and has("name") and (.id|type=="string") and (.name|type=="string") and (.id != "") and (.name != "")))' "$OUT" >/dev/null; then
78+
echo "Snapshot validation failed: one or more entries are missing required fields 'id' or 'name', or they are empty/non-string"
79+
# Show up to first 5 offending entries
80+
jq 'map(select( (has("id")|not) or (has("name")|not) or (.id|type!="string") or (.name|type!="string") or (.id=="") or (.name=="") )) | .[0:5]' "$OUT" || true
8081
exit 1
8182
fi
8283

Cargo.lock

Lines changed: 150 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ default = []
127127
validate-metadata = []
128128
sync-tool = ["reqwest", "tokio", "regex"]
129129

130+
[workspace]
131+
members = [
132+
"tools/linguist_to_snapshot",
133+
"tools/generate_snapshot_job",
134+
]
135+
130136
[build-dependencies]
131137

132138
# ═══════════════════════════════════════════════════════════════════════════

tools/generate_snapshot_job/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
name = "generate_snapshot_job"
33
version = "0.1.0"
44
edition = "2021"
5+
description = "Wrapper CLI used in CI to generate the canonical snapshot by invoking the linguist_to_snapshot converter."
6+
license = "MIT OR Apache-2.0"
7+
repository = "https://github.com/Singularity-ng/singularity-language-registry"
8+
readme = "../../README.md"
9+
keywords = ["snapshot", "ci", "linguist"]
10+
categories = ["command-line-utilities", "development-tools"]
511

612
[dependencies]
713
anyhow = "1.0"

tools/generate_snapshot_job/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use clap::Parser;
3-
use std::process::Command;
43
use std::path::PathBuf;
4+
use std::process::Command;
55

66
#[derive(Parser)]
77
struct Args {

tools/linguist_sync.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn parse_vendor_yml(content: &str) -> HashSet<String> {
6262
.to_string();
6363

6464
if !cleaned.is_empty() && !cleaned.contains('(') && cleaned.len() < 100 {
65-
patterns.insert(cleaned);
65+
let _ = patterns.insert(cleaned);
6666
}
6767
}
6868
}
@@ -88,7 +88,7 @@ fn parse_generated_rb(content: &str) -> HashSet<String> {
8888
if let Some(matched) = cap.get(1) {
8989
let pattern = matched.as_str().to_string();
9090
if pattern.len() < 100 && !pattern.contains("//") {
91-
patterns.insert(pattern);
91+
let _ = patterns.insert(pattern);
9292
}
9393
}
9494
}
@@ -118,7 +118,7 @@ fn parse_heuristics_yml(content: &str) -> HashMap<String, Vec<String>> {
118118
// Save previous extension's patterns
119119
if let Some(ext) = current_extension.take() {
120120
if !patterns.is_empty() {
121-
heuristics.insert(ext, patterns.clone());
121+
let _ = heuristics.insert(ext, patterns.clone());
122122
patterns.clear();
123123
}
124124
}
@@ -142,7 +142,7 @@ fn parse_heuristics_yml(content: &str) -> HashMap<String, Vec<String>> {
142142
// Save last extension
143143
if let Some(ext) = current_extension {
144144
if !patterns.is_empty() {
145-
heuristics.insert(ext, patterns);
145+
let _ = heuristics.insert(ext, patterns);
146146
}
147147
}
148148

@@ -166,16 +166,16 @@ fn categorize_patterns(
166166
if pattern.starts_with('.') && pattern.len() < 10 {
167167
// It's an extension
168168
if binary_exts.contains(&pattern.as_str()) {
169-
binary.insert(pattern.clone());
169+
let _ = binary.insert(pattern.clone());
170170
} else if pattern.contains("pb")
171171
|| pattern.contains("generated")
172172
|| pattern.contains("proto")
173173
{
174-
generated.insert(pattern.clone());
174+
let _ = generated.insert(pattern.clone());
175175
}
176176
} else {
177177
// It's a path
178-
vendored.insert(pattern.clone());
178+
let _ = vendored.insert(pattern.clone());
179179
}
180180
}
181181

tools/linguist_to_snapshot/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
name = "linguist_to_snapshot"
33
version = "0.1.0"
44
edition = "2021"
5+
description = "Convert GitHub Linguist languages.yml/JSON into the registry snapshot JSON format."
6+
license = "MIT OR Apache-2.0"
7+
repository = "https://github.com/Singularity-ng/singularity-language-registry"
8+
readme = "../../README.md"
9+
keywords = ["linguist", "snapshot", "converter", "languages"]
10+
categories = ["command-line-utilities", "development-tools"]
511

612
[dependencies]
713
clap = { version = "4.2", features = ["derive"] }

tools/linguist_to_snapshot/src/main.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,40 @@ fn main() -> Result<()> {
7474
let id = k.as_str().unwrap_or_default().to_string();
7575
let name = id.clone();
7676
// Map some fields
77-
let extensions = v.get(&serde_yaml::Value::from("extensions")).and_then(|x| x.as_sequence()).map(|seq| {
78-
seq.iter().filter_map(|e| e.as_str().map(|s| s.to_string())).collect()
79-
}).unwrap_or_default();
77+
let extensions = v
78+
.get(&serde_yaml::Value::from("extensions"))
79+
.and_then(|x| x.as_sequence())
80+
.map(|seq| {
81+
seq.iter()
82+
.filter_map(|e| e.as_str().map(|s| s.to_string()))
83+
.collect()
84+
})
85+
.unwrap_or_default();
8086

81-
let aliases = v.get(&serde_yaml::Value::from("aliases")).and_then(|x| x.as_sequence()).map(|seq| {
82-
seq.iter().filter_map(|e| e.as_str().map(|s| s.to_string())).collect()
83-
}).unwrap_or_default();
87+
let aliases = v
88+
.get(&serde_yaml::Value::from("aliases"))
89+
.and_then(|x| x.as_sequence())
90+
.map(|seq| {
91+
seq.iter()
92+
.filter_map(|e| e.as_str().map(|s| s.to_string()))
93+
.collect()
94+
})
95+
.unwrap_or_default();
8496

85-
let mime_types = v.get(&serde_yaml::Value::from("mime_types")).and_then(|x| x.as_sequence()).map(|seq| {
86-
seq.iter().filter_map(|e| e.as_str().map(|s| s.to_string())).collect()
87-
}).unwrap_or_default();
97+
let mime_types = v
98+
.get(&serde_yaml::Value::from("mime_types"))
99+
.and_then(|x| x.as_sequence())
100+
.map(|seq| {
101+
seq.iter()
102+
.filter_map(|e| e.as_str().map(|s| s.to_string()))
103+
.collect()
104+
})
105+
.unwrap_or_default();
88106

89-
let tree_sitter_language = v.get(&serde_yaml::Value::from("tree_sitter_language")).and_then(|x| x.as_str()).map(|s| s.to_string());
107+
let tree_sitter_language = v
108+
.get(&serde_yaml::Value::from("tree_sitter_language"))
109+
.and_then(|x| x.as_str())
110+
.map(|s| s.to_string());
90111

91112
snapshots.push(SnapshotEntry {
92113
id,

0 commit comments

Comments
 (0)