用于将变量同步到 Figma 的 GitHub Actions 工作流示例
This repository contains a couple of GitHub Actions workflows:
These workflows demonstrate bi-directional syncing between variables in Figma and design tokens in a codebase using Figma's Variables REST API. For more background and a graphical representation of what these workflows do, see our Syncing design systems using Variables REST API FigJam file.
To use these workflows, you should copy the code in this repository into your organization and modify it to suit the needs of your design processes.
To use the "Sync Figma variables to tokens" workflow, you must be a full member of an Enterprise org in Figma. To use the "Sync tokens to Figma" workflow, you must also have an editor seat.
Both workflows assume that you have a single Figma file with local variable collections, along with one or more tokens json files in the tokens/ directory that adhere* to the draft W3C spec for Design Tokens. For demonstration purposes, this directory contains the tokens exported from the Get started with variables Community file. Have a copy of this file ready if you want to try out the workflow with these existing tokens.
*See
src/token_types.tsfor more details on the format of the expected tokens json files, including the deviations from the draft design tokens spec we've had to make. We expect there to be one tokens file per variable collection and mode.
In addition, you must also have a personal access token for the Figma API to allow these workflows to authenticate with the API. For the "Sync Figma variables to tokens" workflow, the token must have at least the Read-only Variables scope selected. For the "Sync tokens to Figma" workflow, the token must have the Read and write Variables scope selected.
Before running either of these workflows, you'll need to create an encrypted secret in your repository named GH_ACTION_VARIABLES_SYNC_FIGMA_TOKEN containing your personal access token.
Both workflows are configured to run manually for demonstration purposes, and are designed to be as conservative as possible in their functionality (see details below).
To run the "Sync Figma variables to tokens" workflow:
https://www.figma.com/file/{file_key}/{title}.tokens/ directory. If there are no changes to be made, then a pull request will not be created.This workflow has some key behaviors to note:
To run the "Sync tokens to Figma" workflow:
https://www.figma.com/file/{file_key}/{title}. Note: if you are trying out this workflow for the first time, use a file that is separate from your design system to avoid any unintended changes.This workflow has some key behaviors to note:
You can run the GitHub actions locally by running npm install and creating a .env file with the following contents:
FILE_KEY="your_file_key"
PERSONAL_ACCESS_TOKEN="your_personal_access_token"and then running:
npm run sync-tokens-to-figma
# or
# Defaults to writing to the tokens_new directory
npm run sync-figma-to-tokens
# Writes to the specified directory
npm run sync-figma-to-tokens -- --output directory_nameRun the Jest tests:
npm run test暂无开放 Issues,或尚未同步最近议题。