Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 45 additions & 26 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: 'Authenticate to Google Cloud'
id: auth
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: 'projects/84699750544/locations/global/workloadIdentityPools/github/providers/github'
service_account: 'github-actions@analysis-tools-dev.iam.gserviceaccount.com'
create_credentials_file: true

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 24
cache: 'npm'

- name: Install dependencies
Expand All @@ -42,6 +50,8 @@ jobs:
run: npm run lint

- name: Build project
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.auth.outputs.credentials_file_path }}
run: npm run build

deploy:
Expand All @@ -54,18 +64,20 @@ jobs:
- uses: actions/checkout@v4

- name: 'Authenticate to Google Cloud'
id: auth
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: 'projects/84699750544/locations/global/workloadIdentityPools/github/providers/github'
service_account: 'github-actions@analysis-tools-dev.iam.gserviceaccount.com'
create_credentials_file: true

- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 24
cache: 'npm'

- name: Install dependencies
Expand All @@ -75,6 +87,8 @@ jobs:
run: npm run lint

- name: Build project
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.auth.outputs.credentials_file_path }}
run: npm run build

- name: 'Configure Docker'
Expand Down Expand Up @@ -110,45 +124,50 @@ jobs:
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
echo ${{ secrets.FIREBASE_TOKEN }} | base64 -d > ./credentials.json
echo "Building Docker Image with tag $IMAGE_NAME"
docker build --build-arg GH_TOKEN=${{ env.GH_TOKEN }} \
--build-arg PROJECT_ID=analysis-tools-dev \
DOCKER_BUILDKIT=1 docker build --build-arg GH_TOKEN=${{ env.GH_TOKEN }} \
--secret id=gcp_creds,src=${{ steps.auth.outputs.credentials_file_path }} \
-t ${IMAGE_NAME} .
rm ./credentials.json

- name: 'Push Docker Image'
run: |
echo "Pushing Docker Image $IMAGE_NAME"
docker push $IMAGE_NAME

- name: 'Deploy'
uses: pulumi/actions@v5
- name: 'Deploy stage'
env:
# TODO: Create a password for Pulumi stack during project bootstrap
PULUMI_CONFIG_PASSPHRASE: '${{ secrets.PULUMI_SECRET }}'
ALGOLIA_API_KEY: '${{ secrets.ALGOLIA_API_KEY }}'
with:
command: up
work-dir: ./pulumi
cloud-url: gs://analysis-tools-dev-pulumi
# TODO: Fix the branch name
stack-name: stage
refresh: true
ALGOLIA_APP_ID: '${{ secrets.ALGOLIA_APP_ID }}'
run: |
gcloud run deploy website-stage \
--image "${IMAGE_NAME}" \
--project "analysis-tools-dev" \
--region "us-central1" \
--platform "managed" \
--allow-unauthenticated \
--port "3000" \
--cpu "1" \
--memory "1Gi" \
--set-env-vars "PUBLIC_HOST=https://website-stage-2ddf80d-mcppc6wqoq-uc.a.run.app,ALGOLIA_APP_ID=${ALGOLIA_APP_ID},ALGOLIA_API_KEY=${ALGOLIA_API_KEY}" \
--quiet

- name: 'Deploy prod'
uses: pulumi/actions@v5
if: github.ref == 'refs/heads/main'
env:
# TODO: Create a password for Pulumi stack during project bootstrap
PULUMI_CONFIG_PASSPHRASE: '${{ secrets.PULUMI_SECRET_PROD }}'
ALGOLIA_API_KEY: '${{ secrets.ALGOLIA_API_KEY }}'
with:
command: up
work-dir: ./pulumi
cloud-url: gs://analysis-tools-dev-pulumi
stack-name: prod
refresh: true
ALGOLIA_APP_ID: '${{ secrets.ALGOLIA_APP_ID }}'
run: |
gcloud run deploy website-prod \
--image "${IMAGE_NAME}" \
--project "analysis-tools-dev" \
--region "us-central1" \
--platform "managed" \
--allow-unauthenticated \
--port "3000" \
--cpu "1" \
--memory "1Gi" \
--set-env-vars "PUBLIC_HOST=https://analysis-tools.dev,ALGOLIA_APP_ID=${ALGOLIA_APP_ID},ALGOLIA_API_KEY=${ALGOLIA_API_KEY}" \
--quiet

# Node.js is already set up earlier in the workflow

Expand Down
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
FROM node:20 as build
FROM node:24 AS build
WORKDIR /src

COPY package.json package-lock.json /src/
RUN npm ci

ENV GOOGLE_APPLICATION_CREDENTIALS=/src/credentials.json
ENV FIREBASE_PROJECT_ID=analysis-tools-dev
ARG GH_TOKEN
ARG PROJECT_ID

COPY . /src

# Build runs npm run build-data (prebuild hook) which fetches tools data
# from GitHub repos and generates static JSON files, then runs next build
RUN npm run build
RUN rm /src/credentials.json
# Uses BuildKit secret for Firestore credentials during build
RUN --mount=type=secret,id=gcp_creds \
export GOOGLE_APPLICATION_CREDENTIALS=/run/secrets/gcp_creds && \
npm run build

FROM node:20
FROM node:24
WORKDIR /src
COPY --from=build /src /src
ENTRYPOINT ["npm", "run", "start"]
ENTRYPOINT ["npm", "run", "start"]
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ dev: ## Run development server
build: ## Build for production
npm run build

.PHONY: docker-build
docker-build: ## Build docker image with GCP credentials secret
@test -n "$(GOOGLE_APPLICATION_CREDENTIALS)" || (echo "GOOGLE_APPLICATION_CREDENTIALS must be set"; exit 1)
DOCKER_BUILDKIT=1 docker build --secret id=gcp_creds,src=$(GOOGLE_APPLICATION_CREDENTIALS) -t analysis-tools-dev .


.PHONY: start
start: ## Start Node server
npm run start
Expand Down
3 changes: 3 additions & 0 deletions algolia-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ function prepareDataForIndexing(toolsData: Tool[]): ApiTool[] {
resources: tool.resources,
wrapper: tool.wrapper,
votes: tool.votes ?? 0,
upVotes: tool.upVotes,
downVotes: tool.downVotes,
upvotePercentage: tool.upvotePercentage,
other: tool.other,
}));

Expand Down
12 changes: 5 additions & 7 deletions components/tools/listPage/ToolCard/ToolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,11 @@ const ToolCard: FC<ToolCardProps> = ({ tool }) => {
</span>
))}
</li>
{tool.upvotePercentage !== undefined && (
<li>
<span className={styles.metaInfo}>
{tool.upvotePercentage}% upvoted
</span>
</li>
)}
<li>
<span className={styles.metaInfo}>
{tool.upvotePercentage}% upvoted
</span>
</li>
</ul>
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface LanguageFilterCardProps {
options: LanguageFilterOption[];
limit?: number;
className?: string;
selectionMode?: 'checkbox' | 'radio';
}

const LanguageFilterCard: FC<LanguageFilterCardProps> = ({
Expand All @@ -30,6 +31,7 @@ const LanguageFilterCard: FC<LanguageFilterCardProps> = ({
options,
limit = 10,
className,
selectionMode,
}) => {
const {
search,
Expand All @@ -45,6 +47,8 @@ const LanguageFilterCard: FC<LanguageFilterCardProps> = ({

// Fade out background when not showing all options
const [faded, setFaded] = useState(styles.faded);
const isRadioMode =
selectionMode === 'radio' || heading === 'Popular Languages';

const toggleAll = () => {
if (listLimit === 999) {
Expand All @@ -61,8 +65,12 @@ const LanguageFilterCard: FC<LanguageFilterCardProps> = ({
updateFilter(searchFilter, []);
};

const handleCheckboxChange = (value: string) => {
const handleOptionChange = (value: string) => {
const searchFilter = filter as SearchFilter;
if (isRadioMode) {
updateFilter(searchFilter, [value]);
return;
}
toggleFilter(searchFilter, value);
};

Expand All @@ -77,13 +85,14 @@ const LanguageFilterCard: FC<LanguageFilterCardProps> = ({
return values !== undefined && values.length > 0;
};

// Sort options: checked items first, then by count
// Sort options by popularity; keep radio selection from reordering items
const sortedOptions = [...options].sort((a, b) => {
const aChecked = isChecked(a.value);
const bChecked = isChecked(b.value);
if (aChecked && !bChecked) return -1;
if (!aChecked && bChecked) return 1;
// Then sort by count
if (!isRadioMode) {
const aChecked = isChecked(a.value);
const bChecked = isChecked(b.value);
if (aChecked && !bChecked) return -1;
if (!aChecked && bChecked) return 1;
}
const aCount = getLanguageCount(a.value);
const bCount = getLanguageCount(b.value);
return bCount - aCount;
Expand Down Expand Up @@ -129,13 +138,18 @@ const LanguageFilterCard: FC<LanguageFilterCardProps> = ({
return (
<li key={index}>
<Input
type="checkbox"
type={isRadioMode ? 'radio' : 'checkbox'}
name={
isRadioMode
? `radio_${filter}_${heading}`
: undefined
}
id={`checkbox_${filter}_${option.value}`}
value={option.value}
data-filter={filter}
checked={isChecked(option.value)}
onChange={() =>
handleCheckboxChange(option.value)
handleOptionChange(option.value)
}
/>
<label
Expand Down
22 changes: 13 additions & 9 deletions components/tools/listPage/ToolsSidebar/ToolsSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ const ToolsSidebar: FC<ToolsSidebarProps> = ({
languages,
others,
}) => {
const mergedLanguageOptions = [
...LANGUAGE_OPTIONS,
...languages.filter(
(option) =>
!LANGUAGE_OPTIONS.some(
(popular) => popular.value === option.value,
),
),
];

return (
<Sidebar className={styles.bottomSticky}>
<LanguageFilterCard
className={styles.filter}
heading="Popular Languages"
showAllCheckbox={false}
filter="languages"
options={LANGUAGE_OPTIONS}
/>
<LanguageFilterCard
className={styles.filter}
heading="All Languages"
heading="Languages"
filter="languages"
options={languages || []}
options={mergedLanguageOptions}
selectionMode="radio"
/>
<FilterCard
showAllCheckbox={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ const InformationCard: FC<InformationCardProps> = ({ tool }) => {
Information
</Heading>

{tool.upVotes && tool.downVotes && (
<InfoEntry
label={'Votes'}
id="votes"
value={`${tool.votes} (${Math.round(
(tool.upVotes / (tool.upVotes + tool.downVotes)) * 100,
)}% upvotes)`}
/>
)}
<InfoEntry
label={'Votes'}
id="votes"
value={`${tool.votes} (${tool.upvotePercentage}% upvotes)`}
/>

{tool.installation && (
<InfoEntry
Expand Down
6 changes: 3 additions & 3 deletions components/tools/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export interface Tool {
resources: ToolResource[] | null;
wrapper: string | null;
votes: number;
upVotes?: number;
downVotes?: number;
upvotePercentage?: number;
upVotes: number;
downVotes: number;
upvotePercentage: number;
views?: number;
installation?: string;
documentation?: string;
Expand Down
2 changes: 1 addition & 1 deletion components/widgets/VoteWidget/VoteWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const VoteWidget: FC<VoteWidgetProps> = ({
</div>
);
}
if (error || !votesData) {
if (error) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion components/widgets/VoteWidget/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function fetchToolVotesData(
): Promise<APIResponseType<VotesData | null>> {
try {
const voteApiURL = `${getApiURL(APIPaths.VOTES)}/${toolId}`;
const response = await fetch(voteApiURL);
const response = await fetch(voteApiURL, { cache: 'no-store' });
return await response.json();
} catch (error) {
return {
Expand Down
Loading