Skip to content

Commit

Permalink
Do not add logo link if the file does not exist (#65)
Browse files Browse the repository at this point in the history
Fixed logo handling in final json
  • Loading branch information
sergeyk-symbiotic authored Jan 17, 2025
1 parent f5cdf80 commit c957965
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/full-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
generate:
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -19,7 +22,7 @@ jobs:
node-version: '22'

- name: Install dependencies
run: npm install tsx
run: npm install tsx @actions/core @actions/github

- name: Generate
run: npx tsx .github/workflows/scripts/extract-metadata.ts
Expand Down
29 changes: 20 additions & 9 deletions .github/workflows/scripts/extract-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs/promises';
import path from 'path';
import { pathToFileURL } from 'url';
import * as github from '@actions/github';

type Info = Partial<{
name: string;
Expand Down Expand Up @@ -28,7 +29,7 @@ type Info = Partial<{

type Entity = {
info: Info;
logo: string;
logo?: string;
};

enum DIRECTORIES {
Expand All @@ -42,8 +43,10 @@ enum DIRECTORIES {
type Template = Record<DIRECTORIES, Record<string, Entity>>;

async function grabEntitiesInfo(globalDirs: DIRECTORIES[]) {
const repoPath = [github.context.repo.owner, github.context.repo.repo].join('/');
const result = Object.values(DIRECTORIES).reduce<Template>((acc, curr) => {
acc[curr] = {};

return acc;
}, {} as Template);

Expand All @@ -54,17 +57,25 @@ async function grabEntitiesInfo(globalDirs: DIRECTORIES[]) {
const entityPath = path.join(dir, subdir);
try {
const infoPath = path.join(entityPath, 'info.json');
const infoUrl = pathToFileURL(infoPath).href;
const logoPath = path.join(entityPath, 'logo.png');

const infoUrl = pathToFileURL(infoPath).href;
const module = await import(infoUrl);
const info: Info = module.default;
result[dir as DIRECTORIES][subdir] = {
info,
logo:
'https://raw.githubusercontent.com/symbioticfi/metadata-holesky/main/' +
entityPath +
'/logo.png',
};
const entity: Entity = { info };

const hasLogo = await fs
.stat(logoPath)
.then((stats) => stats.isFile())
.catch(() => false);

if (hasLogo) {
const logoUrl = `https://raw.githubusercontent.com/${repoPath}/main/${entityPath}/logo.png`;

entity.logo = logoUrl;
}

result[dir as DIRECTORIES][subdir] = entity;
} catch (error) {
console.error('Error processing entity in ' + entityPath, error);
}
Expand Down

0 comments on commit c957965

Please sign in to comment.