Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
vesla0x1 committed Apr 9, 2024
1 parent 0cd1c6f commit 27d6e93
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
44 changes: 37 additions & 7 deletions .deploy/ipfs_deploy.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
import { create, globSource } from 'kubo-rpc-client';
import { writeFile } from 'node:fs';

async function addDir(){
const auth = process.env.IPFS_RPC_API_SECRET;
const url = process.env.IPFS_RPC_API_URL;
console.log('auth:', auth)
const auth = process.env.IPFS_RPC_API_SECRET;
const url = process.env.IPFS_RPC_API_URL;
const key = process.env.IPFS_RPC_API_NAME_KEY;
const cids_path = process.env.CIDS_FILE_PATH;

async function IPFSDeploy(){
const files = [];
const client = await create({
url: `${url}/api/v0`,
headers: {
authorization: `Bearer ${auth}`,
}
})

for await (const file of client.addAll(globSource(".", "public/**/*"))) {
console.log(file)
console.log('adding files on IPFS..');
for await (const file of client.addAll(globSource(".", "public/**/*"))) {
files.push({ path: file.path, cid: file.cid.toString() });
}

const newPublicDirCID = files[files.length - 1].cid;
console.log(`pinned: ${newPublicDirCID}`);

let unpinned;
for await (const file of client.pin.ls()) {
unpinned = file.cid.toString();
if (file.type === 'recursive' && unpinned !== newPublicDirCID) {
await client.pin.rmAll(unpinned);
}
}

console.log(`unpinned: ${unpinned}`);

console.log('publishion on IPNS...')
const r = await client.name.publish(`${newPublicDirCID}`, { key });

console.log('new version available on:');
console.log(`IPFS address: https://ipfs.io/ipfs/${newPublicDirCID}`);
console.log(`IPNS address: https://ipfs.io/ipns/${r.name}`);

console.log(`saving unpinned and pinned CIDs in ${save_dir}`)
await writeFile(save_dir, `${unpinned}\n${newPublicDirCID}`, err => {
if (err) throw err;
console.log(`${save_dir} has been saved`);
});
}

addDir()
IPFSDeploy();
25 changes: 23 additions & 2 deletions .github/workflows/github-actions-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ name: Publish portfolio on IPFS
run-name: Build Zola portfolio and publish it on IPFS
on: push
jobs:
build:
deploy:
runs-on: ubuntu-latest
environment: production
env:
CIDS_FILENAME: '/tmp/cids'
PINATA_PIN_NAME: ${{ vars.PINATA_PIN_NAME }}

steps:
- name: Install Zola
uses: taiki-e/install-action@v2
Expand All @@ -28,7 +32,7 @@ jobs:
npx all-relative
cd ..
- name: Add public on IPFS
- name: Deploy on IPFS
run: |
cd .deploy && npm install .
mv ../public .
Expand All @@ -37,3 +41,20 @@ jobs:
IPFS_RPC_API_URL: ${{ vars.IPFS_RPC_API_URL }}
IPFS_RPC_API_SECRET: ${{ vars.IPFS_RPC_API_SECRET }}

- name: Unpin old and pin new versions on Pinata
run: |
UNPIN_CID=$(cat $CIDS_FILE_PATH | head -n 1)
PIN_CID=$(cat CIDS_FILE_PATH | tail -n 1)
curl -X DELETE \
-H "Authorization: Bearer ${{ secrets.PINATA_API_KEY }}" \
https://api.pinata.cloud/pinning/unpin/$UNPIN_CID
curl -X POST \
-H "Authorization: Bearer ${{ secrets.PINATA_API_KEY }}" \
-H 'Content-type: application/json' \
-d "{
\"hashToPin\": \"$PIN_CID\",
\"pinataMetadata\": \"{\\\"name\\\": \\\"$PINATA_PIN_NAME\\\"}\"
}" \
https://api.pinata.cloud/pinning/pinByHash

0 comments on commit 27d6e93

Please sign in to comment.