-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: refactor into composite action for reusability
- Loading branch information
Showing
2 changed files
with
183 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
name: 'Deploy to IPFS' | ||
description: 'Deploy a directory to IPFS via Storacha, with optional Pinata and Filebase pinning' | ||
branding: | ||
icon: 'box' | ||
color: 'blue' | ||
|
||
inputs: | ||
node-version: | ||
description: 'Node.js version to use' | ||
default: '20' | ||
required: false | ||
kubo-version: | ||
description: 'Kubo version to use for pinning https://dist.ipfs.tech/kubo/versions' | ||
default: 'v0.33.0' | ||
required: false | ||
path-to-deploy: | ||
description: 'Path to the directory containing the frontend build to merkelize into a CAR file and deploy to IPFS' | ||
required: true | ||
storacha-key: | ||
description: 'Storacha key for authentication' | ||
required: true | ||
storacha-proof: | ||
description: 'Storacha proof for authentication' | ||
required: true | ||
pinata-pinning-url: | ||
description: 'Pinata Pinning Service URL' | ||
default: 'https://api.pinata.cloud/psa' | ||
pinata-jwt-token: | ||
description: 'Pinata JWT token for authentication' | ||
required: false | ||
filebase-bucket: | ||
description: 'Filebase bucket name' | ||
required: false | ||
filebase-access-key: | ||
description: 'Filebase access key' | ||
required: false | ||
filebase-secret-key: | ||
description: 'Filebase secret key' | ||
required: false | ||
github-token: | ||
description: 'GitHub token for updating commit status and PR comments' | ||
required: true | ||
set-github-status: | ||
description: 'Set GitHub commit status and PR comments' | ||
default: 'true' | ||
|
||
outputs: | ||
cid: | ||
description: 'The IPFS CID of the uploaded content' | ||
value: ${{ steps.merkelize.outputs.cid }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install ipfs-car | ||
shell: bash | ||
run: npm install -g ipfs-car@2 | ||
|
||
- name: Merkelize into CAR file | ||
id: merkleize | ||
shell: bash | ||
run: | | ||
CID=$(npx ipfs-car pack ${{ inputs.path-to-deploy }} --no-wrap --output build.car 2>&1 | tail -n 1) | ||
echo "cid=$CID" >> "$GITHUB_OUTPUT" | ||
echo $CID | ||
- name: Configure and upload CAR to Storacha | ||
shell: bash | ||
env: | ||
W3_PRINCIPAL: ${{ inputs.storacha-key }} | ||
run: | | ||
npm install -g @web3-storage/w3cli | ||
w3 space add ${{ inputs.storacha-proof }} | ||
if ! w3 up --car build.car; then | ||
echo "::error::Failed to upload to IPFS" | ||
exit 1 | ||
fi | ||
- name: Upload CAR to Filebase | ||
if: ${{ inputs.filebase-access-key != '' }} | ||
shell: bash | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ inputs.filebase-access-key }} | ||
AWS_SECRET_ACCESS_KEY: ${{ inputs.filebase-secret-key }} | ||
FILEBASE_BUCKET: ${{ inputs.filebase-bucket }} | ||
run: | | ||
aws --endpoint https://s3.filebase.com s3 cp build.car s3://${FILEBASE_BUCKET} --metadata 'import=car' | ||
- name: Setup Kubo | ||
if: ${{ inputs.pinata-jwt-token != ''}} | ||
uses: ipfs/download-ipfs-distribution-action@v1 | ||
with: | ||
name: kubo | ||
version: ${{ inputs.kubo-version }} | ||
|
||
- name: Pin CID to Pinata | ||
if: ${{ inputs.pinata-jwt-token != ''}} | ||
shell: bash | ||
run: | | ||
ipfs init | ||
ipfs pin remote service add pinata "${{ inputs.pinata-pinning-url }}" ${{ inputs.pinata-jwt-token }} | ||
ipfs pin remote add --service=pinata --background --name="build-${{ github.sha }}" ${{ steps.merkelize.outputs.cid }} | ||
- name: Set GitHub commit status | ||
if: ${{ inputs.set-github-status }} | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ inputs.github-token }} | ||
script: | | ||
const cid = '${{ steps.merkelize.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: ${{ inputs.set-github-status && 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' | ||
token: ${{ inputs.github-token }} | ||
|
||
- name: Create or update comment | ||
if: ${{ inputs.set-github-status && github.event_name == 'pull_request' }} | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
token: ${{ inputs.github-token }} | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
### 🚀 Build Preview on IPFS ready | ||
- 🔎 Commit: ${{ github.event.pull_request.head.sha }} | ||
- 🔏 CID `${{ steps.merkelize.outputs.cid }}` | ||
- 📦 [Preview](https://w3s.link/ipfs/${{ steps.merkelize.outputs.cid }}) | ||
- 🔗 [Service Worker Preview](https://inbrowser.link/ipfs/${{ steps.merkelize.outputs.cid }}) | ||
edit-mode: replace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters