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

bazel - added rules player back for docs site #470

Merged
merged 12 commits into from
Aug 2, 2024
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ bazel_dep(name = "rules_player")

archive_override(
module_name = "rules_player",
strip_prefix = "rules_player-1.0.1",
urls = ["https://github.com/player-ui/rules_player/archive/refs/tags/v1.0.1.tar.gz"],
integrity = "sha256-zIbxx1Bh/X4E8OwbPJz1nY9mOd2uAgmTZyf1Hs2mq+U="
strip_prefix = "rules_player-1.1.0",
urls = ["https://github.com/player-ui/rules_player/archive/refs/tags/v1.1.0.tar.gz"],
mercillo marked this conversation as resolved.
Show resolved Hide resolved
integrity = "sha256-LwCE/dbbQUtpkIZedhtgJ5MwCjn5G00XO5LFxq09i7k="
)
#local_path_override(module_name = "rules_player", path = "../rules_player")

Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
workspace(name = "player")
workspace(name = "player")
2 changes: 1 addition & 1 deletion WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ http_file(
name = "android_test_services_apk",
sha256 = "c6bc74268b29bdabad8da962e00e2f6fd613c24b42c69e81b258397b4819f156",
url = "https://dl.google.com/android/maven2/androidx/test/services/test-services/1.4.2/test-services-1.4.2.apk"
)
)
27 changes: 27 additions & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@rules_player//distribution/tar:defs.bzl", "stamp_tar_files")
load("@rules_player//gh-pages:defs.bzl","gh_pages")

genrule(
name = "full_site",
Expand All @@ -18,4 +20,29 @@ genrule(
chmod -R u+rwX,a+rX $$tmp_dir &&
tar -czhf $@ -C $$tmp_dir .
"""
)

stamp_tar_files(
name = "full_site_stamped",
tar = ":full_site",
substitutions = {
"NEXT_PUBLIC_GA_MEASUREMENT_ID": "{STABLE_GA_MEASUREMENT_ID}",
"DOCS_BASE_PATH": "{STABLE_DOCS_BASE_PATH}",
"ALGOLIA_SEARCH_API_KEY": "{STABLE_ALGOLIA_SEARCH_API_KEY}",
},
)

genrule(
name = "get_version",
srcs = ["//:VERSION"],
outs = ["VERSION"],
cmd = "cat $(SRCS) > $@"
)

gh_pages(
name="gh_deploy",
source_dir="$(location :full_site_stamped)",
repo="player-ui/player-ui.github.io",
data = [":full_site_stamped", ":get_version"],
version = "$(location :get_version)",
)
7 changes: 4 additions & 3 deletions docs/site/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const useSearch = () => {
.slice(0, 10)
.map((r) => {
return searchIndex.searchIndex[r.ref];
});
})
.filter((e) => e !== undefined);

setResults(searchResults);
}
Expand Down Expand Up @@ -103,7 +104,7 @@ const SearchResult = (props: SearchIndex) => {
);
};

export const FallbackSearchInput = () => {
export const FallbackSearchInput = (): React.JSX.Element => {
const { search, results, clear } = useSearch();
const [searchActive, setSearchActive] = React.useState(false);
const [query, setQuery] = React.useState("");
Expand Down Expand Up @@ -162,7 +163,7 @@ export const FallbackSearchInput = () => {
);
};

export const SearchInput = () => {
export const SearchInput = (): React.JSX.Element => {
// Only use algolia search if we're on the /latest/ version
// it's the only one that's indexed
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { FlowManager, CompletedState, Flow } from '@player-ui/react';
import flow1 from './flow-1.json';
import flow2 from './flow-2.json';
import flow3 from './flow-3.json';
import {
FlowManager,
CompletedState,
Flow,
FinalState,
} from "@player-ui/react";
import flow1 from "./flow-1.json";
import flow2 from "./flow-2.json";
import flow3 from "./flow-3.json";

const basicFlows = [flow1, flow2, flow3];

Expand All @@ -16,24 +21,26 @@ export function createStaticFlowManager(flows: Array<Flow>): FlowManager {
return {
next: async (previousResult?: CompletedState) => {
if (!previousResult) {
return { value: flows[0] };
const firstFlow = flows[0] as Flow;
return { done: false, value: firstFlow };
}

const prevIndex = flows.findIndex((v) => v.id === previousResult.flow.id);
const nextIndex =
prevIndex + (previousResult.endState.outcome === 'back' ? -1 : 1);
prevIndex + (previousResult.endState.outcome === "back" ? -1 : 1);

if (nextIndex < 0 || nextIndex >= flows.length) {
return { done: true };
return { done: true } as FinalState;
}

await delay(Math.random() * 500);

return { value: flows[nextIndex] };
const nextFlow = flows[nextIndex] as Flow;
return { done: false, value: nextFlow };
},
};
}

export const basicFlowManager = createStaticFlowManager(
basicFlows as Array<Flow>
export const basicFlowManager: FlowManager = createStaticFlowManager(
basicFlows as Array<Flow>,
);
2 changes: 2 additions & 0 deletions docs/storybook/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ deps = [
"//:node_modules/@babel/preset-env",
"//:node_modules/@storybook/react-webpack5",
"//:node_modules/@storybook/addon-docs",
"//:node_modules/@storybook/components",
"//:node_modules/@storybook/manager-api",
"//:node_modules/@types/react-redux",
"//:node_modules/react-redux",
"//:node_modules/redux-state-sync",
Expand Down
18 changes: 9 additions & 9 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ bazel run @rules_player//distribution:staged-maven-deploy -- "$RELEASE_TYPE" --p
# Make sure to re-stamp the outputs with the BASE_PATH so nextjs knows what to do with links

# Commented out as it needs to be re-written
#if [ "$RELEASE_TYPE" == "snapshot" ] && [ "$CURRENT_BRANCH" == "main" ]; then
# STABLE_DOCS_BASE_PATH=next bazel run --verbose_failures --config=release //docs:deploy_docs -- --dest_dir next
#elif [ "$RELEASE_TYPE" == "release" ] && [ "$CURRENT_BRANCH" == "main" ]; then
# STABLE_DOCS_BASE_PATH=latest bazel run --verbose_failures --config=release //docs:deploy_docs -- --dest_dir latest
#fi
if [ "$RELEASE_TYPE" == "snapshot" ] && [ "$CURRENT_BRANCH" == "main" ]; then
STABLE_DOCS_BASE_PATH=next bazel run --verbose_failures --config=release //docs:gh_deploy -- --dest_dir next
elif [ "$RELEASE_TYPE" == "release" ] && [ "$CURRENT_BRANCH" == "main" ]; then
STABLE_DOCS_BASE_PATH=latest bazel run --verbose_failures --config=release //docs:gh_deploy -- --dest_dir latest
fi

# Commented out for now due to failures to deploy
# causes lots of "java.io.IOException: io.grpc.StatusRuntimeException: CANCELLED: Failed to read message." messages in the build
# Also deploy to the versioned folder for main releases
# if [ "$RELEASE_TYPE" == "release" ]; then
# SEMVER_MAJOR=$(cat VERSION | cut -d. -f1)
# STABLE_DOCS_BASE_PATH=$SEMVER_MAJOR bazel run --verbose_failures --config=release //docs:deploy_docs -- --dest_dir "$SEMVER_MAJOR"
# fi
if [ "$RELEASE_TYPE" == "release" ]; then
SEMVER_MAJOR=$(cat VERSION | cut -d. -f1)
STABLE_DOCS_BASE_PATH=$SEMVER_MAJOR bazel run --verbose_failures --config=release //docs:gh_deploy -- --dest_dir "$SEMVER_MAJOR"
fi
Loading