The Automation Pipeline: Figma to GitHub in Real-Time
Article content
This is Part 5 of The Design-to-Code Loop series (7 posts on closing the gap between Figma and production code).
Introduction
Waiting for a designer to "finish" a token change before a developer picks it up is a manual step disguised as a process. The alternative isn't a faster handoff, it's removing the handoff entirely: a pipeline that listens for changes in Figma and automatically opens a pull request with the transformed tokens, no human copy-paste step in between. Call it the Zero-Latency Pipeline, because no step in it waits on a person remembering to do something.
The Pipeline Architecture
The pipeline breaks into four stages, each owning one job and handing off to the next through a defined interface.
- Figma Webhooks: Figma has no "variable changed" event, so you listen for
LIBRARY_PUBLISH(a library, including its variables, was published) orFILE_UPDATE, then fetch the variables yourself. Figma doesn't talk to GitHub directly: the webhook hits an endpoint you own, which verifies the request (Figma v2 webhooks include thepasscodeyou set when creating the webhook in the payload) and then triggers the workflow via GitHub'srepository_dispatchAPI. Events arrive with some delay, andFILE_UPDATEis debounced, so "zero-latency" describes the absence of a manual step, not literal real-time propagation. - GitHub Action (The Orchestrator): A workflow that fetches the updated Figma variables via the API, authenticated with a scoped personal access token stored as a repository secret, never committed to the codebase.
- Token Transformer (Style Dictionary): A step that converts raw Figma variables into Sass, CSS Custom Properties, or TypeScript objects, applying whatever naming and structure conventions your codebase already uses.
- Automated PR Generation: A script that creates a new branch, commits the updated tokens, and opens a PR for review. The PR step deliberately avoids a direct commit to main, so token changes still get a human glance before merge. The automation removes the copy-paste and keeps the review.
GitHub Action: The Sync Logic
GitHub Actions is the natural orchestrator here because it already sits between your repository and your deploy pipeline, so a token update flows through the same review and CI gates as any other change. Here's a simplified view of how a sync action might look:
# .github/workflows/figma-sync.yml
name: Sync Figma Tokens
on:
repository_dispatch:
types: [figma-token-update]
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch Figma Tokens
run: npm run figma:fetch
env:
FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}
- name: Transform Tokens
run: npm run tokens:build
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: "design: update tokens from Figma"
title: "Design Tokens Update"
branch: "chore/figma-sync"Transforming Variables into Code
The transformation step is where most of the value lives, because raw Figma variable exports don't map directly onto usable code. A Figma color variable is a hex value with a name; your codebase needs that same value expressed as a CSS custom property, a Sass variable, and a TypeScript constant, each with naming that matches your existing conventions. Style Dictionary handles this by treating tokens as a single source of truth (a JSON file per category) and generating platform-specific output from it, so the same token change produces consistent CSS, TypeScript, and, if you ship native apps, iOS and Android output from one edit.
// Style Dictionary v4 config example
export default {
source: ['tokens/**/*.json'],
platforms: {
css: {
transformGroup: 'css',
buildPath: 'src/styles/',
files: [{
destination: 'variables.css',
format: 'css/variables'
}]
},
ts: {
transformGroup: 'js',
buildPath: 'src/lib/theme/',
files: [{
destination: 'tokens.ts',
format: 'javascript/es6'
}]
}
}
};Step-by-Step Instructions: Building the Pipeline
- Generate a Figma Personal Access Token: Ensure it has read access to your design file, and scope it as narrowly as Figma allows: read-only, single file.
- Configure Figma Webhooks: Create a
LIBRARY_PUBLISHwebhook (via the Figma webhooks v2 API) pointing at a small Node.js or serverless endpoint. The endpoint checks thepasscodefield, responds200quickly, and calls GitHub'srepository_dispatchAPI with a token that can trigger workflows. - Implement the Fetch Script: Write a script that calls the Figma REST API (
GET /v1/files/:file_key/variables/local) with plainfetchto retrieve the latest variables. The Variables REST API requires an Enterprise plan; on other plans, export via a plugin instead. Version the raw JSON output alongside the transformed tokens so a bad transform is easy to diff against the source. - Set up Style Dictionary: Configure your transform rules to match your project's styling architecture, matching existing naming conventions rather than adopting Style Dictionary's defaults wholesale.
- Automate the Pull Request: Use the
create-pull-requestaction to automate the final step of the loop, and add a CI check that runs your visual regression suite against the PR before a human reviews it.
What Breaks This Pipeline in Practice
The two failure modes worth planning for upfront. First, a Figma variable gets renamed instead of edited: the pipeline sees this as a delete-plus-create, so the transform step can drop a token that's still referenced in code, and the failure only shows up as a broken build or a missing CSS variable somewhere downstream. Guard against this with a CI step that diffs the generated token file against the previous version and fails loudly on any removed key. Second, a designer publishes a work-in-progress variable set mid-edit, triggering a sync on incomplete data. The fix is a deliberate "publish" convention: treat a library publish as "this is ready to sync," and subscribe to LIBRARY_PUBLISH rather than FILE_UPDATE, so the pipeline only runs on intentional publishes.
Conclusion
The pipeline removes the friction from the design-to-code process by automating the mundane task of token synchronization. Start with the one-way sync (Figma to code) before attempting bidirectional updates, and add the removed-token CI check before your first real sync, catching a silent breakage in a PR review is far cheaper than catching it in a production stylesheet.
Next in the series: Architecting AI-Agent Design Workflows →. The pipeline handles token sync. Next: extending it with agents that can observe, interpret, and generate.
Sources & References
- GitHub Actions: Events That Trigger Workflows: official reference on
repository_dispatchand other workflow triggers - Style Dictionary Documentation: official docs on token transforms and multi-platform output
- Val Head: writer and consultant on animation and design engineering practice
- Figma REST API Documentation: official reference for the Variables and webhooks APIs
Suggested Reading
Architectural Note: Research, drafting, and code for this post were augmented by Gemini (Google DeepMind), directed and verified by Maas Mirzaa. How this workflow works →