Skip to content

Commit

Permalink
Merge branch 'main' into feature/plugin-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnNiang authored Sep 20, 2023
2 parents 9fce449 + 7de97e4 commit 5881da9
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/halo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ jobs:
ghcr-token: ${{ secrets.GHCR_TOKEN }}
dockerhub-user: ${{ secrets.DOCKER_USERNAME }}
dockerhub-token: ${{ secrets.DOCKER_TOKEN }}
push: ${{ github.event_name == 'push' || github.event_name == 'release' }} # we only push to GHCR if the push is to the next branch
push: ${{ github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'release' }}
console-ref: ${{ github.event_name == 'release' && github.ref || 'main' }}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.Validate;
import org.pf4j.PluginWrapper;
import org.pf4j.RuntimeMode;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -186,10 +187,15 @@ public Mono<String> uglifyCssBundle() {
@Override
public Mono<String> generateJsBundleVersion() {
return Mono.fromSupplier(() -> {
if (RuntimeMode.DEVELOPMENT.equals(pluginManager.getRuntimeMode())) {
return String.valueOf(System.currentTimeMillis());
}
var compactVersion = pluginManager.getStartedPlugins()
.stream()
.sorted(Comparator.comparing(PluginWrapper::getPluginId))
.map(pluginWrapper -> pluginWrapper.getDescriptor().getVersion())
.map(pluginWrapper -> pluginWrapper.getPluginId() + ":"
+ pluginWrapper.getDescriptor().getVersion()
)
.collect(Collectors.joining());
return Hashing.sha256().hashUnencodedChars(compactVersion).toString();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import static org.mockito.Mockito.when;

import com.github.zafarkhaja.semver.Version;
import com.google.common.hash.Hashing;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
Expand All @@ -27,8 +29,10 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.pf4j.PluginDescriptor;
import org.pf4j.PluginState;
import org.pf4j.PluginWrapper;
import org.pf4j.RuntimeMode;
import org.springframework.web.server.ServerWebInputException;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
Expand Down Expand Up @@ -226,4 +230,59 @@ void reload() {
);
verify(pluginWrapper, times(1)).getPluginPath();
}

@Test
void generateJsBundleVersionTest() {
when(pluginManager.getRuntimeMode()).thenReturn(RuntimeMode.DEVELOPMENT);

pluginService.generateJsBundleVersion()
.as(StepVerifier::create)
.consumeNextWith(version -> assertThat(version).isNotNull())
.verifyComplete();

when(pluginManager.getRuntimeMode()).thenReturn(RuntimeMode.DEPLOYMENT);
var plugin1 = mock(PluginWrapper.class);
var plugin2 = mock(PluginWrapper.class);
var plugin3 = mock(PluginWrapper.class);
when(pluginManager.getStartedPlugins()).thenReturn(List.of(plugin1, plugin2, plugin3));

var descriptor1 = mock(PluginDescriptor.class);
var descriptor2 = mock(PluginDescriptor.class);
var descriptor3 = mock(PluginDescriptor.class);
when(plugin1.getDescriptor()).thenReturn(descriptor1);
when(plugin2.getDescriptor()).thenReturn(descriptor2);
when(plugin3.getDescriptor()).thenReturn(descriptor3);

when(plugin1.getPluginId()).thenReturn("fake-1");
when(plugin2.getPluginId()).thenReturn("fake-2");
when(plugin3.getPluginId()).thenReturn("fake-3");

when(descriptor1.getVersion()).thenReturn("1.0.0");
when(descriptor2.getVersion()).thenReturn("2.0.0");
when(descriptor3.getVersion()).thenReturn("3.0.0");

var str = "fake-1:1.0.0fake-2:2.0.0fake-3:3.0.0";
var result = Hashing.sha256().hashUnencodedChars(str).toString();
assertThat(result.length()).isEqualTo(64);

pluginService.generateJsBundleVersion()
.as(StepVerifier::create)
.consumeNextWith(version -> assertThat(version).isEqualTo(result))
.verifyComplete();

var plugin4 = mock(PluginWrapper.class);
var descriptor4 = mock(PluginDescriptor.class);
when(plugin4.getDescriptor()).thenReturn(descriptor4);
when(plugin4.getPluginId()).thenReturn("fake-4");
when(descriptor4.getVersion()).thenReturn("3.0.0");
var str2 = "fake-1:1.0.0fake-2:2.0.0fake-4:3.0.0";
var result2 = Hashing.sha256().hashUnencodedChars(str2).toString();
when(pluginManager.getStartedPlugins()).thenReturn(List.of(plugin1, plugin2, plugin4));
pluginService.generateJsBundleVersion()
.as(StepVerifier::create)
.consumeNextWith(version -> assertThat(version).isEqualTo(result2))
.verifyComplete();

assertThat(result).isNotEqualTo(result2);
}
}
17 changes: 8 additions & 9 deletions console/packages/components/src/components/dialog/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
IconForbidLine,
IconInformation,
} from "../../icons/icons";
import { computed, ref } from "vue";
import { ref, type Component, markRaw, type Raw } from "vue";
import type { Type } from "@/components/dialog/interface";
import type { Type as ButtonType } from "@/components/button/interface";
Expand Down Expand Up @@ -48,25 +48,24 @@ const emit = defineEmits<{
(event: "close"): void;
}>();
const icons = {
const icons: Record<Type, { icon: Raw<Component>; color: string }> = {
success: {
icon: IconCheckboxCircle,
icon: markRaw(IconCheckboxCircle),
color: "green",
},
info: {
icon: IconInformation,
icon: markRaw(IconInformation),
color: "blue",
},
warning: {
icon: IconErrorWarning,
icon: markRaw(IconErrorWarning),
color: "orange",
},
error: {
icon: IconForbidLine,
icon: markRaw(IconForbidLine),
color: "red",
},
};
const icon = computed(() => icons[props.type]);
const loading = ref(false);
Expand Down Expand Up @@ -108,8 +107,8 @@ const handleClose = () => {
<div class="flex justify-between items-start py-2 mb-2">
<div class="flex flex-row items-center gap-3">
<component
:is="icon.icon"
:class="`text-${icon.color}-500`"
:is="icons[type].icon"
:class="`text-${icons[type].color}-500`"
class="w-6 h-6"
></component>
<div class="text-base text-gray-900 font-bold">{{ title }}</div>
Expand Down
23 changes: 14 additions & 9 deletions console/packages/components/src/components/toast/Toast.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<script lang="ts" setup>
import type { Type } from "./interface";
import { computed, onMounted, ref, watchEffect } from "vue";
import {
onMounted,
ref,
watchEffect,
type Raw,
type Component,
markRaw,
} from "vue";
import {
IconCheckboxCircle,
IconErrorWarning,
Expand Down Expand Up @@ -36,27 +43,25 @@ const emit = defineEmits<{
(event: "close"): void;
}>();
const icons = {
const icons: Record<Type, { icon: Raw<Component>; color: string }> = {
success: {
icon: IconCheckboxCircle,
icon: markRaw(IconCheckboxCircle),
color: "text-green-500",
},
info: {
icon: IconInformation,
icon: markRaw(IconInformation),
color: "text-sky-500",
},
warning: {
icon: IconErrorWarning,
icon: markRaw(IconErrorWarning),
color: "text-orange-500",
},
error: {
icon: IconForbidLine,
icon: markRaw(IconForbidLine),
color: "text-red-500",
},
};
const icon = computed(() => icons[props.type]);
const createTimer = () => {
if (props.duration < 0) return;
timer.value = setTimeout(() => {
Expand Down Expand Up @@ -115,7 +120,7 @@ defineExpose({ close });
>
<div class="toast-body">
<div class="toast-icon">
<component :is="icon.icon" :class="[icon.color]" />
<component :is="icons[type].icon" :class="icons[type].color" />
</div>
<div class="toast-content">
<div class="toast-description">
Expand Down

0 comments on commit 5881da9

Please sign in to comment.