Skip to content

Commit

Permalink
feat(workflows): switch to bun
Browse files Browse the repository at this point in the history
  • Loading branch information
nexpid committed Dec 5, 2024
1 parent b5ccefb commit b0486b1
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 136 deletions.
62 changes: 0 additions & 62 deletions .github/scripts/iconpack_tree_writer/index.mjs

This file was deleted.

71 changes: 71 additions & 0 deletions .github/scripts/iconpack_tree_writer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { join } from "node:path";
import { readdir, rm } from "node:fs/promises";

console.log("Starting...");

const processStart = performance.now();

const { list } = (await Bun.file(join("iconpacks", "list.json")).json()) as {
list: {
id: string;
load: string;
suffix: string;
}[];
};
const hashes: Record<
string,
{
hash: string;
size: number;
}
> = {};

for (const ic of list) {
const start = performance.now();
const [user, repo, branch, ...rawPath] = (ic.load as string)
.split("/")
.slice(3);
const path = rawPath.join("/");

const raw = await fetch(
`https://api.github.com/repos/${user}/${repo}/git/trees/${branch}?recursive=1`,
).then((x) => x.json());
const files = (raw.tree as any[])
.filter((x) => x.type === "blob")
.filter(
(x) =>
x.path.startsWith(path) &&
["png", "jpg", "webm", "lottie"].some((ext) =>
x.path.endsWith(`${ic.suffix}.${ext}`),
),
)
.map((x) => ({
size: x.size,
path: x.path.split("/").slice(path.length).join("/"),
}))
.filter((x) => x.path.length > 0);

hashes[ic.id] = {
hash: raw.sha,
size: files.reduce((a, b) => a + b.size, 0),
};
await Bun.write(
join("../trees", `${ic.id}.txt`),
files.map((x) => x.path).join("\n"),
);

console.log(
`Parsed "${ic.id}" [${(performance.now() - start).toFixed(1)}ms]`,
);
}

for (const f of (
await readdir("../trees", {
withFileTypes: true,
})
).filter((x) => x.isFile() && !list.some((y) => x.name === `${y.id}.txt`)))
await rm(join("../trees", f.name));

await Bun.write(join("../trees", "_hashes.txt"), JSON.stringify(hashes));

console.log(`\nDone [${(performance.now() - processStart).toFixed(1)}ms]`);
49 changes: 0 additions & 49 deletions .github/scripts/list_iconpacks/index.mjs

This file was deleted.

53 changes: 53 additions & 0 deletions .github/scripts/list_iconpacks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { join } from "node:path";

const processStart = performance.now();

const template = await Bun.file(
join(".github/scripts/list_iconpacks", "template.md"),
).text();
const { list } = (await Bun.file(join("iconpacks", "list.json")).json()) as {
list: {
name: string;
description: string;
credits: {
authors: { id: string; name: string }[];
sources: string[];
};
load: string;
suffix: string;
}[];
};

const packs: string[] = [];
for (const pack of list) {
const authors = pack.credits.authors.map((a) =>
a.id ? `[@${a.name}](https://discord.com/users/${a.id})` : `**${a.name}**`,
);
const sources = pack.credits.sources.map((x) => `[${x}](${x})`);

packs.push(
[
`### ${pack.name} <img src="${pack.load}design/components/Icon/native/redesign/generated/images/BellIcon${pack.suffix}.png" alt="Preview for ${pack.name}" width=24 height=24 />\n`,
`${pack.description} `,
`Created by: ${
authors.length > 1
? `${authors.slice(0, -1).join(", ")} and ${
authors[authors.length - 1]
}`
: authors.join(", ")
} `,
sources.length === 1
? `Assets from: ${sources[0]} `
: sources.length > 1
? `Assets from:\n\n${sources.map((x) => `- ${x}`).join("\n")} `
: "",
].join("\n"),
);
}

await Bun.write(
join("docs", "ICONPACKS.md"),
template.replace(/{{}}/g, packs.join("\n\n")),
);

console.log(`\nDone [${(performance.now() - processStart).toFixed(1)}ms]`);
25 changes: 11 additions & 14 deletions .github/workflows/iconpack_tree_writer.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
name: Iconpack Tree Writer
name: write iconpack trees (half-hourly)

on:
push:
branches:
- main
paths:
- "iconpacks/list.json"
- ".github/scripts/iconpack_tree_writer/**/*.*"
- ".github/workflows/iconpack_tree_writer.yml"
schedule:
- cron: "*/30 * * * *"
workflow_dispatch:

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
write:
runs-on: ubuntu-latest
name: Write files
name: write files
permissions:
contents: write
steps:
Expand All @@ -30,20 +29,18 @@ jobs:
ref: iconpack-trees
path: trees

- uses: actions/setup-node@v4
- uses: oven-sh/setup-bun@v2
with:
node-version: 18.x
- uses: pnpm/action-setup@v3
with:
package_json_file: main/package.json
bun-version: latest

- working-directory: main
run: pnpm i
run: bun i

- name: Write trees
- name: write trees
working-directory: main
run: node .github/scripts/iconpack_tree_writer/index.mjs
run: bun run treewriter

- name: Commit changes
- name: commit changes
working-directory: trees
run: |
git config --global user.name "github-actions[bot]"
Expand All @@ -57,5 +54,5 @@ jobs:
git commit -m "chore: update iconpacks trees" | true
fi
git pull
git pull --ff-only
git push
21 changes: 10 additions & 11 deletions .github/workflows/list_iconpacks.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
name: List Iconpacks
name: list iconpacks

on:
push:
branches:
- main
paths:
- "iconpacks/list.json"
- ".github/scripts/list_iconpacks/**/*.*"
- ".github/workflows/list_iconpacks.yml"
workflow_dispatch:

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
write:
runs-on: ubuntu-latest
name: Write Readme
name: write readme
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
- uses: oven-sh/setup-bun@v2
with:
node-version: 18.x
- uses: pnpm/action-setup@v3
- run: pnpm i
bun-version: latest

- name: Write ICONPACKS.md
run: node .github/scripts/list_iconpacks/index.mjs
- run: bun i

- name: Commit changes
- name: list iconpacks
run: bun run listiconpacks

- name: commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
Expand Down

0 comments on commit b0486b1

Please sign in to comment.