ci: add build workflow #1
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
name: Build and Publish to IPFS | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
publish-to-ipfs: | |
runs-on: 'ubuntu-latest' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Build project | |
run: npm run build | |
- name: Upload to IPFS | |
uses: web3-storage/add-to-web3@v3 | |
id: web3storage # | |
with: | |
path_to_add: 'dist' | |
proof: ${{ secrets.W3_PROOF }} | |
secret_key: ${{ secrets.W3_PRINCIPAL }} | |
- name: Output CID | |
run: echo ${{ steps.web3storage.outputs.cid }} | |
- name: Output URL | |
run: echo ${{ steps.web3storage.outputs.url }} | |
- name: Update commit status | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const url = '${{ steps.web3storage.outputs.url }}'; | |
github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: context.sha, | |
state: 'success', | |
target_url: url, | |
description: `Preview (${steps.web3storage.outputs.cid}) deployment ready`, | |
context: 'IPFS Preview' | |
}); | |
- name: Comment on PR | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const url = '${{ steps.web3storage.outputs.url }}'; | |
github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: `🚀 Preview ${steps.web3storage.outputs.cid} deployment available at: ${url}` | |
}); | |