Skip to content

feat: publish succeess state & support base58 keys #31

feat: publish succeess state & support base58 keys

feat: publish succeess state & support base58 keys #31

Workflow file for this run

name: Build and Publish to IPFS
# Explicitly declare permissions
permissions:
contents: read
pull-requests: write
statuses: write
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
NODE_VERSION: '20'
jobs:
build:
runs-on: 'ubuntu-latest'
outputs:
cid: ${{ steps.merklize.outputs.cid }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: |
npm ci
npm install -g ipfs-car
- name: Build project
run: npm run build
- name: Merkelize Build
id: merklize
run: |
CID=$(npx ipfs-car pack out --no-wrap --output build.car 2>&1 | tail -n 1)
echo "cid=$CID" >> "$GITHUB_OUTPUT"
echo $CID
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-output-car
path: build.car
upload-car-to-storacha:
runs-on: 'ubuntu-latest'
needs: 'build'
if: success() && (github.event_name == 'push' || github.event_name == 'pull_request')
steps:
- name: Check required secrets
run: |
if [ -z "${{ secrets.STORACHA_KEY }}" ] || [ -z "${{ secrets.STORACHA_PROOF }}" ]; then
echo "::error::Missing required secrets STORACHA_KEY and STORACHA_PROOF"
exit 1
fi
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output-car
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Configure and upload CAR to Storacha
env:
W3_PRINCIPAL: ${{ secrets.STORACHA_KEY }}
run: |
npm install -g @web3-storage/w3cli
w3 space add ${{ secrets.STORACHA_PROOF }}
# Delete previous CARs - disabled for now
# w3 ls | while read -r cid; do
# w3 rm --shards "$cid"
# done
if ! w3 up --car build.car; then
echo "::error::Failed to upload to IPFS"
exit 1
fi
upload-car-to-filebase:
runs-on: 'ubuntu-latest'
needs: 'build'
if: success() && (github.event_name == 'push' || github.event_name == 'pull_request')
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output-car
- name: Check required secrets
run: |
if [ -z "${{ secrets.FILEBASE_SECRET_KEY }}" ] || [ -z "${{ secrets.FILEBASE_ACCESS_KEY }}" ]; then
echo "::error::Missing required secrets FILEBASE_SECRET_KEY and FILEBASE_ACCESS_KEY"
exit 1
fi
- name: Upload CAR to Filebase
env:
AWS_ACCESS_KEY_ID: ${{ secrets.FILEBASE_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.FILEBASE_SECRET_KEY }}
FILEBASE_BUCKET: ${{ secrets.FILEBASE_BUCKET }}
run: |
aws --endpoint https://s3.filebase.com s3 cp build.car s3://${FILEBASE_BUCKET} --debug --metadata 'import=car'
update-commit-status:
runs-on: 'ubuntu-latest'
needs: ['build', 'upload-car-to-storacha', 'upload-car-to-filebase']
steps:
- name: Update commit status
uses: actions/github-script@v7
with:
script: |
const cid = '${{ needs.build.outputs.cid }}';
// For PR events, we need to use the head SHA
const sha = context.eventName === 'pull_request'
? context.payload.pull_request.head.sha
: context.sha;
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: sha,
state: 'success',
target_url: `https://w3s.link/ipfs/${cid}`,
description: `CID: ${cid}`,
context: 'IPFS Preview'
});
- name: Find Comment to update
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'πŸš€ Build'
- name: Create or update comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
### πŸš€ Build Preview on IPFS ready
- πŸ” CID `${{ needs.build.outputs.cid }}`
- πŸ“¦ [Preview](https://w3s.link/ipfs/${{ needs.build.outputs.cid }})
- πŸ”— [Service Worker Preview](https://inbrowser.link/ipfs/${{ needs.build.outputs.cid }})
edit-mode: replace