|
| 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 | + actions: read |
| 12 | + contents: read |
| 13 | + pull-requests: write |
| 14 | + statuses: write |
| 15 | + |
| 16 | +on: |
| 17 | + workflow_run: |
| 18 | + workflows: ["Build"] |
| 19 | + types: [completed] |
| 20 | + |
| 21 | +env: |
| 22 | + BUILD_PATH: 'website-build' |
| 23 | + |
| 24 | +jobs: |
| 25 | + deploy-ipfs: |
| 26 | + if: github.event.workflow_run.conclusion == 'success' |
| 27 | + runs-on: ubuntu-latest |
| 28 | + outputs: |
| 29 | + cid: ${{ steps.deploy.outputs.cid }} |
| 30 | + environment: |
| 31 | + name: 'ipfs-publish' |
| 32 | + steps: |
| 33 | + - name: Download build artifact |
| 34 | + uses: actions/download-artifact@v4 |
| 35 | + with: |
| 36 | + name: website-build-${{ github.event.workflow_run.id }} |
| 37 | + path: ${{ env.BUILD_PATH }} |
| 38 | + run-id: ${{ github.event.workflow_run.id }} |
| 39 | + github-token: ${{ github.token }} |
| 40 | + |
| 41 | + - name: Deploy to IPFS |
| 42 | + uses: ipshipyard/ipfs-deploy-action@v1 |
| 43 | + id: deploy |
| 44 | + with: |
| 45 | + path-to-deploy: ${{ env.BUILD_PATH }} |
| 46 | + cluster-url: "/dnsaddr/ipfs-websites.collab.ipfscluster.io" |
| 47 | + cluster-user: ${{ secrets.CLUSTER_USER }} |
| 48 | + cluster-password: ${{ secrets.CLUSTER_PASSWORD }} |
| 49 | + cluster-pin-expire-in: ${{ github.event.workflow_run.head_branch != 'main' && '2160h' || '' }} |
| 50 | + github-token: ${{ github.token }} |
| 51 | + |
| 52 | + dnslink-update: |
| 53 | + runs-on: ubuntu-latest |
| 54 | + needs: deploy-ipfs |
| 55 | + if: github.event.workflow_run.head_branch == 'main' |
| 56 | + environment: |
| 57 | + name: 'dnslink' |
| 58 | + url: "https://dnslink.dev/" |
| 59 | + steps: |
| 60 | + - name: Update DNSLink |
| 61 | + uses: ipshipyard/dnslink-action@v1 |
| 62 | + with: |
| 63 | + cid: ${{ needs.deploy-ipfs.outputs.cid }} |
| 64 | + dnslink_domain: 'dnslink.dev' |
| 65 | + dnsimple_token: ${{ secrets.DNSIMPLE_TOKEN }} |
| 66 | + dnsimple_account_id: ${{ secrets.DNSIMPLE_ACCOUNT_ID }} |
| 67 | + github_token: ${{ github.token }} |
| 68 | + set_github_status: true |
| 69 | + |
| 70 | + deploy-gh-pages: |
| 71 | + if: | |
| 72 | + github.event.workflow_run.conclusion == 'success' && |
| 73 | + github.event.workflow_run.head_branch == 'main' |
| 74 | + runs-on: ubuntu-latest |
| 75 | + permissions: |
| 76 | + pages: write |
| 77 | + id-token: write |
| 78 | + environment: |
| 79 | + name: github-pages |
| 80 | + url: ${{ steps.deployment.outputs.page_url }} |
| 81 | + steps: |
| 82 | + - name: Download build artifact |
| 83 | + uses: actions/download-artifact@v4 |
| 84 | + with: |
| 85 | + name: website-build-${{ github.event.workflow_run.id }} |
| 86 | + path: website-build |
| 87 | + run-id: ${{ github.event.workflow_run.id }} |
| 88 | + github-token: ${{ github.token }} |
| 89 | + |
| 90 | + - name: Upload Pages artifact |
| 91 | + uses: actions/upload-pages-artifact@v3 |
| 92 | + with: |
| 93 | + path: website-build |
| 94 | + |
| 95 | + - name: Deploy to GitHub Pages |
| 96 | + id: deployment |
| 97 | + uses: actions/deploy-pages@v4 |
0 commit comments