Skip to content

Commit

Permalink
Merge pull request #53 from bioimage-io/remove-uploader-before-valida…
Browse files Browse the repository at this point in the history
…tion

fix: remove uploader from rdf before validation, closes #52
  • Loading branch information
jmetz authored Feb 14, 2024
2 parents 83edde4 + a845e14 commit 62da14f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion functions/notify_ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default async (event, context) => {
console.error(GITHUB_URL);
console.error(err);
const res = Response.json(
{ 'message': `Failed: ${err.message}` },
{ 'message': `Failed to fetch from CI endpoint: ${err.message}` },
{ status: 500 });
res.headers.set("Access-Control-Allow-Origin", "*");
res.headers.append("Access-Control-Allow-Headers", "*");
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"imjoy-rpc": "^0.5.44",
"jszip": "^3.10.1",
"lucide-svelte": "^0.294.0",
"netlify-cli": "^17.16.2",
"playwright": "^1.40.1",
"sass": "^1.70.0",
"spdx-license-list": "^6.8.0",
Expand All @@ -35,6 +36,5 @@
"tinro": "^0.6.12",
"vite": "^5.0.8",
"vitest": "^1.0.4"
},
"dependencies": {}
}
}
24 changes: 18 additions & 6 deletions src/lib/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const regex_rdf = /(rdf\.yml|rdf\.yaml|bioimage\.yml|bioimage\.yaml)$/gi;
const hostname = `${window.location.protocol}//${window.location.host}`;
const generate_name_url = `${hostname}/.netlify/functions/generate_name`;
const notify_ci_url = `${hostname}/.netlify/functions/notify_ci`;
const validator_url = "https://raw.githubusercontent.com/bioimage-io/spec-bioimage-io/main/scripts/bio-rdf-validator.imjoy.html"
//const validator_url = `${hostname}/static/bio-rdf-validator.imjoy.html`



export enum UploaderStep {
Expand Down Expand Up @@ -232,7 +235,7 @@ export class Uploader {
load_validator() {
if (this.validator) return this.validator;
this.validator = this.api.getPlugin(
"https://raw.githubusercontent.com/jmetz/spec-bioimage-io/dev/scripts/bio-rdf-validator.imjoy.html"
validator_url
);
return this.validator;
}
Expand All @@ -245,8 +248,14 @@ export class Uploader {
const validator = await this.load_validator();
let rdf = yaml.load(yaml.dump(this.rdf));
rdf = clean_rdf(rdf);

console.log("RDF after cleaning: ", rdf);
const results = await validator.validate(rdf);

console.warn("STRIPPING UNSUPPORTED FIELDS IN RDF: TODO - THIS SHOULD BE A TEMPORARY FIX");
const rdf_copy = { ...rdf }
delete rdf_copy.uploader;

const results = await validator.validate(rdf_copy);
if (results.error) {
throw new Error(results.error);
}
Expand Down Expand Up @@ -277,7 +286,7 @@ export class Uploader {
console.log("Generated name:", model_name);
const error = "";
this.resource_path = model_name;
this.rdf.nickname = model_name.name;
this.rdf.nickname = model_name.id;
return { model_name, error };
} catch (err) {
console.error("Failed to generate name:")
Expand Down Expand Up @@ -401,8 +410,8 @@ export class Uploader {
console.error("Nofiying the ci-bot failed:");
console.error(err);
this.error_object = err;
this.status.message = err.message,
this.status.step = UploaderStep.FAILED;
this.status.message = err.message;
this.status.step = UploaderStep.FAILED;
this.render();
return
}
Expand All @@ -424,15 +433,18 @@ export class Uploader {
console.error("notify_ci_url not set")
throw new Error("notify_ci_url not set");
}
const payload = { 'resource_path': this.resource_path!.id, 'package_url': this.zip_urls!.get};
this.status.message = "⌛ Trying to notify bioimage-bot for the new item...";
this.status.step = UploaderStep.NOTIFYING_CI;
this.render();
console.debug("Notifying CI bot using:");
console.debug(payload)
// trigger CI with the bioimageio bot endpoint
try {
const resp = await fetch(notify_ci_url, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ 'resource_path': this.resource_path!.id, 'package_url': this.zip_urls!.get })
body: JSON.stringify(payload)
});
if (resp.status === 200) {
const ci_resp = (await resp.json());
Expand Down

0 comments on commit 62da14f

Please sign in to comment.