|
| 1 | +# Deploy workflow - triggered by workflow_run after successful build |
| 2 | +# This workflow has access to secrets but never executes untrusted code |
| 3 | +# It only downloads and deploys pre-built artifacts from the build workflow |
| 4 | +# Security: Fork code cannot access secrets as it only runs in build workflow |
| 5 | +# Deploys to IPFS for all branches and GitHub Pages for main branch only |
| 6 | + |
| 7 | +name: Deploy |
| 8 | + |
| 9 | +# Explicitly declare permissions |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + statuses: write |
| 14 | + |
| 15 | +on: |
| 16 | + workflow_run: |
| 17 | + workflows: ["Build"] |
| 18 | + types: [completed] |
| 19 | + |
| 20 | +env: |
| 21 | + BUILD_PATH: 'docs-build' |
| 22 | + |
| 23 | +jobs: |
| 24 | + deploy-ipfs: |
| 25 | + if: github.event.workflow_run.conclusion == 'success' |
| 26 | + runs-on: ubuntu-latest |
| 27 | + outputs: |
| 28 | + cid: ${{ steps.deploy.outputs.cid }} |
| 29 | + steps: |
| 30 | + - name: Download build artifact |
| 31 | + uses: actions/download-artifact@v5 |
| 32 | + with: |
| 33 | + name: docs-build-${{ github.event.workflow_run.id }} |
| 34 | + path: ${{ env.BUILD_PATH }} |
| 35 | + run-id: ${{ github.event.workflow_run.id }} |
| 36 | + github-token: ${{ github.token }} |
| 37 | + |
| 38 | + - name: Debug PR context and SHA |
| 39 | + run: | |
| 40 | + echo "Event: ${{ github.event_name }}" |
| 41 | + echo "SHA: ${{ github.sha }}" |
| 42 | + echo "Head SHA: ${{ github.event.pull_request.head.sha }}" |
| 43 | + echo "workflow_run.head_sha: ${{ github.event.workflow_run.head_sha }}" |
| 44 | +
|
| 45 | + - name: Deploy to IPFS |
| 46 | + uses: ipfs/ipfs-deploy-action@v1 |
| 47 | + id: deploy |
| 48 | + with: |
| 49 | + path-to-deploy: ${{ env.BUILD_PATH }} |
| 50 | + cluster-url: "/dnsaddr/ipfs-websites.collab.ipfscluster.io" |
| 51 | + cluster-user: ${{ secrets.CLUSTER_USER }} |
| 52 | + cluster-password: ${{ secrets.CLUSTER_PASSWORD }} |
| 53 | + cluster-pin-expire-in: ${{ github.event.workflow_run.head_branch != 'main' && '2160h' || '' }} |
| 54 | + #storacha-key: ${{ secrets.STORACHA_KEY }} |
| 55 | + #storacha-proof: ${{ secrets.STORACHA_PROOF }} |
| 56 | + github-token: ${{ github.token }} |
| 57 | + |
| 58 | + deploy-gh-pages: |
| 59 | + if: | |
| 60 | + github.event.workflow_run.conclusion == 'success' && |
| 61 | + github.event.workflow_run.head_branch == 'main' |
| 62 | + runs-on: ubuntu-latest |
| 63 | + permissions: |
| 64 | + pages: write |
| 65 | + id-token: write |
| 66 | + environment: |
| 67 | + name: github-pages |
| 68 | + url: ${{ steps.deployment.outputs.page_url }} |
| 69 | + steps: |
| 70 | + - name: Download build artifact |
| 71 | + uses: actions/download-artifact@v4 |
| 72 | + with: |
| 73 | + name: docs-build-${{ github.event.workflow_run.id }} |
| 74 | + path: docs-build |
| 75 | + run-id: ${{ github.event.workflow_run.id }} |
| 76 | + github-token: ${{ github.token }} |
| 77 | + |
| 78 | + - name: Upload Pages artifact |
| 79 | + uses: actions/upload-pages-artifact@v3 |
| 80 | + with: |
| 81 | + path: docs-build |
| 82 | + |
| 83 | + - name: Deploy to GitHub Pages |
| 84 | + id: deployment |
| 85 | + uses: actions/deploy-pages@v4 |
0 commit comments