Automated IPFS Deployments #10
This file contains hidden or 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: Deploy to IPFS | |
| on: | |
| pull_request: | |
| branches: [main, dev] | |
| types: [opened, synchronize, reopened] | |
| workflow_dispatch: # Allow manual triggers | |
| jobs: | |
| deploy-ipfs: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write # To comment on PRs with deployment URLs | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| cache: bun | |
| - name: Install client dependencies | |
| run: | | |
| cd client | |
| bun install | |
| - name: Build client app | |
| run: | | |
| cd client | |
| bun run build | |
| - name: Install action dependencies | |
| run: | | |
| cd .github/actions/deploy-ipfs | |
| bun install | |
| - name: Deploy to IPFS | |
| id: deploy | |
| uses: ./.github/actions/deploy-ipfs | |
| with: | |
| pinata-jwt: ${{ secrets.PINATA_JWT }} | |
| pinata-gateway: ${{ secrets.PINATA_API_GATEWAY }} | |
| source-dir: "./client/out" | |
| pin-name: "CommBank.eth App - ${{ github.sha }}" | |
| - name: Comment on PR | |
| uses: actions/github-script@v7 | |
| if: github.event_name == 'pull_request' | |
| with: | |
| script: | | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('🌐 IPFS Preview Deployment') | |
| ); | |
| const commentBody = `## 🌐 IPFS Preview Deployment | |
| Your CommBank.eth app has been deployed to IPFS! | |
| **🔗 Preview URL:** ${{ steps.deploy.outputs.gateway-url }} | |
| **📋 IPFS Hash:** \`${{ steps.deploy.outputs.ipfs-hash }}\` | |
| **📅 Deployed:** ${new Date().toISOString()} | |
| > This deployment is automatically updated when you push new commits to this PR. | |
| `; | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: commentBody | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: commentBody | |
| }); | |
| } |