Skip to content

Commit 2885d18

Browse files
feat: deploy to ipfs
1 parent 363d3f3 commit 2885d18

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

.github/deploy-ipfs.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import { Blob } from 'node:buffer'
4+
5+
async function* readAllFilesRecursively(root) {
6+
for (const entry of await fs.promises.readdir(root, { withFileTypes: true })) {
7+
const fullPath = path.join(root, entry.name)
8+
if (entry.isDirectory()) {
9+
yield* readAllFilesRecursively(fullPath)
10+
} else if (entry.isFile()) {
11+
yield fullPath
12+
}
13+
}
14+
}
15+
16+
const pinDirectoryToPinata = async (root) => {
17+
if (!root) throw new Error(`Usage: node pin-ens.mjs <directory>`)
18+
19+
const formData = new FormData()
20+
21+
for await (const file of readAllFilesRecursively(root)) {
22+
const relativePath = path.relative(root, file) || path.basename(file)
23+
const normalizedPath = relativePath.split(path.sep).join('/')
24+
const buffer = await fs.promises.readFile(file)
25+
formData.append('file', new Blob([buffer]), normalizedPath)
26+
console.info(`Added file: ${normalizedPath} (${file.length} bytes)`)
27+
}
28+
29+
if (!process.env.PINATA_JWT) throw new Error(`PINATA_JWT environment variable is not set, cannot upload.`)
30+
31+
const response = await fetch('https://api.pinata.cloud/pinning/pinFileToIPFS', {
32+
method: 'POST',
33+
headers: { Authorization: 'Bearer ' + process.env.PINATA_JWT },
34+
body: formData,
35+
})
36+
console.info(await response.text())
37+
}
38+
39+
pinDirectoryToPinata(process.argv[2]).catch((e) => {
40+
console.error(error)
41+
process.exitCode = 1
42+
})

.github/workflows/ci.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ jobs:
111111
name: Cypress e2e tests in ${{ matrix.browser }} ${{ matrix.count }}
112112
timeout-minutes: 15
113113
runs-on: ubuntu-latest
114+
if: github.ref_name != 'feat/ens'
114115
steps:
115116
- uses: actions/checkout@v4
116117
- uses: actions/setup-node@v4
@@ -159,3 +160,22 @@ jobs:
159160
- name: Check runtime errors
160161
if: always()
161162
run: if grep --ignore-case --extended-regexp "update depth exceeded|many re-renders|unmounted component|non-unique keys|uncontrolled to controlled|properties of undefined" e2e-*.log; then exit 1; fi
163+
164+
deploy-ipfs:
165+
name: Deploy to IPFS
166+
if: github.ref_name == 'main'
167+
timeout-minutes: 10
168+
runs-on: ubuntu-latest
169+
environment: ens
170+
needs: [lint, test, cypress-component, cypress-component-rpc, cypress-e2e]
171+
steps:
172+
- uses: actions/checkout@v4
173+
- uses: actions/setup-node@v4
174+
with:
175+
node-version: 22
176+
cache: yarn
177+
- run: yarn set version stable
178+
- run: yarn install --immutable
179+
- run: yarn build
180+
- name: Deploy to IPFS via Pinata
181+
run: yarn deploy:ens

.github/workflows/ipfs.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
on: [push]
3+
env:
4+
DO_NOT_TRACK: 1
5+
IBM_TELEMETRY_DISABLED: true
6+
permissions:
7+
contents: read
8+
jobs:
9+
deploy-ipfs:
10+
name: Deploy to IPFS
11+
if: github.ref_name == 'feat/ens'
12+
timeout-minutes: 10
13+
runs-on: ubuntu-latest
14+
environment: ens
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: 22
20+
cache: yarn
21+
- run: yarn set version stable
22+
- run: yarn install --immutable
23+
- run: yarn build
24+
- name: Deploy to IPFS via Pinata
25+
run: yarn deploy:ipfs

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"format:check": "prettier --check \"**/*.{ts,tsx,md}\"",
2323
"prepare": "husky",
2424
"storybook": "yarn workspace curve-ui-kit run storybook",
25-
"storybook:build": "yarn workspace curve-ui-kit run build:storybook"
25+
"storybook:build": "yarn workspace curve-ui-kit run build:storybook",
26+
"deploy:ipfs": "node .github/deploy-ipfs.mjs ./apps/main/.vercel/output/static"
2627
},
2728
"devDependencies": {
2829
"@commitlint/cli": "^20.1.0",

0 commit comments

Comments
 (0)