Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 26 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
name: Build and Deploy to IPFS
# 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

permissions:
contents: read
pull-requests: write
statuses: write

on:
push:
branches:
- main
pull_request_target:
pull_request:
branches:
- main

env:
BUILD_PATH: 'docs/.vuepress/dist'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-and-deploy:
build:
runs-on: ubuntu-latest
outputs: # This exposes the CID output of the action to the rest of the workflow
cid: ${{ steps.deploy.outputs.cid }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
# No ref parameter needed - uses correct ref automatically:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does change the behaviour to checkout the merge commit. I guess there's a reason for this being the default. So let's give it a go and change if needed in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this, which I just realised, is that this will cause ipfs-deploy-action to set the commit status for merge SHA commits that aren't visible in the pull request.

Both Cloudflare Pages and Vercel use the PR head commit for the following reasons:

  • The preview deployment reflects exactly what's in your feature branch
  • It doesn't include any potential merge conflicts or changes that would result from merging with the target branch
  • Each new commit pushed to the PR branch triggers a new preview deployment from that latest commit

If we want to ensure that PRs are up to date and avoid merge conflicts, we can require branches to be up to date before merging in the branch protection rules in GitHub.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently testing this in this PR: #2119

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, with #2119 the commit SHA that was used in the PR comment is pull_request.head.sha while the code that was checked out was technically the merge commit SHA (which should be different).

I'm currently investigating why.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm now that there's a discrepancy between the commit SHA used for the build and the commit SHA used to update the comment.

You can see it here: https://github.com/ipfs/ipfs-docs/actions/runs/17208024892/job/48812841343#step:2:87

It's checking out and building e8daa37, but setting the commit status for a3bd938.

# - For PRs: merge commit or PR head
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it decided if it's the merge commit or PR head?

Copy link
Member

@2color 2color Aug 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, it defaults to the merge commit, which may seem confusing, because it doesn't reflect the actual HEAD state of the PR branch. Instead, it contains PR changes PLUS any new commits that landed on main since the PR was created.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, i made a mental shortcut, clarified in 3872fec

# - For pushes: the pushed commit

- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -31,16 +41,15 @@ jobs:
cache: 'npm'

- name: Install dependencies
run: npm ci
run: npm ci --prefer-offline --no-audit --progress=false

- name: Build project
run: npm run docs:build

- uses: ipfs/ipfs-deploy-action@v1
name: Deploy to IPFS
id: deploy
# Upload artifact for deploy workflow
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
path-to-deploy: docs/.vuepress/dist
storacha-key: ${{ secrets.STORACHA_KEY }}
storacha-proof: ${{ secrets.STORACHA_PROOF }}
github-token: ${{ github.token }}
name: docs-build-${{ github.run_id }}
path: ${{ env.BUILD_PATH }}
retention-days: 1
58 changes: 58 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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

name: Deploy

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

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

env:
BUILD_PATH: 'docs-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: docs-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
uses: ipfs/ipfs-deploy-action@b491fdc2b1ca70a9b11b1a26dd4d36210c46653f # ipfs-deploy-action/pull/37
id: deploy
with:
path-to-deploy: ${{ env.BUILD_PATH }}
storacha-key: ${{ secrets.STORACHA_KEY }}
storacha-proof: ${{ secrets.STORACHA_PROOF }}
github-token: ${{ github.token }}

# TODO: Add DNSLink update when needed
#- name: Update DNSLink
# if: github.event.workflow_run.head_branch == 'main'
# uses: ipfs/[email protected]
# with:
# cid: ${{ steps.deploy.outputs.cid }}
# dnslink_domain: 'docs.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