Skip to content

ci: automate Figma Code Connect validation and publishing - #1369

Merged
georgewrmarshall merged 11 commits into
mainfrom
cursor/figma-code-connect-ci-e628
Sep 7, 2026
Merged

georgewrmarshall merged 11 commits into
mainfrom
cursor/figma-code-connect-ci-e628

Conversation

@georgewrmarshall

@georgewrmarshall georgewrmarshall commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR adds automated Figma Code Connect CI/CD following Figma's recommended workflow:

  • Pull requests: yarn figma:connect:publish:dry-run — validates Code Connect files against the Figma API without publishing
  • Push to main: yarn figma:connect:publish — publishes Code Connect mappings to Figma Dev Mode

The job only runs when Code Connect files change (**/*.figma.tsx or figma.config.json in either design system package).

This branch was rebased onto latest main. The new check-release job from main is kept. The required-checks gate:

  • Treats a skipped Figma Code Connect job as success when no Code Connect files changed
  • Requires detect-figma-code-connect-changes to succeed, so a failed git fetch/git diff cannot skip validation while All jobs pass still succeeds

Other changes

  • New reusable workflow: .github/workflows/figma-code-connect.yml, integrated into main.yml as a required check (skipped when no Code Connect files change)
  • Added --exit-on-unreadable-files to all figma:connect:publish scripts (Figma's CI recommendation)
  • Updated docs/figma-code-connect.md and .cursor/rules/figma-integration.md with CI workflow documentation

New components without .figma.tsx files are not enforced in CI — that remains a manual / cursor rule / Bugbot check.

Related issues

Fixes: N/A

Manual testing steps

  1. Confirm Check workflows (actionlint) passes on this PR
  2. Confirm Detect Figma Code Connect changes succeeds and Figma Code Connect is skipped (this PR does not change .figma.tsx or figma.config.json files)
  3. Confirm All jobs pass succeeds
  4. Verify FIGMA_ACCESS_TOKEN is configured as a repository secret with Code Connect (Write) and File content (Read-only) scopes
  5. After merge, confirm Code Connect mappings update in the MMDS Components Figma file Dev Mode when Code Connect files change

Screenshots/Recordings

Screenshot 2026-09-02 at 2 19 29 PM

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Setup required

Add a FIGMA_ACCESS_TOKEN repository secret with access to the MMDS Components Figma file. See docs/figma-code-connect.md for scope details.

Open in Web Open in Cursor 

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Removed update-readme-content script
    • Restored the root package.json script to run scripts/update-readme-content.ts via tsx so create-package and docs references work again.
  • ✅ Fixed: Git diff failure skips validation
    • Changed the git diff error path to throw and fail the process so CI cannot skip Code Connect validation when the diff cannot be computed.

Create PR

Or push these changes by commenting:

@cursor push 0b29c63402
Preview (0b29c63402)
diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -53,6 +53,7 @@
     "test:scripts": "NODE_OPTIONS=--experimental-vm-modules yarn jest --config ./jest.config.scripts.js --silent",
     "test:storybook": "yarn workspace @metamask/storybook-react test-storybook",
     "test:verbose": "yarn workspaces foreach --all --parallel --verbose run test:verbose",
+      "update-readme-content": "tsx scripts/update-readme-content.ts",
     "validate:figma-code-connect-changes": "tsx scripts/validate-figma-code-connect-changes.ts",
     "workspaces:list-versions": "./scripts/list-workspace-versions.sh"
   },

diff --git a/scripts/validate-figma-code-connect-changes.ts b/scripts/validate-figma-code-connect-changes.ts
--- a/scripts/validate-figma-code-connect-changes.ts
+++ b/scripts/validate-figma-code-connect-changes.ts
@@ -120,10 +120,10 @@
       .filter(Boolean);
   } catch (error) {
     const message = error instanceof Error ? error.message : String(error);
-    console.warn(
-      `Unable to diff against ${args.at(-1)}. Skipping change validation. (${message})`,
+    // Fail validation if we cannot determine the diff, rather than silently skipping.
+    throw new Error(
+      `Unable to diff against ${args.at(-1)}. Failing change validation. (${message})`,
     );
-    return [];
   }
 }

You can send follow-ups to the cloud agent here.

Comment thread package.json Outdated
Comment thread scripts/validate-figma-code-connect-changes.ts Outdated
Comment thread scripts/validate-figma-code-connect-changes.ts Fixed
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@georgewrmarshall

Copy link
Copy Markdown
Contributor Author

@cursoragent token has been added address all comments, then see if CI passes

@cursor

cursor Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

All review comments are addressed and CI is passing.

Fixes applied

  1. Restored update-readme-content script — accidentally removed from package.json when adding validate:figma-code-connect-changes; yarn create-package depends on it.

  2. Git diff failure now fails CI — runGitDiff throws instead of returning [], so validation can't silently pass.

  3. CodeQL / command injection — replaced execSync with execa for git commands.

  4. Lint failures — refactored to use ValidationContext instead of process.env in tests, switched to toStrictEqual, fixed prettier formatting, and replaced process.exit() with thrown errors.

  5. CI git fetch — added git fetch origin "${GITHUB_BASE_REF:-main}" before change validation so PR diffs resolve correctly.

  6. Docs formatting — fixed prettier issues in docs/figma-code-connect.md.

CI status

Latest run passed (Main workflow — success). With the token configured, Figma Code Connect / Validate Code Connect ran the full dry-run against the Figma API successfully.

PR: #1369

Open in Web Open in Cursor 

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@cursor
cursor Bot force-pushed the cursor/figma-code-connect-ci-e628 branch from 803fea5 to ac13d8f Compare July 8, 2026 18:41
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

cursoragent and others added 7 commits September 2, 2026 19:07
Add GitHub Actions workflow to dry-run Code Connect on every pull request
and publish mappings when changes merge to main. Includes a change
validation script for new components and CI documentation updates.

Co-authored-by: George Marshall <georgewrmarshall@users.noreply.github.com>
Fall back to parse-only validation on PRs when the repository secret is
not configured, so CI passes while the token is being set up. Publishing
on main still requires the token.

Co-authored-by: George Marshall <georgewrmarshall@users.noreply.github.com>
- Restore update-readme-content script removed from package.json
- Fail validation when git diff fails instead of silently passing
- Use execa instead of execSync for safer git commands
- Refactor validation context to avoid process.env in tests
- Fix eslint/prettier/jest issues in validation script and tests
- Fetch PR base branch in CI before running change validation

Co-authored-by: George Marshall <georgewrmarshall@users.noreply.github.com>
Co-authored-by: George Marshall <georgewrmarshall@users.noreply.github.com>
Remove custom validation scripts and CI wrappers. PRs run
figma:connect:publish:dry-run directly; merges to main run
figma:connect:publish.

Co-authored-by: George Marshall <georgewrmarshall@users.noreply.github.com>
Co-authored-by: George Marshall <georgewrmarshall@users.noreply.github.com>
Add a path detection job so dry-run and publish run only when
.figma.tsx or figma.config.json files change, per Figma CI guidance.
Treat a skipped figma job as success in the required checks gate.

Co-authored-by: George Marshall <georgewrmarshall@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/figma-code-connect-ci-e628 branch from 94b1bb6 to 04bdcc1 Compare September 2, 2026 19:09
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Failed detect job skips Figma CI
    • Made all-jobs-complete depend on and require success from detect-figma-code-connect-changes so a failed detect cannot be masked by a skipped figma-code-connect.

Create PR

Or push these changes by commenting:

@cursor push d3baa38311
Preview (d3baa38311)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -147,6 +147,7 @@
       - lint-build-test
       - test-storybook
       - chromatic
+      - detect-figma-code-connect-changes
       - figma-code-connect
     outputs:
       passed: ${{ steps.set-output.outputs.passed }}
@@ -161,6 +162,7 @@
             "lint-build-test:${{ needs.lint-build-test.result }}"
             "test-storybook:${{ needs.test-storybook.result }}"
             "chromatic:${{ needs.chromatic.result }}"
+            "detect-figma-code-connect-changes:${{ needs.detect-figma-code-connect-changes.result }}"
           )
 
           for entry in "${REQUIRED[@]}"; do

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 04bdcc1. Configure here.

Comment thread .github/workflows/main.yml
Require the detect job to succeed in All jobs complete so a failed
git fetch or diff cannot skip Code Connect validation while the
required check still passes.

Co-authored-by: George Marshall <georgewrmarshall@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@georgewrmarshall
georgewrmarshall marked this pull request as ready for review September 2, 2026 19:43
@georgewrmarshall
georgewrmarshall requested a review from a team as a code owner September 2, 2026 19:43
@georgewrmarshall
georgewrmarshall enabled auto-merge (squash) September 2, 2026 19:43
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Path-gated so most PRs never hit the Figma API. The regex only matches .figma.tsx files and figma.config.json under the two design-system packages — component source changes alone do not trigger validation or publish.

- detect-figma-code-connect-changes
if: >
needs.detect-figma-code-connect-changes.result == 'success' &&
needs.detect-figma-code-connect-changes.outputs.changed == 'true'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both conditions matter: changed == true alone is not enough, because a failed detect job also produces a skipped Figma job. Requiring result == success keeps a broken git fetch/git diff from silently bypassing Code Connect checks.

needs.detect-figma-code-connect-changes.outputs.changed == 'true'
uses: ./.github/workflows/figma-code-connect.yml
with:
publish: ${{ github.event_name == 'push' }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

publish is true only on push (main after merge). Pull requests always get a dry-run against the Figma API, so Dev Mode mappings only update after code lands on main.


all-jobs-complete:
name: All jobs complete
if: ${{ always() }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

always() is required because figma-code-connect is often skipped. Without it, a skipped dependency would cancel this gate job and All jobs pass would never run.

if [[ "$FIGMA_RESULT" != "success" && "$FIGMA_RESULT" != "skipped" ]]; then
echo "figma-code-connect finished with $FIGMA_RESULT"
exit 1
fi

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Detect is a hard required check; Figma itself may be success or skipped. That lets PRs with no Code Connect file changes stay green, while still failing the required check if detect errors or if dry-run/publish fails when it does run.

publish:
description: 'Publish Code Connect mappings to Figma (true on main push, false on PR dry-run)'
required: true
type: boolean

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Single reusable workflow for both PR validation and main publish. Callers flip this boolean; the job name and which yarn script runs both derive from it so we do not maintain two nearly identical workflows.

- name: Checkout and setup environment
uses: MetaMask/action-checkout-and-setup@v1
with:
is-high-risk-environment: ${{ inputs.publish }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Publish is treated as high-risk because it writes to the shared Figma file via FIGMA_ACCESS_TOKEN. Dry-run stays low-risk since it only validates against the API and does not mutate Dev Mode mappings.

if: ${{ inputs.publish }}
env:
FIGMA_ACCESS_TOKEN: ${{ secrets.FIGMA_ACCESS_TOKEN }}
run: yarn figma:connect:publish

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On PRs this runs yarn figma:connect:publish:dry-run; on main push it runs the real publish. Both platforms (React + React Native) are covered by those root scripts, so one CI job keeps both packages in sync with Figma.

Comment thread package.json
"figma:connect:publish:react:dry-run": "figma connect publish --dry-run --config packages/design-system-react/figma.config.json",
"figma:connect:publish:react-native": "figma connect publish --config packages/design-system-react-native/figma.config.json",
"figma:connect:publish:react-native:dry-run": "figma connect publish --dry-run --config packages/design-system-react-native/figma.config.json",
"figma:connect:publish:react": "figma connect publish --exit-on-unreadable-files --config packages/design-system-react/figma.config.json",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

--exit-on-unreadable-files is Figma's CI recommendation: a broken or unreadable .figma.tsx fails the job instead of being skipped. That makes dry-run useful as a merge gate when Code Connect files change.

- **Code Connect (Write)** — required for publishing and API validation
- **File content (Read-only)** — required for reading component definitions

Use a service account or bot token with access to the [MMDS Components Figma file](https://www.figma.com/design/1D6tnzXqWgnUC3spaAOELN/%F0%9F%A6%8A-MMDS-Components?m=auto), not a personal token tied to an individual contributor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CI depends on a repo FIGMA_ACCESS_TOKEN with Code Connect write + file content read. Prefer a shared service/bot token so publish on main does not depend on any one contributor's personal Figma access.

Change Tag Code Connect files so this PR runs Figma validation instead
of skipping it. Template-file migration cannot land until all parser
mappings move to CLI v2 together.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@georgewrmarshall georgewrmarshall self-assigned this Sep 2, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

📖 Storybook Links

Compare the preview for this pull request with the latest Storybooks from the main branch.

🔀 Pull Request Preview

🌳 Main Branch (Latest)

@georgewrmarshall
georgewrmarshall merged commit 4d0edb8 into main Sep 7, 2026
35 checks passed
@georgewrmarshall
georgewrmarshall deleted the cursor/figma-code-connect-ci-e628 branch September 7, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants