Skip to content

Commit

Permalink
ci: Setup basic CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Gorantala committed Aug 8, 2024
1 parent 56c85ab commit c39172a
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 12 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI
run-name: ${{github.workflow}} (${{github.event_name}} on ${{ github.ref_name}})

on: [push, pull_request]

concurrency:
group: 'ci'
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: package.json

- name: Install dependencies
run: npm install

- name:
Verify the integrity of provenance attestations and registry signatures for installed
dependencies
run: npm audit signatures

- name: Build
run: npm run build --workspaces
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.next
node_modules
build
6 changes: 5 additions & 1 deletion examples/pixel/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
eslint: {
ignoreDuringBuilds: true,
},
};

export default nextConfig;
16 changes: 12 additions & 4 deletions examples/pixel/src/components/SearchBar.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import _ from 'lodash';
import { Suspense, useEffect, useState } from 'react';
import Link from 'next/link';
import { useRouter, useSearchParams } from 'next/navigation';
import { InputField, LoaderIcon, SearchIcon } from '@bloomreach/react-banana-ui';
import JsonView from '@uiw/react-json-view';
import Highlighter from 'react-highlight-words';
import Link from 'next/link';
import { useEffect, useState } from 'react';
import { useRouter, useSearchParams } from 'next/navigation';
import useAnalytics from '../hooks/useAnalytics';
import useAutosuggestApi from '../hooks/useAutosuggestApi';
import { CONFIG } from '../constants';

export function SearchBar() {
function SearchBarInner() {
const router = useRouter();
const searchParams = useSearchParams();
const { trackEvent } = useAnalytics();
Expand Down Expand Up @@ -154,3 +154,11 @@ export function SearchBar() {
</div>
);
}

export function SearchBar() {
return (
<Suspense>
<SearchBarInner />
</Suspense>
);
}
12 changes: 12 additions & 0 deletions examples/visual-search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ npm run dev
or:

[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/devbox/github/bloomreach/web-code-samples/tree/main/examples/visual-search)

## Troubleshooting

### Command does not support workspaces.

If you see this error when you run `npm run dev`
```
npm error code ENOWORKSPACES
npm error This command does not support workspaces.
```

run `npx next telemetry disable` to fix it
16 changes: 11 additions & 5 deletions examples/visual-search/app/fetch-image-url/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import {NextRequest, NextResponse} from "next/server";
export async function GET(req: NextRequest, res: NextResponse) {
try {
const {searchParams} = new URL(req.url);
const url = searchParams.get('url')
const url = searchParams.get('url');

if (!url) {
return res.status(400).json({message: 'url query parameter is required'});
return new NextResponse(JSON.stringify({message: 'url query parameter is required'}), {
status: 400,
headers: { 'Content-Type': 'application/json' }
});
}

const response = await fetch(url);
Expand All @@ -22,11 +25,14 @@ export async function GET(req: NextRequest, res: NextResponse) {
status: 200,
headers: {
'Content-Type': response.headers.get('content-type') || 'image/*',
'Content-Length': response.headers.get('content-length') || arr.length,
'Content-Length': response.headers.get('content-length') || String(arr.length),
},
})
} catch (e) {
} catch (e: any) {
console.error(e);
return new NextResponse.error(e);
return new NextResponse(JSON.stringify({ message: e.message || 'An error occurred' }), {
status: 500,
headers: { 'Content-Type': 'application/json' },
})
}
}
6 changes: 4 additions & 2 deletions examples/visual-search/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ export default function Home() {
}

const handleImageFileChange = async (event: ChangeEvent<HTMLInputElement>) => {
const file = event.currentTarget.files[0];
const file = event.currentTarget.files && event.currentTarget.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
setImageSrc(e.target.result);
if (e?.target?.result) {
setImageSrc(e.target.result.toString());
}
};
reader.readAsDataURL(file);
await uploadImage(file);
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@bloomreach/web-code-samples",
"private": true,
"workspaces": [
"examples/*"
],
"engines": {
"node": ">=20"
}
}

0 comments on commit c39172a

Please sign in to comment.