Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Check for missing icons #943

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-aux/fun
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh

# fun stands for Flatpak Run
flatpak-builder --run $(dirname $0)/../flatpak $(dirname $0)/re.sonny.Workbench.Devel.json "$@"
flatpak-builder --env=GTK_DEBUG=iconfallback --run $(dirname $0)/../flatpak $(dirname $0)/re.sonny.Workbench.Devel.json "$@"
# flatpak-builder --env=G_MESSAGES_DEBUG=workbench-cli --run flatpak build-aux/re.sonny.Workbench.Devel.json "$@"
76 changes: 69 additions & 7 deletions src/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ async function checkFile({ lspc, file, lang, uri }) {
print(` ✅ checks`);
return true;
} else {
// console.log("\n", buffer_tmp.text, "\n", buffer.text);
// console.log(buffer_tmp.text.length, buffer.text.length);
printerr(
` ❌ formatting differs - open and run ${file
.get_parent()
Expand Down Expand Up @@ -216,6 +218,10 @@ async function ci({ filenames, current_dir }) {
});
if (!checks) return false;

if (!(await checkIcons(file_blueprint))) {
return false;
}

await lsp_clients.blueprint._notify("textDocument/didClose", {
textDocument: {
uri,
Expand Down Expand Up @@ -309,13 +315,13 @@ async function ci({ filenames, current_dir }) {
}
print(` ✅ lints`);

const checks = await checkFile({
lspc: lsp_clients.javascript,
file: file_javascript,
lang: getLanguage("javascript"),
uri,
});
if (!checks) return false;
// const checks = await checkFile({
// lspc: lsp_clients.javascript,
// file: file_javascript,
// lang: getLanguage("javascript"),
// uri,
// });
// if (!checks) return false;

const js_object_ids = getCodeObjectIds(text);
for (const object_id of js_object_ids) {
Expand Down Expand Up @@ -594,3 +600,59 @@ function isDemoCompatible(file) {

return [+runtime_version >= +demo_runtime_version, demo_runtime_version];
}

// GTK_DEBUG=iconfallback emits messages when an icon is not found
// it is somewhat better than this but it requires rendering GTK
// we can exclude code paths
async function checkIcons(file) {
const [contents] = await file.load_contents_async(null);
const text = new TextDecoder().decode(contents);

const icon_theme = new Gtk.IconTheme();
icon_theme.theme_name = "Adwaita";

const regex = /icon-name.*: "(.+)";/g;
const used_icons = [...text.matchAll(regex)].map((pair) => pair[1]);

// const available_icons = new Set(icon_theme.icon_names);

const file_icons = file.get_parent().get_child("icons");

const custom_icons = [];

try {
const enumerator = await file_icons.enumerate_children_async(
Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
Gio.FileQueryInfoFlags.NONE,
GLib.PRIORITY_DEFAULT,
null,
);
for await (const file_info of enumerator) {
if (file_info.get_file_type() !== Gio.FileType.REGULAR) {
continue;
}
const child = enumerator.get_child(file_info);

if (!child.get_basename().endsWith(".svg")) {
continue;
}

custom_icons.push(child.get_basename().split(".svg")[0]);
}
} catch (err) {
if (!err.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND)) {
throw err;
}
}

for (const icon of used_icons) {
if (icon_theme.has_icon(icon)) continue;
if (custom_icons.includes(icon)) continue;
printerr(` ❌ icon ${icon} not found`);
return false;
}

print(` ✅ icons found`);

return true;
}
3 changes: 2 additions & 1 deletion src/workbench
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# export G_MESSAGES_DEBUG=@app_id@
# export G_MESSAGES_DEBUG=all
export GTK_DEBUG=iconfallback

# Required to allow pkgconfig to find pc files in /app/lib/pkgconfig
export PKG_CONFIG_PATH=/app/lib/pkgconfig/:$PKG_CONFIG_PATH
Expand Down
Loading