Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 24 additions & 51 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: Build and Deploy
# Build workflow - runs for both PRs and main branch pushes
# This workflow builds the website without access to secrets
# For PRs: Runs on untrusted fork code safely (using pull_request event, not pull_request_target)
# For main: Builds and uploads artifacts for deployment
# Artifacts are passed to the deploy workflow which has access to secrets

name: Build

# Explicitly declare permissions
permissions:
contents: read
pull-requests: write
statuses: write
pages: write
id-token: write

on:
push:
Expand All @@ -19,16 +24,17 @@ env:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true # Cancel in progress runs if a new run is started
cancel-in-progress: true

jobs:
build-and-deploy:
build:
runs-on: ubuntu-latest
outputs:
cid: ${{ steps.deploy.outputs.cid }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# No ref parameter needed - uses correct ref automatically:
# - For PRs: merge commit or PR head
# - For pushes: the pushed commit

- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -42,50 +48,17 @@ jobs:
- name: Build project
run: make website

- name: Upload static files as artifact
id: upload-artifact
uses: actions/upload-pages-artifact@v3
# Upload artifact for deploy workflow
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: website-build-${{ github.run_id }}
path: ${{ env.BUILD_PATH }}
retention-days: 1

- uses: ipfs/ipfs-deploy-action@v1
name: Deploy to IPFS Mirror Providers
id: deploy
# Upload for GitHub Pages (main branch only)
- name: Upload Pages artifact
if: github.ref == 'refs/heads/main'
uses: actions/upload-pages-artifact@v3
with:
path-to-deploy: ${{ env.BUILD_PATH }}
cluster-url: "/dnsaddr/ipfs-websites.collab.ipfscluster.io"
cluster-user: ${{ secrets.CLUSTER_USER }}
cluster-password: ${{ secrets.CLUSTER_PASSWORD }}
storacha-key: ${{ secrets.STORACHA_KEY }}
storacha-proof: ${{ secrets.STORACHA_PROOF }}
#TODO pinata-jwt-token: ${{ secrets.PINATA_JWT_TOKEN }}
github-token: ${{ github.token }}

# TODO: right now, DNSLink is controlled by Fleek, and we use ipfs/ipfs-deploy-action for PR previews
#- name: Update DNSLink
# if: false # TODO github.ref == 'refs/heads/main' # only update DNSLink for main branch
# uses: ipfs/dnslink-action@v0.1
# with:
# cid: ${{ steps.deploy.outputs.cid }}
# dnslink_domain: 'specs.ipfs.tech'
# cf_record_id: ${{ secrets.CF_RECORD_ID }}
# cf_zone_id: ${{ secrets.CF_ZONE_ID }}
# cf_auth_token: ${{ secrets.CF_AUTH_TOKEN }}
# github_token: ${{ github.token }}
# set_github_status: true


gh-pages:
runs-on: 'ubuntu-latest'
needs: build-and-deploy
if: github.ref == 'refs/heads/main' # only deploy to gh-pages for main branch
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
environment:
name: 'github-pages'
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
path: ${{ env.BUILD_PATH }}
79 changes: 79 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Deploy workflow - triggered by workflow_run after successful build
# This workflow has access to secrets but never executes untrusted code
# It only downloads and deploys pre-built artifacts from the build workflow
# Security: Fork code cannot access secrets as it only runs in build workflow
# Deploys to IPFS for all branches and GitHub Pages for main branch only

name: Deploy

# Explicitly declare permissions
permissions:
contents: read
pull-requests: write
statuses: write

on:
workflow_run:
workflows: ["Build"]
types: [completed]

env:
BUILD_PATH: 'website-build'

jobs:
deploy-ipfs:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
outputs:
cid: ${{ steps.deploy.outputs.cid }}
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: website-build-${{ github.event.workflow_run.id }}
path: ${{ env.BUILD_PATH }}
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}

- name: Deploy to IPFS Mirror Providers
uses: ipfs/ipfs-deploy-action@b491fdc2b1ca70a9b11b1a26dd4d36210c46653f # ipfs-deploy-action/pull/37
id: deploy
with:
path-to-deploy: ${{ env.BUILD_PATH }}
cluster-url: "/dnsaddr/ipfs-websites.collab.ipfscluster.io"
cluster-user: ${{ secrets.CLUSTER_USER }}
cluster-password: ${{ secrets.CLUSTER_PASSWORD }}
storacha-key: ${{ secrets.STORACHA_KEY }}
storacha-proof: ${{ secrets.STORACHA_PROOF }}
#TODO pinata-jwt-token: ${{ secrets.PINATA_JWT_TOKEN }}
github-token: ${{ github.token }}

# TODO: right now, DNSLink is controlled by Fleek, and we use ipfs/ipfs-deploy-action for PR previews
#- name: Update DNSLink
# if: github.event.workflow_run.head_branch == 'main'
# uses: ipfs/dnslink-action@v0.1
# with:
# cid: ${{ steps.deploy.outputs.cid }}
# dnslink_domain: 'specs.ipfs.tech'
# cf_record_id: ${{ secrets.CF_RECORD_ID }}
# cf_zone_id: ${{ secrets.CF_ZONE_ID }}
# cf_auth_token: ${{ secrets.CF_AUTH_TOKEN }}
# github_token: ${{ github.token }}
# set_github_status: true

deploy-gh-pages:
if: |
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main'
needs: deploy-ipfs
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4