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

Switch to a new progress event for build status #55

Closed

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Aug 29, 2023

Using the new onTaskProgress option, switch to a more full featured BUILD_PROGRESS event chromaui/chromatic-cli#805.

📦 Published PR as canary version: 0.0.42--canary.55.36a4f81.0

✨ Test out this PR locally via:

npm install @chromaui/addon-visual-tests@0.0.42--canary.55.36a4f81.0
# or 
yarn add @chromaui/addon-visual-tests@0.0.42--canary.55.36a4f81.0

Comment on lines +72 to +84
let newStep: BuildProgressPayload["step"];
if (step === "initialize" && ctx.announcedBuild) {
newStep = "build";
}
if (announced && !started && ctx.build) {
console.debug("emitting", BUILD_STARTED, ctx.build.status);
channel.emit(BUILD_STARTED, ctx.build.status);
started = true;
if (step === "upload" && ctx.isolatorUrl) {
newStep = "verify";
}
if (["build", "upload"].includes(step) && ctx.build) {
newStep = "snapshot";
}
if (ctx.build?.status !== "IN_PROGRESS") {
newStep = "complete";
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure about this logic, @ghengeveld do you have a better idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not digging the let newStep. I'd rather have a function that returns the new step.

As you know I don't like let at all. I can sort of let it slide when it's used for memory storage over time (such as step above), but not when it's used with a series of if statements to (synchronously) determine its final value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what I'd like to see is a map (or other iteration) of steps, each specifying how they'd react to onTaskComplete and/or onTaskProgress events. Something like:

const steps = {
  _current: steps.announce,

  go(ctx, step) {
    channel.emit(BUILD_PROGRESS, { step, buildId: ctx.announcedBuild?.id });
    steps._current = steps[step];
  },

  announce: {
    onTaskComplete(ctx) {
      if (ctx.announcedBuild) steps.go(ctx, "build");
    }
  },
  build: {
    onTaskProgress(ctx, data) {
      if (data.unit === "bytes") {
        steps.go(ctx, "publish");
        steps.publish.onTaskProgress(ctx, data);
      };
    }
  },
  publish: {
    onTaskComplete(ctx) {
      if (ctx.isolatorUrl) steps.go(ctx, "verify");
    },
    onTaskProgress({ announcedBuild }, { progress, total, unit }) {
      channel.emit(BUILD_PROGRESS, { ... });
    }
  },
  verify: {
    onTaskComplete({ build }) {
      if (build) steps.go(ctx, "test");
    },
  },
  test: {
    onTaskComplete({ build }) {
      if (build.completedAt) steps.go(ctx, "complete");
    },
    onTaskProgress({ announcedBuild }, { progress, total, unit }) {
      channel.emit(BUILD_PROGRESS, { ... });
    }
  },
  complete: {}
}

Note I also renamed initialize to announce and snapshot to test.

@tmeasday tmeasday mentioned this pull request Aug 29, 2023

export function BuildStatus({}) {
return <div>Build Status</div>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentionally unfinished?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is a second PR that actually implements the UI: #56

// build: passedBuild,
},
parameters: withFigmaDesign(
"https://www.figma.com/file/GFEbCgCVDtbZhngULbw2gP/Visual-testing-in-Storybook?type=design&node-id=508-525764&t=18c1zI1SMe76dWYk-4"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to link to the "Render settings" screen?

Comment on lines +72 to +84
let newStep: BuildProgressPayload["step"];
if (step === "initialize" && ctx.announcedBuild) {
newStep = "build";
}
if (announced && !started && ctx.build) {
console.debug("emitting", BUILD_STARTED, ctx.build.status);
channel.emit(BUILD_STARTED, ctx.build.status);
started = true;
if (step === "upload" && ctx.isolatorUrl) {
newStep = "verify";
}
if (["build", "upload"].includes(step) && ctx.build) {
newStep = "snapshot";
}
if (ctx.build?.status !== "IN_PROGRESS") {
newStep = "complete";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not digging the let newStep. I'd rather have a function that returns the new step.

As you know I don't like let at all. I can sort of let it slide when it's used for memory storage over time (such as step above), but not when it's used with a series of if statements to (synchronously) determine its final value.

Comment on lines +72 to +84
let newStep: BuildProgressPayload["step"];
if (step === "initialize" && ctx.announcedBuild) {
newStep = "build";
}
if (announced && !started && ctx.build) {
console.debug("emitting", BUILD_STARTED, ctx.build.status);
channel.emit(BUILD_STARTED, ctx.build.status);
started = true;
if (step === "upload" && ctx.isolatorUrl) {
newStep = "verify";
}
if (["build", "upload"].includes(step) && ctx.build) {
newStep = "snapshot";
}
if (ctx.build?.status !== "IN_PROGRESS") {
newStep = "complete";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what I'd like to see is a map (or other iteration) of steps, each specifying how they'd react to onTaskComplete and/or onTaskProgress events. Something like:

const steps = {
  _current: steps.announce,

  go(ctx, step) {
    channel.emit(BUILD_PROGRESS, { step, buildId: ctx.announcedBuild?.id });
    steps._current = steps[step];
  },

  announce: {
    onTaskComplete(ctx) {
      if (ctx.announcedBuild) steps.go(ctx, "build");
    }
  },
  build: {
    onTaskProgress(ctx, data) {
      if (data.unit === "bytes") {
        steps.go(ctx, "publish");
        steps.publish.onTaskProgress(ctx, data);
      };
    }
  },
  publish: {
    onTaskComplete(ctx) {
      if (ctx.isolatorUrl) steps.go(ctx, "verify");
    },
    onTaskProgress({ announcedBuild }, { progress, total, unit }) {
      channel.emit(BUILD_PROGRESS, { ... });
    }
  },
  verify: {
    onTaskComplete({ build }) {
      if (build) steps.go(ctx, "test");
    },
  },
  test: {
    onTaskComplete({ build }) {
      if (build.completedAt) steps.go(ctx, "complete");
    },
    onTaskProgress({ announcedBuild }, { progress, total, unit }) {
      channel.emit(BUILD_PROGRESS, { ... });
    }
  },
  complete: {}
}

Note I also renamed initialize to announce and snapshot to test.

@tmeasday
Copy link
Member Author

I'm going to take a second pass over this once I've figured out the server->manager/preview use addon state (as I will store this build progress information in addon state).

@weeksling I will leave this PR so you can base any UI work on it but be aware I am going to change quite a lot of things later (probably in a distinct PR).

@tmeasday
Copy link
Member Author

tmeasday commented Sep 5, 2023

This was merged as part of #69 with a lot of changes.

@tmeasday tmeasday closed this Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants