Skip to content

Commit 5f679f3

Browse files
committed
Initial commit
0 parents  commit 5f679f3

File tree

6 files changed

+615
-0
lines changed

6 files changed

+615
-0
lines changed

.github/workflows/update-cache.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-24.04
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 24
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Build cache
25+
run: node build-cache.js
26+
27+
- name: Upload static files as artifact
28+
uses: actions/upload-pages-artifact@v3
29+
with:
30+
path: cache/
31+
32+
deploy:
33+
runs-on: ubuntu-24.04
34+
needs: build
35+
permissions:
36+
contents: read # to access the repository contents
37+
pages: write # to deploy to Pages
38+
id-token: write # to verify the deployment originates from an appropriate source
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
44+
- name: Deploy to GitHub Pages
45+
uses: actions/deploy-pages@v4
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
tmp/
3+
cache/

build-cache.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { execSync } from 'child_process';
2+
import { createHash } from 'crypto';
3+
import { existsSync, mkdirSync, writeFileSync } from 'fs';
4+
import { resolve } from 'path';
5+
import { rimrafSync } from 'rimraf';
6+
import presets from './presets.json' with { type: 'json' };
7+
8+
const CACHE_DIR = resolve(new URL('.', import.meta.url).pathname, 'cache');
9+
10+
function hashLibraryList(libs) {
11+
const list = Array.from(new Set(libs)).sort().join('\n');
12+
return createHash('sha256').update(list).digest('hex');
13+
}
14+
15+
if (existsSync(CACHE_DIR)) {
16+
rimrafSync(CACHE_DIR);
17+
}
18+
19+
mkdirSync(CACHE_DIR, { recursive: true });
20+
let index = [];
21+
for (const libs of presets) {
22+
const hash = hashLibraryList(libs);
23+
console.log(hash);
24+
for (const lib of libs) {
25+
console.log(` -> ${lib}`);
26+
}
27+
28+
const cache = resolve(CACHE_DIR, `libraries-${hash}.tar.zst`);
29+
const dir = `tmp/${hash}`;
30+
const absDir = resolve(dir);
31+
mkdirSync(dir, { recursive: true });
32+
const libVars = libs.map((_, index) => `"$L_${index}"`);
33+
const libCmd = `arduino-cli lib install -- ${libVars.join(' ')}`;
34+
try {
35+
execSync(libCmd, {
36+
cwd: dir,
37+
env: {
38+
HOME: process.env.HOME ?? '',
39+
PATH: process.env.PATH ?? '',
40+
ARDUINO_SKETCHBOOK_DIR: absDir,
41+
...Object.fromEntries(libs.map((libName, index) => [`L_${index}`, libName])),
42+
}
43+
});
44+
writeFileSync(`${absDir}/libraries/index.txt`, libs.sort().join('\n'));
45+
writeFileSync(`${absDir}/libraries/libraries_hash.txt`, hash);
46+
execSync(`tar -cf - -C ${absDir}/libraries . | zstd -19 -T0 - > ${cache}`);
47+
} finally {
48+
rimrafSync(absDir);
49+
}
50+
index.push(hash);
51+
}
52+
53+
writeFileSync(resolve(CACHE_DIR, 'index.json'), JSON.stringify(index, null, 2));
54+
writeFileSync(resolve(CACHE_DIR, 'index.txt'), index.join('\n') + '\n');

0 commit comments

Comments
 (0)