Skip to content

fix: simpler button #18

fix: simpler button

fix: simpler button #18

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: Cache Next.js build
uses: actions/cache@v4
with:
path: |
.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Build project
run: npm run build
- name: Merkelize Build
id: merklize
run: |
set -x
if [ ! -d "out" ]; then
echo "::error::Build output directory 'out' not found"
exit 1
fi
# Capture stderr to which the CID is printed. See https://github.com/storacha/ipfs-car/pull/169
CID=$(npx ipfs-car pack out --no-wrap --output build.car 2>&1 | tail -n 1)
echo "cid=$CID" >> "$GITHUB_OUTPUT"
echo $GITHUB_OUTPUT
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-output-car
path: build.car
publish-to-ipfs:
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/or 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
- name: Update commit status
uses: actions/github-script@v7
with:
script: |
const cid = '${{ needs.build.outputs.cid }}';
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.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 Gateway](https://w3s.link/ipfs/${{ needs.build.outputs.cid }})
πŸ”— [Service Worker Gateway](https://inbrowser.link/ipfs/${{ needs.build.outputs.cid }})
edit-mode: replace